diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..2066ef2 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,19 @@ +{ + // Utilisez IntelliSense pour en savoir plus sur les attributs possibles. + // Pointez pour afficher la description des attributs existants. + // Pour plus d'informations, visitez : https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Test Cypress via NPM", + "cwd": "${workspaceFolder}", + "type": "node", + "request": "launch", + "runtimeExecutable": "npm", + "runtimeArgs": [ + "run-script", + "test" + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 3b66410..bebba7e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,11 @@ { - "git.ignoreLimitWarning": true + "git.ignoreLimitWarning": true, + "conventionalCommits.scopes": [ + "#1", + "#2", + "#3", + "#4", + "#5", + "#6" + ] } \ No newline at end of file diff --git a/cypress.json b/cypress.json index 0967ef4..52667bb 100644 --- a/cypress.json +++ b/cypress.json @@ -1 +1,6 @@ -{} +{ + "baseUrl": "http://localhost:3000", + "env" : { + "logoutUrl": "/ok.html" + } +} diff --git a/cypress/fixtures/userSet.json b/cypress/fixtures/userSet.json new file mode 100644 index 0000000..ad778bc --- /dev/null +++ b/cypress/fixtures/userSet.json @@ -0,0 +1,25 @@ +[ + { + "valid-admin": { + "email": "adrian@trusk.com", + "password": "adrian@trusk.com" + } + }, + { + "invalid-admin": { + "email": "adrian@trusk.com", + "password": "adrian" + } + }, + { + "unexisting-user": { + "email": "adrian.pothuaud@trusk.com", + "password": "badpassword" + } + }, + { + "malformed-email": { + "email": "adrian-trusk" + } + } +] \ No newline at end of file diff --git a/cypress/integration/trusk-test/test.spec.js b/cypress/integration/trusk-test/test.spec.js index 37f3364..e3aaefc 100644 --- a/cypress/integration/trusk-test/test.spec.js +++ b/cypress/integration/trusk-test/test.spec.js @@ -1,45 +1,77 @@ /// -it('Should work as expected', () => { - cy.visit('http://localhost:3000') - // title - cy.title().should('eq', 'QA @ Trusk') - // elements - cy.get('h1').should('be.visible') - cy.get('p').should('be.visible') - cy.get('label').should('be.visible') - cy.get('input').should('be.visible') - cy.get('button').should('be.visible') - // submit empty - cy.get('input').first().clear() - cy.get('input').last().clear() - cy.get('button').click() - cy.contains('Renseignes une adresse e-mail!').should('be.visible') - cy.contains('Renseignes un mot de passe!').should('be.visible') - // submit invalid email - cy.get('input').first().clear().type('adrian-trusk') - cy.get('button').click() - cy.contains('Renseignes une adresse e-mail valide!').should('be.visible') - // submit wrong email - cy.get('input').first().clear().type('adrian.pothuaud@trusk.com') - cy.get('button').click() - cy.contains('Renseignes la bonne adresse e-mail!').should('be.visible') - // submit bad password - cy.get('input').first().clear().type('adrian@trusk.com') - cy.get('input').last().clear().type('adrian') - cy.get('button').click() - cy.contains('Renseignes le bon mot de passe').should('be.visible') - // submit valid credentials - cy.get('input').first().clear().type('adrian@trusk.com') - cy.get('input').last().clear().type('adrian@trusk.com') - cy.get('button').click() - cy.contains('Salut testeur !').should('be.visible') - // get back - cy.contains('Retour').click() - cy.title().should('eq', 'QA @ Trusk') - cy.get('h1').should('be.visible') - cy.get('p').should('be.visible') - cy.get('label').should('be.visible') - cy.get('input').should('be.visible') - cy.get('button').should('be.visible') -}) \ No newline at end of file +describe('Should allow valid user and block the rest', () => { + + beforeEach(function() { + // Changed theses should as required conditions to perform other tests + cy.visit('/') + // title + cy.title().should('eq', 'QA @ Trusk') + // elements + cy.get('#hello').should('be.visible') + cy.get('#guess').should('be.visible') + cy.get('#email-label').should('be.visible') + cy.get('#email-input').should('be.visible') + cy.get('#password-label').should('be.visible') + cy.get('#password-input').should('be.visible') + cy.get('#submit').should('be.visible') + + }); + + it('Prevent submiting empty credentials', function() { + // submit empty + cy.get('#email-input').clear() + cy.get('#password-input').clear() + cy.get('#submit').click() + cy.contains('Renseignes une adresse e-mail!').should('be.visible') + cy.contains('Renseignes un mot de passe!').should('be.visible') + }); + + + it('Prevent submiting malformed email', function() { + // submit invalid email + cy.get('#email-input').clear().type('adrian-trusk') + cy.get('#password-input').clear() + cy.get('#submit').click() + cy.contains('Renseignes une adresse e-mail valide!').should('be.visible') + }); + + it('Prevent submiting an unexisting user', function() { + // submit wrong email + cy.get('#email-input').clear().type('adrian.pothuaud@trusk.com') + cy.get('#password-input').clear().type('badpassword') + cy.get('#submit').click() + cy.contains('Renseignes la bonne adresse e-mail!').should('be.visible') + cy.contains('Renseignes le bon mot de passe').should('be.visible') + }); + + it('Prevent submiting invalid password of an existing user', function() { + // submit bad password + cy.get('#email-input').clear().type('adrian@trusk.com') + cy.get('#password-input').clear().type('adrian') + cy.get('#submit').click() + cy.contains('Renseignes le bon mot de passe').should('be.visible') + }); + + it('Allow connect a user in the system with right credentials', function() { + // submit valid credentials + cy.get('#email-input').clear().type('adrian@trusk.com') + cy.get('#password-input').clear().type('adrian@trusk.com') + cy.get('#submit').click() + cy.contains('Salut testeur !').should('be.visible') + + }); + + it.skip('Allow to disconnect a connected user', function() { + // cy.visit("ok.html") + // get back + cy.contains('Retour').click() + cy.title().should('eq', 'QA @ Trusk') + cy.get('h1').should('be.visible') + cy.get('p').should('be.visible') + cy.get('label').should('be.visible') + cy.get('input').should('be.visible') + cy.get('#submit').should('be.visible') + }); + +}); \ No newline at end of file diff --git a/package.json b/package.json index 01b774a..d98f2ff 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,8 @@ "version": "0.0.1", "main": "index.js", "scripts": { - "start": "nodemon index.js" + "start": "nodemon index.js", + "test": "cypress open" }, "devDependencies": { "cypress": "^8.3.0",