92 lines
3.5 KiB
JavaScript
92 lines
3.5 KiB
JavaScript
describe('Login Tests', () => {
|
|
const rememberCheckbox = '[data-testid="rememberCheckbox"]';
|
|
|
|
beforeEach(() => {
|
|
cy.visit('/#/login');
|
|
});
|
|
|
|
it('should toggle password visibility', () => {
|
|
cy.dataCy('showPasswordIcon').should('exist');
|
|
cy.dataCy('showPasswordIcon').click();
|
|
cy.dataCy('showPasswordIcon').should('have.text', 'visibility_off');
|
|
cy.dataCy('showPasswordIcon').click();
|
|
cy.dataCy('showPasswordIcon').should('have.text', 'visibility');
|
|
});
|
|
|
|
it('should select a language from the dropdown', () => {
|
|
cy.dataCy('switchLanguage').should('exist');
|
|
cy.changeLanguage('en');
|
|
cy.get('button[type="submit"]').should('contain', 'Log in');
|
|
cy.changeLanguage('es');
|
|
cy.get('button[type="submit"]').should('contain', 'Iniciar sesión');
|
|
});
|
|
|
|
it('should fail to log in using wrong user', () => {
|
|
cy.dataCy('loginUserInput').type('incorrectUser');
|
|
cy.dataCy('loginPasswordInput').type('nightmare');
|
|
cy.get('button[type="submit"]').click();
|
|
cy.dataCy('negativeNotify').should('contain', 'login failed');
|
|
});
|
|
|
|
it('should fail to log in using wrong password', () => {
|
|
cy.dataCy('loginUserInput').type('incorrectUser');
|
|
cy.dataCy('loginPasswordInput').type('nightmare');
|
|
cy.get('button[type="submit"]').click();
|
|
cy.dataCy('negativeNotify').should('contain', 'login failed');
|
|
});
|
|
|
|
it('should log in', () => {
|
|
cy.loginFlow('employee');
|
|
});
|
|
|
|
it('should log in as guest', () => {
|
|
cy.dataCy('loginAsGuestButton').should('exist');
|
|
cy.dataCy('loginAsGuestButton').click();
|
|
cy.url().should('contain', '/#/cms/home');
|
|
});
|
|
|
|
it('should save localStorage keepLogin true value if remember checkbox is checked', () => {
|
|
cy.dataCy('rememberCheckbox').should('exist');
|
|
cy.dataCy('rememberCheckbox').click();
|
|
cy.getValue(rememberCheckbox).should('equal', 'true');
|
|
cy.loginFlow('employee', false);
|
|
cy.window().then(window => {
|
|
expect(window.localStorage.getItem('keepLogin')).to.eq('true');
|
|
});
|
|
});
|
|
|
|
it('should save localStorage keepLogin false value if remember checkbox is not checked', () => {
|
|
cy.dataCy('rememberCheckbox').should('exist');
|
|
cy.getValue(rememberCheckbox).should('equal', 'false');
|
|
cy.loginFlow('employee', false);
|
|
cy.window().then(window => {
|
|
expect(window.localStorage.getItem('keepLogin')).to.eq('false');
|
|
});
|
|
});
|
|
|
|
it('saves data in session storage if remember is not checked', () => {
|
|
cy.dataCy('rememberCheckbox').should('exist');
|
|
cy.getValue(rememberCheckbox).should('equal', 'false');
|
|
cy.loginFlow('employee', false);
|
|
cy.window().then(window => {
|
|
expect(window.sessionStorage.getItem('hederaLastUser')).to.eq(
|
|
'employee'
|
|
);
|
|
expect(window.localStorage.getItem('hederaLastUser')).to.eq(null);
|
|
});
|
|
});
|
|
|
|
it('saves data in local storage if remember is checked', () => {
|
|
cy.dataCy('rememberCheckbox').should('exist');
|
|
cy.dataCy('rememberCheckbox').click();
|
|
cy.getValue(rememberCheckbox).should('equal', 'true');
|
|
cy.loginFlow('employee', false);
|
|
cy.window().then(window => {
|
|
expect(window.localStorage.getItem('hederaLastUser')).to.eq(
|
|
'employee'
|
|
);
|
|
expect(window.sessionStorage.getItem('hederaLastUser')).to.eq(null);
|
|
});
|
|
});
|
|
});
|