diff --git a/cypress/fixtures/admin.json b/cypress/fixtures/admin.json new file mode 100644 index 0000000..fb25ded --- /dev/null +++ b/cypress/fixtures/admin.json @@ -0,0 +1,4 @@ +{ + "username": "admin", + "password": "admin" +} \ No newline at end of file diff --git a/cypress/integration/create-channel.spec.js b/cypress/integration/create-channel.spec.js new file mode 100644 index 0000000..8a89d97 --- /dev/null +++ b/cypress/integration/create-channel.spec.js @@ -0,0 +1,58 @@ +/// +/* globals cy, expect */ + +context('Create Channel Browser Testing', () => { + let channelName = 'Test Channel ', + description = 'Test Description '; + before(() => { + cy.randomNum().then(num => { + channelName += num; + description += num; + }); + cy.clearLocalStorage({ domain: null }); + cy.clearCookies({ domain: null }); + }); + it('should visit user login screen', () => cy.userLogin()); + describe('Channel Creation process', () => { + it('should login', () => cy.login()); + it('should visit the channel creation screen', () => cy.naviagte('/admin/admin-circle-create')); + /*it('should enter incorrect channel data', () => { + cy.get('#admin-circle-create input[name="name"]').type('!"#$%&'); + cy.get('#admin-circle-create input[name="name"]').should('have.value', '!"#$%&'); + cy.get('#admin-circle-create input[name="description"]').type(description); + cy.get('#admin-circle-create input[name="description"]').should('have.value', description); + }); + it('should click on create channel button', () => { + cy.get('#admin-circle-create input[type="submit"]').click(); + }); + it('should provide errors about incorrect channel data', () => { + // TO-DO: Check for error messages + cy.get('element') + .should('contain.text', 'Error message.'); + });*/ + it('should enter correct channel data', () => { + cy.get('#admin-circle-create input[name="name"]').clear().type(channelName); + cy.get('#admin-circle-create input[name="name"]').should('have.value', channelName); + cy.get('#admin-circle-create input[name="description"]').clear().type(description); + cy.get('#admin-circle-create input[name="description"]').should('have.value', description); + }); + it('should click on create channel button', () => { + cy.get('#admin-circle-create input[type="submit"]').click(); + }); + it('should land on channels list screen', () => { + cy.location().should((loc) => { + expect(loc.pathname).to.eq('/admin'); + }); + // Workaround - component reactivity bug + cy.reload(); + cy.get('.accept-button').click(); + // End workaround + }); + it('should land newly created channel on channels list screen', () => { + cy.contains('solid-display-value[name="circle.name"]', channelName).should("exist"); + cy.fixture('admin.json').then(admin => { + cy.contains('solid-display-value[name="username"]', admin.username).should("exist"); + }); + }); + }); +}); diff --git a/cypress/integration/create-job-offer.spec.js b/cypress/integration/create-job-offer.spec.js new file mode 100644 index 0000000..f968154 --- /dev/null +++ b/cypress/integration/create-job-offer.spec.js @@ -0,0 +1,64 @@ +/// +/* globals cy, expect */ + +context('Create Job Offer Browser Testing', () => { + let jobDate = '', + jobTitle = 'Test Job Offer ', + description = 'Test Description '; + before(() => { + cy.nextYear(1).then(year => { + jobDate = year + '-12-31'; + }); + cy.randomNum().then(num => { + jobTitle += num; + description += num; + }); + cy.clearLocalStorage({ domain: null }); + cy.clearCookies({ domain: null }); + }); + it('should visit user login screen', () => cy.userLogin()); + describe('Job Offer Creation process', () => { + it('should login', () => cy.login()); + it('should visit the job offer creation screen', () => cy.naviagte('/job-offers/job-offers-create')); + /*it('should enter incorrect job offer data', () => { + cy.get('#job-offers-create input[name="closingDate"]').type('!"#$%&'); + cy.get('#job-offers-create input[name="closingDate"]').should('have.value', '!"#$%&'); + cy.get('#job-offers-create input[name="title"]').type('!"#$%&'); + cy.get('#job-offers-create input[name="title"]').should('have.value', '!"#$%&'); + cy.get('#job-offers-create textarea[name="description"]').type(description); + cy.get('#job-offers-create textarea[name="description"]').should('have.value', description); + }); + it('should click on create job offer button', () => { + cy.get('#job-offers-create input[type="submit"]').click(); + }); + it('should provide errors about incorrect job offer data', () => { + // TO-DO: Check for error messages + cy.get('element') + .should('contain.text', 'Error message.'); + });*/ + it('should enter correct job offer data', () => { + cy.get('#job-offers-create input[name="closingDate"]').clear().type(jobDate); + cy.get('#job-offers-create input[name="closingDate"]').should('have.value', jobDate); + cy.get('#job-offers-create input[name="title"]').clear().type(jobTitle); + cy.get('#job-offers-create input[name="title"]').should('have.value', jobTitle); + cy.get('#job-offers-create textarea[name="description"]').clear().type(description); + cy.get('#job-offers-create textarea[name="description"]').should('have.value', description); + }); + it('should click on create job offer button', () => { + cy.get('#job-offers-create input[type="submit"]').click(); + }); + it('should land on job offers list screen', () => { + cy.location().should((loc) => { + expect(loc.pathname).to.eq('/job-offers'); + }); + // Workaround - component reactivity bug + cy.reload(); + cy.get('.accept-button').click(); + // End workaround + }); + it('should land newly created job offer on job offers list screen', () => { + cy.contains('solid-display-value[name="title"]', jobTitle).should("exist"); + cy.contains('solid-display-value[name="description"]', description).should("exist"); + }); + }); +}); diff --git a/cypress/integration/create-project.spec.js b/cypress/integration/create-project.spec.js new file mode 100644 index 0000000..65af225 --- /dev/null +++ b/cypress/integration/create-project.spec.js @@ -0,0 +1,64 @@ +/// +/* globals cy, expect */ + +context('Create Project Browser Testing', () => { + let projectName = 'Test Project ', + customerName = 'Test Customer ', + description = 'Test Description '; + before(() => { + cy.randomNum().then(num => { + projectName += num; + customerName += num; + description += num; + }); + cy.clearLocalStorage({ domain: null }); + cy.clearCookies({ domain: null }); + }); + it('should visit user login screen', () => cy.userLogin()); + describe('Project Creation process', () => { + it('should login', () => cy.login()); + it('should visit the project creation screen', () => cy.naviagte('/admin/admin-projects/admin-project-create')); + /*it('should enter incorrect project data', () => { + cy.get('#admin-project-create input[name="customer.name"]').type('!"#$%&'); + cy.get('#admin-project-create input[name="customer.name"]').should('have.value', '!"#$%&'); + cy.get('#admin-project-create input[name="name"]').type('!"#$%&'); + cy.get('#admin-project-create input[name="name"]').should('have.value', '!"#$%&'); + cy.get('#admin-project-create textarea[name="description"]').type(description); + cy.get('#admin-project-create textarea[name="description"]').should('have.value', description); + }); + it('should click on create project button', () => { + cy.get('#admin-project-create input[type="submit"]').click(); + }); + it('should provide errors about incorrect project data', () => { + // TO-DO: Check for error messages + cy.get('element') + .should('contain.text', 'Error message.'); + });*/ + it('should enter correct project data', () => { + cy.get('#admin-project-create input[name="customer.name"]').clear().type(customerName); + cy.get('#admin-project-create input[name="customer.name"]').should('have.value', customerName); + cy.get('#admin-project-create input[name="name"]').clear().type(projectName); + cy.get('#admin-project-create input[name="name"]').should('have.value', projectName); + cy.get('#admin-project-create textarea[name="description"]').clear().type(description); + cy.get('#admin-project-create textarea[name="description"]').should('have.value', description); + }); + it('should click on create project button', () => { + cy.get('#admin-project-create input[type="submit"]').click(); + }); + it('should land on projects list screen', () => { + cy.location().should((loc) => { + expect(loc.pathname).to.eq('/admin/admin-projects'); + }); + // Workaround - component reactivity bug + cy.reload(); + cy.get('.accept-button').click(); + // End workaround + }); + it('should land newly created project on projects list screen', () => { + cy.contains('solid-display-value[name="project.name"]', projectName).should("exist"); + cy.fixture('admin.json').then(admin => { + cy.contains('solid-display-value[name="username"]', admin.username).should("exist"); + }); + }); + }); +}); diff --git a/cypress/integration/create-user.spec.js b/cypress/integration/create-user.spec.js index 2670ba8..b6dc322 100644 --- a/cypress/integration/create-user.spec.js +++ b/cypress/integration/create-user.spec.js @@ -1,45 +1,26 @@ /// /* globals cy, expect */ -context('Creat User Browser Testing', () => { - const firstName = 'First', - lastName = 'Last', - username = 'testuser_creation_' + Math.floor(1000 + Math.random() * 9000), - email = username + '@testemail.com'; +context('Create User Browser Testing', () => { + let firstName = 'First ', + lastName = 'Last ', + username = 'testuser_creation_', + email = ''; before(() => { - cy.clearLocalStorage({ domain: null}); + cy.randomNum().then(num => { + firstName += num; + lastName += num; + username += num; + email = username + '@testemail.com'; + }); + cy.clearLocalStorage({ domain: null }); cy.clearCookies({ domain: null }); }); - it('visit the homepage', () => { - cy.visit('/'); - }); - it('should await for an user login', () => { - cy.location().should((loc) => { - expect(loc.pathname).to.eq('/auth/login/'); - }); - }); + it('should visit user login screen', () => cy.userLogin()); describe('User Creation process', () => { - it('should login', () => { - cy.get('#id_username').type('admin'); - cy.get('#id_username').should('have.value', 'admin'); - cy.get('#id_password').type('admin'); - cy.get('#id_password').should('have.value', 'admin'); - cy.get('.connection-btn').click(); - cy.get('.accept-button').click(); - cy.location().should((loc) => { - expect(loc.pathname).to.eq('/'); - }); - }); - it('should visit the user creation screen', () => { - cy.visit('/admin/admin-users/admin-users-create'); - cy.location().should((loc) => { - expect(loc.pathname).to.eq('/admin/admin-users/admin-users-create'); - }); - // Workaround - seems to be a bug when accessing the route directly - cy.get('.accept-button').click(); - // End workaround - }); - /*it('should enter erroneous user data and submit', () => { + it('should login', () => cy.login()); + it('should visit the user creation screen', () => cy.naviagte('/admin/admin-users/admin-users-create')); + /*it('should enter incorrect user data', () => { cy.get('#admin-users-create input[name="first_name"]').type(firstName); cy.get('#admin-users-create input[name="first_name"]').should('have.value', firstName); cy.get('#admin-users-create input[name="last_name"]').type(lastName); @@ -52,12 +33,12 @@ context('Creat User Browser Testing', () => { it('should click on create user button', () => { cy.get('#admin-users-create input[type="submit"]').click(); }); - it('should provide errors about erroneous user data', () => { + it('should provide errors about incorrect user data', () => { // TO-DO: Check for error messages cy.get('element') .should('contain.text', 'Error message.'); });*/ - it('should enter user data and submit', () => { + it('should enter correct user data', () => { cy.get('#admin-users-create input[name="first_name"]').clear().type(firstName); cy.get('#admin-users-create input[name="first_name"]').should('have.value', firstName); cy.get('#admin-users-create input[name="last_name"]').clear().type(lastName); @@ -75,5 +56,9 @@ context('Creat User Browser Testing', () => { expect(loc.pathname).to.eq('/admin/admin-users'); }); }); + it('should land newly created user on users list screen', () => { + cy.contains('solid-display-value[name="name"]', firstName + ' ' + lastName).should("exist"); + cy.contains('solid-display-value[name="username"]', username).should("exist"); + }); }); }); diff --git a/cypress/integration/edit-channel.spec.js b/cypress/integration/edit-channel.spec.js new file mode 100644 index 0000000..32a702a --- /dev/null +++ b/cypress/integration/edit-channel.spec.js @@ -0,0 +1,58 @@ +/// +/* globals cy, expect */ + +context('Edit Channel Browser Testing', () => { + let channelName = 'Edited Test Channel ', + description = 'Edited Test Description ', + menuQuery = [ + 'solid-display.circle-tab', + 'solid-display:last-child', + 'solid-display[order-by="name"]' + ]; + before(() => { + cy.randomNum().then(num => { + channelName += num; + description += num; + }); + cy.clearLocalStorage({ domain: null }); + cy.clearCookies({ domain: null }); + }); + it('should visit user login screen', () => cy.userLogin()); + describe('Channel Edition process', () => { + it('should login', () => cy.login()); + it('should visit the channel list screen', () => cy.naviagte('/admin')); + it('should visit the last channel edit screen', () => { + cy.get(menuQuery.join(' ')) + .invoke('attr', 'data-src') + .then(url => cy.encodeUrl(url).then(id => { + cy.naviagte('/circle/@' + id + '/circle-information/circle-edit'); + })); + }); + it('should enter new channel data', () => { + cy.get('#circle-edit input[name="name"]').clear().type(channelName); + cy.get('#circle-edit input[name="name"]').should('have.value', channelName); + cy.get('#circle-edit input[name="description"]').clear().type(description); + cy.get('#circle-edit input[name="description"]').should('have.value', description); + }); + it('should click button to save the channel', () => { + cy.get('#circle-edit input[value="Enregistrer"]').click(); + }); + it('should land on channel information screen', () => { + cy.get(menuQuery.join(' ')) + .invoke('attr', 'data-src') + .then(url => cy.encodeUrl(url).then(id => { + cy.location().should((loc) => { + expect(loc.pathname).to.eq('/circle/@' + id + '/circle-information'); + }); + })); + // Workaround - component reactivity bug + cy.reload(); + cy.get('.accept-button').click(); + // End workaround + }); + it('should show edited channel data on channel information screen', () => { + cy.contains('solid-display-value[name="name"]', channelName).should("exist"); + cy.contains('solid-display-value[name="description"]', description).should("exist"); + }); + }); +}); diff --git a/cypress/integration/edit-job-offer.spec.js b/cypress/integration/edit-job-offer.spec.js new file mode 100644 index 0000000..10a7b27 --- /dev/null +++ b/cypress/integration/edit-job-offer.spec.js @@ -0,0 +1,59 @@ +/// +/* globals cy, expect */ + +context('Edit Job Offer Browser Testing', () => { + let jobDate = '', + jobTitle = 'Edited Test Job Offer ', + description = 'Edited Test Description ', + menuQuery = [ + 'solid-display.job-board__list', + 'solid-display:last-child' + ]; + before(() => { + cy.nextYear(2).then(year => { + jobDate = year + '-12-31'; + }); + cy.randomNum().then(num => { + jobTitle += num; + description += num; + }); + cy.clearLocalStorage({ domain: null }); + cy.clearCookies({ domain: null }); + }); + it('should visit user login screen', () => cy.userLogin()); + describe('Job Offer Edition process', () => { + it('should login', () => cy.login()); + it('should visit the job offers list screen', () => cy.naviagte('/job-offers')); + it('should visit the last project edit screen', () => { + cy.get(menuQuery.join(' ')) + .invoke('attr', 'data-src') + .then(url => cy.encodeUrl(url).then(id => { + cy.naviagte('/job-offers/job-offers-edit/@' + id); + })); + }); + it('should enter new job offer data', () => { + cy.get('#job-offers-edit input[name="closingDate"]').clear().type(jobDate); + cy.get('#job-offers-edit input[name="closingDate"]').should('have.value', jobDate); + cy.get('#job-offers-edit input[name="title"]').clear().type(jobTitle); + cy.get('#job-offers-edit input[name="title"]').should('have.value', jobTitle); + cy.get('#job-offers-edit textarea[name="description"]').clear().type(description); + cy.get('#job-offers-edit textarea[name="description"]').should('have.value', description); + }); + it('should click button to save the job offer', () => { + cy.get('#job-offers-edit input[type="submit"]').click(); + }); + it('should land on job offers list screen', () => { + cy.location().should((loc) => { + expect(loc.pathname).to.eq('/job-offers'); + }); + // Workaround - component reactivity bug + cy.reload(); + cy.get('.accept-button').click(); + // End workaround + }); + it('should show edited project data on project information screen', () => { + cy.contains('solid-display-value[name="title"]', jobTitle).should("exist"); + cy.contains('solid-display-value[name="description"]', description).should("exist"); + }); + }); +}); diff --git a/cypress/integration/edit-project.spec.js b/cypress/integration/edit-project.spec.js new file mode 100644 index 0000000..e7a532d --- /dev/null +++ b/cypress/integration/edit-project.spec.js @@ -0,0 +1,62 @@ +/// +/* globals cy, expect */ + +context('Edit Project Browser Testing', () => { + let projectName = 'Edited Test Project ', + customerName = 'Edited Test Customer ', + description = 'Edited Test Description ', + menuQuery = [ + 'solid-display.project-tab', + 'solid-display:last-child', + 'solid-display[order-by="customer.name"]' + ]; + before(() => { + cy.randomNum().then(num => { + projectName += num; + customerName += num; + description += num; + }); + cy.clearLocalStorage({ domain: null }); + cy.clearCookies({ domain: null }); + }); + it('should visit user login screen', () => cy.userLogin()); + describe('Project Edition process', () => { + it('should login', () => cy.login()); + it('should visit the project list screen', () => cy.naviagte('/admin/admin-projects')); + it('should visit the last project edit screen', () => { + cy.get(menuQuery.join(' ')) + .invoke('attr', 'data-src') + .then(url => cy.encodeUrl(url).then(id => { + cy.naviagte('/project/@' + id + '/project-information/project-edit'); + })); + }); + it('should enter new project data', () => { + cy.get('#project-edit input[name="customer.name"]').clear().type(customerName); + cy.get('#project-edit input[name="customer.name"]').should('have.value', customerName); + cy.get('#project-edit input[name="name"]').clear().type(projectName); + cy.get('#project-edit input[name="name"]').should('have.value', projectName); + cy.get('#project-edit textarea[name="description"]').clear().type(description); + cy.get('#project-edit textarea[name="description"]').should('have.value', description); + }); + it('should click button to save the project', () => { + cy.get('#project-edit input[value="Enregistrer"]').click(); + }); + it('should land on project information screen', () => { + cy.get(menuQuery.join(' ')) + .invoke('attr', 'data-src') + .then(url => cy.encodeUrl(url).then(id => { + cy.location().should((loc) => { + expect(loc.pathname).to.eq('/project/@' + id + '/project-information'); + }); + })); + // Workaround - component reactivity bug + cy.reload(); + cy.get('.accept-button').click(); + // End workaround + }); + it('should show edited project data on project information screen', () => { + cy.contains('solid-display-value[name="customer.name"]', customerName).should("exist"); + cy.contains('solid-display-value[name="name"]', projectName).should("exist"); + }); + }); +}); diff --git a/cypress/integration/retire-project.spec.js b/cypress/integration/retire-project.spec.js new file mode 100644 index 0000000..0584d6e --- /dev/null +++ b/cypress/integration/retire-project.spec.js @@ -0,0 +1,35 @@ +/// +/* globals cy, expect */ + +context('Retire Project Browser Testing', () => { + before(() => { + cy.clearLocalStorage({ domain: null }); + cy.clearCookies({ domain: null }); + }); + it('should visit user login screen', () => cy.userLogin()); + describe('Project Retirement process', () => { + it('should login', () => cy.login()); + it('should visit the project creation screen', () => cy.naviagte('/admin/admin-projects')); + it('should visit the last project edit screen', () => { + cy.get('solid-display[widget-project="hubl-menu-fix-url-project"][fields="project"]:last-child solid-display') + .invoke('attr', 'data-src') + .then(url => cy.encodeUrl(url).then(id => { + cy.naviagte('/project/@' + id + '/project-information/project-edit'); + })); + }); + it('should click button to retire the project', () => { + cy.scrollTo('bottom'); + cy.get('solid-delete[data-label="Retirer"] button').click(); + }); + it('should stay on project edit screen', () => { + cy.get('solid-display[widget-project="hubl-menu-fix-url-project"]:last-child solid-display') + .invoke('attr', 'data-src') + .then(url => cy.encodeUrl(url).then(id => { + cy.location().should((loc) => { + expect(loc.pathname).to.eq('/project/@' + id + '/project-information/project-edit'); + }); + })); + }); + // TO-DO: ceraify what needs to happen after and do the checks + }); +}); diff --git a/cypress/integration/tests.spec.js b/cypress/integration/signin.spec.js similarity index 70% rename from cypress/integration/tests.spec.js rename to cypress/integration/signin.spec.js index ba53571..62e1265 100644 --- a/cypress/integration/tests.spec.js +++ b/cypress/integration/signin.spec.js @@ -1,43 +1,36 @@ /// - +/* globals cy, expect */ context('Browser testing', () => { - before(() => { - cy.clearLocalStorage({ domain: null}); - cy.clearCookies({ domain: null }); + before(() => { + cy.clearLocalStorage({ domain: null}); + cy.clearCookies({ domain: null }); + }); + it('should visit user login screen', () => cy.userLogin()); + describe('Login process', () => { + it('should write "admin" on username field and "password" on password field', () => { + cy.get('#id_username').type('admin'); + cy.get('#id_username').should('have.value', 'admin'); + cy.get('#id_password').type('password'); + cy.get('#id_password').should('have.value', 'password'); }); - it('visit the homepage', () => { - cy.visit('/'); + it('should click on login button', () => { + cy.get(':nth-child(1) > .flex-column > [type="submit"]').click(); }); - it('should await for an user login', () => { + it('should provide an error, username and password mismatch.', () => { + cy.get('.error').should('contain.text', 'Ton nom d\'utilisateur et ton mot de passe ne correspondent pas. Réessaye.'); + }); + it('should write "admin" on password field then press the login button', () => { + cy.get('#id_password').type('admin'); + cy.get('#id_password').should('have.value', 'admin'); + cy.get(':nth-child(1) > .flex-column > [type="submit"]').click(); + }); + it('should ask for user permission to access their datas.', () => { cy.location().should((loc) => { - expect(loc.pathname).to.eq('/auth/login/'); + expect(loc.pathname).to.eq('/authorize'); }); + cy.get('.accept-button').click(); }); - describe('Login process', () => { - it('should write "admin" on username field and "password" on password field', () => { - cy.get('#id_username').type('admin'); - cy.get('#id_username').should('have.value', 'admin'); - cy.get('#id_password').type('password'); - cy.get('#id_password').should('have.value', 'password'); - }); - it('should click on login button', () => { - cy.get(':nth-child(1) > .flex-column > [type="submit"]').click(); - }); - it('should provide an error, username and password mismatch.', () => { - cy.get('.error').should('contain.text', 'Ton nom d\'utilisateur et ton mot de passe ne correspondent pas. Réessaye.') - }); - it('should write "admin" on password field then press the login button', () => { - cy.get('#id_password').type('admin'); - cy.get('#id_password').should('have.value', 'admin'); - cy.get(':nth-child(1) > .flex-column > [type="submit"]').click(); - }); - it('should ask for user permission to access their datas.', () => { - cy.location().should((loc) => { - expect(loc.pathname).to.eq('/authorize') - }); - cy.get('.accept-button').click(); - }); // it('should redirect the user to the app.', () => { // cy.get('.accept-button').click(); // cy.location().should((loc) => { @@ -103,6 +96,5 @@ context('Browser testing', () => { // expect(loc.pathname).to.eq('/auth/login/'); // }); // }); - }); }); - +}); diff --git a/cypress/integration/signup.spec.js b/cypress/integration/signup.spec.js index 4a77c44..9597980 100644 --- a/cypress/integration/signup.spec.js +++ b/cypress/integration/signup.spec.js @@ -1,27 +1,24 @@ /// -/* globals cy, expect */ +/* globals cy */ context('Signup Browser Testing', () => { - const username = 'testuser_signup_' + Math.floor(1000 + Math.random() * 9000), - email = username + '@testemail.com', - password = 'testpwd'; + let username = 'testuser_creation_', + email = '', + password = 'testpwd'; before(() => { + cy.randomNum().then(num => { + username += num; + email = username + '@testemail.com'; + }); cy.clearLocalStorage({ domain: null }); cy.clearCookies({ domain: null }); }); - it('visit the homepage', () => { - cy.visit('/'); - }); - it('should await for an user login', () => { - cy.location().should((loc) => { - expect(loc.pathname).to.eq('/auth/login/'); - }); - }); + it('should visit user login screen', () => cy.userLogin()); describe('Signup process', () => { it('should click on signup page link', () => { cy.get('.sib-link.sib-register-link').click(); }); - it('should write erroneous user data', () => { + it('should write incorrect user data', () => { cy.get('#id_username').type('!"#$%&'); cy.get('#id_username').should('have.value', '!"#$%&'); cy.get('#id_email').type(email.split('.')[0]); @@ -34,7 +31,7 @@ context('Signup Browser Testing', () => { it('should click on signup button', () => { cy.get('.sib-registration-btn').click(); }); - it('should provide errors about erroneous user data', () => { + it('should provide errors about incorrect user data', () => { cy.get('tbody tr:nth-child(1) ul.errorlist li') .should('contain.text', 'Enter a valid username. This value may contain only letters, numbers, and ./+/-/_ characters.'); cy.get('tbody tr:nth-child(2) ul.errorlist li') @@ -55,5 +52,9 @@ context('Signup Browser Testing', () => { it('should click on signup button', () => { cy.get('.sib-registration-btn').click(); }); + it('should show email confirmation dialog', () => { + cy.contains('h1.text-center', 'Un e-mail d\'activation a été envoyé.').should("exist"); + cy.contains('p.text-center', 'Vérifie ta boite mail et clique sur le lien pour activer ton compte.').should("exist"); + }); }); }); diff --git a/cypress/support/commands.js b/cypress/support/commands.js index ca4d256..1450915 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -23,3 +23,58 @@ // // -- This will overwrite an existing command -- // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) + +/* globals Cypress, cy, expect */ + +Cypress.Commands.add('login', () => { + cy.fixture('admin.json').then(admin => { + cy.get('#id_username').type(admin.username); + cy.get('#id_username').should('have.value', admin.username); + cy.get('#id_password').type(admin.password); + cy.get('#id_password').should('have.value', admin.password); + cy.get('.connection-btn').click(); + cy.get('.accept-button').click(); + cy.location().should((loc) => { + expect(loc.pathname).to.eq('/'); + }); + }); +}); + +Cypress.Commands.add('naviagte', route => { + cy.visit(route); + cy.location().should((loc) => { + expect(loc.pathname).to.eq(route); + }); + // Workaround - seems to be a bug when accessing the route directly + cy.get('.accept-button').click(); + cy.wait(2000); + // End workaround +}); + +Cypress.Commands.add('userLogin', () => { + cy.visit('/'); + cy.location().should((loc) => { + expect(loc.pathname).to.eq('/auth/login/'); + }); +}); + +Cypress.Commands.add('encodeUrl', url => { + const encodeIdReplacement = [ + ['~', '~~'], + ['.', '~!'], + [':', '~@'], + ['/', '~_'], + ]; + encodeIdReplacement.forEach(([char, repl]) => { + url = url.split(char).join(repl); + }); + return url; +}); + +Cypress.Commands.add('randomNum', () => { + return Math.floor(1000 + Math.random() * 9000); +}); + +Cypress.Commands.add('nextYear', increment => { + return new Date().getFullYear() + ( increment || 1 ); +}); diff --git a/cypress/support/index.js b/cypress/support/index.js index 92fa6f5..cc8bcf0 100644 --- a/cypress/support/index.js +++ b/cypress/support/index.js @@ -13,10 +13,12 @@ // https://on.cypress.io/configuration // *********************************************************** -// Import commands.js using ES2015 syntax: -import './commands' +/* globals Cypress */ -//require('cypress-terminal-report').installSupport(); +// Import commands.js using ES2015 syntax: +import './commands'; + +require('cypress-terminal-report').installSupport(); // Alternatively you can use CommonJS syntax: // require('./commands') @@ -27,4 +29,9 @@ Cypress.on('uncaught:exception', (err, runnable) => { return false; }); -Cypress.on('fail', () => Cypress.runner.abort()) +Cypress.on('fail', (error) => { + console.log(error); + if ( typeof Cypress.runner.abort == 'function' ) { + Cypress.runner.abort(); + } +});