diff --git a/cypress.json b/cypress.json index dfa75fdc57..2f3a1e8fe1 100644 --- a/cypress.json +++ b/cypress.json @@ -6,7 +6,10 @@ "pluginsFile": "cypress/plugins/index.ts", "fixturesFolder": "cypress/fixtures", "baseUrl": "http://localhost:4000", - "retries": 2, + "retries": { + "runMode": 2, + "openMode": 0 + }, "env": { "DSPACE_TEST_COMMUNITY": "0958c910-2037-42a9-81c7-dca80e3892b4", "DSPACE_TEST_COLLECTION": "282164f5-d325-4740-8dd1-fa4d6d3e7200", diff --git a/cypress/integration/login-modal.spec.ts b/cypress/integration/login-modal.spec.ts new file mode 100644 index 0000000000..da0eb4802a --- /dev/null +++ b/cypress/integration/login-modal.spec.ts @@ -0,0 +1,77 @@ +import { 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() { + // 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 = "password"]').type('{enter}'); + }, +}; + +describe('Login Modal', () => { + it('should login when clicking button', () => { + cy.visit('/'); + + // Open login menu in header & verify tag is visible + page.openLoginMenu(); + cy.get('ds-log-in').should('be.visible'); + + // Login, and the tag should no longer exist + page.submitLoginAndPassword(); + cy.get('ds-log-in').should('not.exist'); + + // Open login menu again, verify user menu & logout button now available + page.openLoginMenu(); + cy.get('ds-user-menu').should('be.visible'); + cy.get('ds-log-out').should('be.visible'); + }); + + it('should login when clicking enter', () => { + cy.visit('/'); + + // Open login menu in header & verify tag is visible + page.openLoginMenu(); + cy.get('.form-login').should('be.visible'); + + // Login, and the tag should no longer exist + page.submitLoginAndPasswordByPressingEnter(); + cy.get('.form-login').should('not.exist'); + + // Open login menu again, verify user menu & logout button now available + page.openLoginMenu(); + cy.get('ds-user-menu').should('be.visible'); + cy.get('ds-log-out').should('be.visible'); + }); + + it('should stay on same page after login', () => { + const ENTITYPAGE = '/entities/publication/' + TEST_ENTITY_PUBLICATION; + cy.visit(ENTITYPAGE); + + // Open login menu in header & verify tag is visible + page.openLoginMenu(); + cy.get('ds-log-in').should('be.visible'); + + // Login, and the tag should no longer exist + page.submitLoginAndPassword(); + cy.get('ds-log-in').should('not.exist'); + + // Verify we are still on the same page + cy.url().should('include', ENTITYPAGE); + + // Open login menu again, verify user menu & logout button now available + page.openLoginMenu(); + cy.get('ds-user-menu').should('be.visible'); + cy.get('ds-log-out').should('be.visible'); + }); +}); diff --git a/cypress/support/index.ts b/cypress/support/index.ts index 5a30a5e002..de00a33534 100644 --- a/cypress/support/index.ts +++ b/cypress/support/index.ts @@ -25,6 +25,6 @@ import 'cypress-axe'; // Default UUIDs listed here are all in the Demo Entities Data set available at // https://github.com/DSpace-Labs/AIP-Files/releases/tag/demo-entities-data // (This is the data set used in our CI environment) -export const TEST_COLLECTION = Cypress.env("DSPACE_TEST_COLLECTION") || '282164f5-d325-4740-8dd1-fa4d6d3e7200'; -export const TEST_COMMUNITY = Cypress.env("DSPACE_TEST_COMMUNITY") || '0958c910-2037-42a9-81c7-dca80e3892b4'; -export const TEST_ENTITY_PUBLICATION = Cypress.env("DSPACE_TEST_ENTITY_PUBLICATION") || 'e98b0f27-5c19-49a0-960d-eb6ad5287067'; +export const TEST_COLLECTION = Cypress.env('DSPACE_TEST_COLLECTION') || '282164f5-d325-4740-8dd1-fa4d6d3e7200'; +export const TEST_COMMUNITY = Cypress.env('DSPACE_TEST_COMMUNITY') || '0958c910-2037-42a9-81c7-dca80e3892b4'; +export const TEST_ENTITY_PUBLICATION = Cypress.env('DSPACE_TEST_ENTITY_PUBLICATION') || 'e98b0f27-5c19-49a0-960d-eb6ad5287067';