Refactor to use custom commands for login/logout & make admin user configurable

This commit is contained in:
Tim Donohue
2021-12-21 17:14:27 -06:00
parent 1f1c55d9dc
commit cb91ccbc33
4 changed files with 93 additions and 64 deletions

View File

@@ -1,34 +1,27 @@
import { TEST_ENTITY_PUBLICATION } from 'cypress/support';
import { TEST_ADMIN_PASSWORD, TEST_ADMIN_USER, TEST_ENTITY_PUBLICATION } from 'cypress/support';
const page = {
openLoginMenu() {
// Click the closed "Log In" dropdown menu (to open Login menu)
cy.get('ds-auth-nav-menu.navbar-collapsed').click();
},
submitLoginAndPassword() {
// In opened Login modal, fill out email & password, then click submit
cy.get('ds-themed-navbar ds-log-in-password input[type = "email"]').type('dspacedemo+admin@gmail.com');
cy.get('ds-themed-navbar ds-log-in-password input[type = "password"]').type('dspace');
cy.get('ds-themed-navbar ds-log-in-password button[type = "submit"]').click();
},
submitLoginAndPasswordByPressingEnter() {
submitLoginAndPasswordByPressingEnter(email, password) {
// In opened Login modal, fill out email & password, then click Enter
cy.get('ds-themed-navbar ds-log-in-password input[type = "email"]').type('dspacedemo+admin@gmail.com');
cy.get('ds-themed-navbar ds-log-in-password input[type = "password"]').type('dspace');
cy.get('ds-themed-navbar ds-log-in-password input[type = "email"]').type(email);
cy.get('ds-themed-navbar ds-log-in-password input[type = "password"]').type(password);
cy.get('ds-themed-navbar ds-log-in-password input[type = "password"]').type('{enter}');
},
}
};
describe('Login Modal', () => {
it('should login when clicking button', () => {
cy.visit('/');
// Open login menu in header & verify <ds-log-in> tag is visible
page.openLoginMenu();
cy.get('ds-log-in').should('be.visible');
// Login menu should exist
cy.get('ds-log-in').should('exist');
// Login, and the <ds-log-in> tag should no longer exist
page.submitLoginAndPassword();
cy.login(TEST_ADMIN_USER, TEST_ADMIN_PASSWORD);
cy.get('ds-log-in').should('not.exist');
// Open login menu again, verify user menu & logout button now available
@@ -37,7 +30,7 @@ describe('Login Modal', () => {
cy.get('ds-log-out').should('be.visible');
});
it('should login when clicking enter', () => {
it('should login when clicking enter key', () => {
cy.visit('/');
// Open login menu in header & verify <ds-log-in> tag is visible
@@ -45,7 +38,7 @@ describe('Login Modal', () => {
cy.get('.form-login').should('be.visible');
// Login, and the <ds-log-in> tag should no longer exist
page.submitLoginAndPasswordByPressingEnter();
page.submitLoginAndPasswordByPressingEnter(TEST_ADMIN_USER, TEST_ADMIN_PASSWORD);
cy.get('.form-login').should('not.exist');
// Open login menu again, verify user menu & logout button now available
@@ -58,12 +51,11 @@ describe('Login Modal', () => {
const ENTITYPAGE = '/entities/publication/' + TEST_ENTITY_PUBLICATION;
cy.visit(ENTITYPAGE);
// Open login menu in header & verify <ds-log-in> tag is visible
page.openLoginMenu();
cy.get('ds-log-in').should('be.visible');
// Login menu should exist
cy.get('ds-log-in').should('exist');
// Login, and the <ds-log-in> tag should no longer exist
page.submitLoginAndPassword();
cy.login(TEST_ADMIN_USER, TEST_ADMIN_PASSWORD);
cy.get('ds-log-in').should('not.exist');
// Verify we are still on the same page
@@ -74,4 +66,23 @@ describe('Login Modal', () => {
cy.get('ds-user-menu').should('be.visible');
cy.get('ds-log-out').should('be.visible');
});
it('logout should work', () => {
cy.visit('/');
cy.get('ds-log-in').should('exist');
cy.get('ds-log-out').should('not.exist');
// Click login
cy.login(TEST_ADMIN_USER, TEST_ADMIN_PASSWORD);
cy.get('ds-log-in').should('not.exist');
cy.get('ds-log-out').should('exist');
// Click logout
cy.logout();
cy.get('ds-log-in').should('exist');
cy.get('ds-log-out').should('not.exist');
});
});