hubl/cypress/integration/create-user.spec.js

68 lines
3.2 KiB
JavaScript
Raw Normal View History

/// <reference types="Cypress" />
/* globals cy, expect */
context('Create User Browser Testing', () => {
let firstName = 'First ',
lastName = 'Last ',
username = 'testuser_creation_',
email = '';
before(() => {
cy.randomNum().then(num => {
firstName += num;
lastName += num;
username += num;
email = username + '@testemail.com';
});
cy.clearLocalStorageSnapshot();
cy.clearLocalStorage({ domain: null });
cy.clearCookies({ domain: null });
});
beforeEach(() => cy.restoreLocalStorage());
afterEach(() => cy.saveLocalStorage());
it('should visit user login screen', () => cy.userLogin());
describe('User Creation process', () => {
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);
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 incorrect user data', () => {
// TO-DO: Check for error messages
cy.get('element')
.should('contain.text', 'Error message.');
});*/
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);
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');
});
});
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");
});
});
});