diff --git a/cypress/integration/create-user.spec.js b/cypress/integration/create-user.spec.js new file mode 100644 index 0000000..2670ba8 --- /dev/null +++ b/cypress/integration/create-user.spec.js @@ -0,0 +1,79 @@ +/// +/* 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'; + before(() => { + 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/'); + }); + }); + 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', () => { + 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); + cy.get('#admin-users-create input[name="last_name"]').should('have.value', lastName); + cy.get('#admin-users-create input[name="username"]').type('!"#$%&'); + cy.get('#admin-users-create input[name="username"]').should('have.value', '!"#$%&'); + cy.get('#admin-users-create input[name="email"]').type(email.split('.')[0]); + cy.get('#admin-users-create input[name="email"]').should('have.value', email.split('.')[0]); + }); + it('should click on create user button', () => { + cy.get('#admin-users-create input[type="submit"]').click(); + }); + it('should provide errors about erroneous user data', () => { + // TO-DO: Check for error messages + cy.get('element') + .should('contain.text', 'Error message.'); + });*/ + it('should enter user data and submit', () => { + 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); + cy.get('#admin-users-create input[name="last_name"]').should('have.value', lastName); + cy.get('#admin-users-create input[name="username"]').clear().type(username); + cy.get('#admin-users-create input[name="username"]').should('have.value', username); + cy.get('#admin-users-create input[name="email"]').clear().type(email); + cy.get('#admin-users-create input[name="email"]').should('have.value', email); + }); + it('should click on create user button', () => { + cy.get('#admin-users-create input[type="submit"]').click(); + }); + it('should land on users list screen', () => { + cy.location().should((loc) => { + expect(loc.pathname).to.eq('/admin/admin-users'); + }); + }); + }); +}); diff --git a/cypress/integration/signup.spec.js b/cypress/integration/signup.spec.js new file mode 100644 index 0000000..4a77c44 --- /dev/null +++ b/cypress/integration/signup.spec.js @@ -0,0 +1,59 @@ +/// +/* globals cy, expect */ + +context('Signup Browser Testing', () => { + const username = 'testuser_signup_' + Math.floor(1000 + Math.random() * 9000), + email = username + '@testemail.com', + password = 'testpwd'; + before(() => { + 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/'); + }); + }); + describe('Signup process', () => { + it('should click on signup page link', () => { + cy.get('.sib-link.sib-register-link').click(); + }); + it('should write erroneous user data', () => { + cy.get('#id_username').type('!"#$%&'); + cy.get('#id_username').should('have.value', '!"#$%&'); + cy.get('#id_email').type(email.split('.')[0]); + cy.get('#id_email').should('have.value', email.split('.')[0]); + cy.get('#id_password1').type(password + 'wrong1'); + cy.get('#id_password1').should('have.value', password + 'wrong1'); + cy.get('#id_password2').type(password + 'wrong2'); + cy.get('#id_password2').should('have.value', password + 'wrong2'); + }); + it('should click on signup button', () => { + cy.get('.sib-registration-btn').click(); + }); + it('should provide errors about erroneous 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') + .should('contain.text', 'Enter a valid email address.'); + cy.get('tbody tr:nth-child(4) ul.errorlist li') + .should('contain.text', 'The two password fields didn\'t match.'); + }); + it('should write correct user data', () => { + cy.get('#id_username').clear().type(username); + cy.get('#id_username').should('have.value', username); + cy.get('#id_email').clear().type(email); + cy.get('#id_email').should('have.value', email); + cy.get('#id_password1').clear().type(password); + cy.get('#id_password1').should('have.value', password); + cy.get('#id_password2').clear().type(password); + cy.get('#id_password2').should('have.value', password); + }); + it('should click on signup button', () => { + cy.get('.sib-registration-btn').click(); + }); + }); +});