|
| 1 | +import { TEST_ADMIN_PASSWORD, TEST_ADMIN_USER, TEST_ENTITY_PUBLICATION } from 'cypress/support/e2e'; |
| 2 | +import { testA11y } from 'cypress/support/utils'; |
| 3 | + |
| 4 | +const page = { |
| 5 | + openLoginMenu() { |
| 6 | + // Click the "Log In" dropdown menu in header |
| 7 | + cy.get('ds-themed-navbar [data-test="login-menu"]').click(); |
| 8 | + }, |
| 9 | + openUserMenu() { |
| 10 | + // Once logged in, click the User menu in header |
| 11 | + cy.get('ds-themed-navbar [data-test="user-menu"]').click(); |
| 12 | + }, |
| 13 | + submitLoginAndPasswordByPressingButton(email, password) { |
| 14 | + // Enter email |
| 15 | + cy.get('ds-themed-navbar [data-test="email"]').type(email); |
| 16 | + // Enter password |
| 17 | + cy.get('ds-themed-navbar [data-test="password"]').type(password); |
| 18 | + // Click login button |
| 19 | + cy.get('ds-themed-navbar [data-test="login-button"]').click(); |
| 20 | + }, |
| 21 | + submitLoginAndPasswordByPressingEnter(email, password) { |
| 22 | + // In opened Login modal, fill out email & password, then click Enter |
| 23 | + cy.get('ds-themed-navbar [data-test="email"]').type(email); |
| 24 | + cy.get('ds-themed-navbar [data-test="password"]').type(password); |
| 25 | + cy.get('ds-themed-navbar [data-test="password"]').type('{enter}'); |
| 26 | + }, |
| 27 | + submitLogoutByPressingButton() { |
| 28 | + // This is the POST command that will actually log us out |
| 29 | + cy.intercept('POST', '/server/api/authn/logout').as('logout'); |
| 30 | + // Click logout button |
| 31 | + cy.get('ds-themed-navbar [data-test="logout-button"]').click(); |
| 32 | + // Wait until above POST command responds before continuing |
| 33 | + // (This ensures next action waits until logout completes) |
| 34 | + cy.wait('@logout'); |
| 35 | + } |
| 36 | +}; |
| 37 | + |
| 38 | +// CLARIN - CLARIN-DSpace7.x has different login |
| 39 | +// describe('Login Modal', () => { |
| 40 | +// it('should login when clicking button & stay on same page', () => { |
| 41 | +// const ENTITYPAGE = '/entities/publication/'.concat(TEST_ENTITY_PUBLICATION); |
| 42 | +// cy.visit(ENTITYPAGE); |
| 43 | +// |
| 44 | +// // Login menu should exist |
| 45 | +// cy.get('ds-log-in').should('exist'); |
| 46 | +// |
| 47 | +// // Login, and the <ds-log-in> tag should no longer exist |
| 48 | +// page.openLoginMenu(); |
| 49 | +// cy.get('.form-login').should('be.visible'); |
| 50 | +// |
| 51 | +// page.submitLoginAndPasswordByPressingButton(TEST_ADMIN_USER, TEST_ADMIN_PASSWORD); |
| 52 | +// cy.get('ds-log-in').should('not.exist'); |
| 53 | +// |
| 54 | +// // Verify we are still on the same page |
| 55 | +// cy.url().should('include', ENTITYPAGE); |
| 56 | +// |
| 57 | +// // Open user menu, verify user menu & logout button now available |
| 58 | +// page.openUserMenu(); |
| 59 | +// cy.get('ds-user-menu').should('be.visible'); |
| 60 | +// cy.get('ds-log-out').should('be.visible'); |
| 61 | +// }); |
| 62 | +// |
| 63 | +// it('should login when clicking enter key & stay on same page', () => { |
| 64 | +// cy.visit('/home'); |
| 65 | +// |
| 66 | +// // Open login menu in header & verify <ds-log-in> tag is visible |
| 67 | +// page.openLoginMenu(); |
| 68 | +// cy.get('.form-login').should('be.visible'); |
| 69 | +// |
| 70 | +// // Login, and the <ds-log-in> tag should no longer exist |
| 71 | +// page.submitLoginAndPasswordByPressingEnter(TEST_ADMIN_USER, TEST_ADMIN_PASSWORD); |
| 72 | +// cy.get('.form-login').should('not.exist'); |
| 73 | +// |
| 74 | +// // Verify we are still on homepage |
| 75 | +// cy.url().should('include', '/home'); |
| 76 | +// |
| 77 | +// // Open user menu, verify user menu & logout button now available |
| 78 | +// page.openUserMenu(); |
| 79 | +// cy.get('ds-user-menu').should('be.visible'); |
| 80 | +// cy.get('ds-log-out').should('be.visible'); |
| 81 | +// }); |
| 82 | +// |
| 83 | +// it('should support logout', () => { |
| 84 | +// // First authenticate & access homepage |
| 85 | +// cy.login(TEST_ADMIN_USER, TEST_ADMIN_PASSWORD); |
| 86 | +// cy.visit('/'); |
| 87 | +// |
| 88 | +// // Verify ds-log-in tag doesn't exist, but ds-log-out tag does exist |
| 89 | +// cy.get('ds-log-in').should('not.exist'); |
| 90 | +// cy.get('ds-log-out').should('exist'); |
| 91 | +// |
| 92 | +// // Click logout button |
| 93 | +// page.openUserMenu(); |
| 94 | +// page.submitLogoutByPressingButton(); |
| 95 | +// |
| 96 | +// // Verify ds-log-in tag now exists |
| 97 | +// cy.get('ds-log-in').should('exist'); |
| 98 | +// cy.get('ds-log-out').should('not.exist'); |
| 99 | +// }); |
| 100 | +// |
| 101 | +// it('should allow new user registration', () => { |
| 102 | +// cy.visit('/'); |
| 103 | +// |
| 104 | +// page.openLoginMenu(); |
| 105 | +// |
| 106 | +// // Registration link should be visible |
| 107 | +// cy.get('ds-themed-navbar [data-test="register"]').should('be.visible'); |
| 108 | +// |
| 109 | +// // Click registration link & you should go to registration page |
| 110 | +// cy.get('ds-themed-navbar [data-test="register"]').click(); |
| 111 | +// cy.location('pathname').should('eq', '/register'); |
| 112 | +// cy.get('ds-register-email').should('exist'); |
| 113 | +// }); |
| 114 | +// |
| 115 | +// it('should allow forgot password', () => { |
| 116 | +// cy.visit('/'); |
| 117 | +// |
| 118 | +// page.openLoginMenu(); |
| 119 | +// |
| 120 | +// // Forgot password link should be visible |
| 121 | +// cy.get('ds-themed-navbar [data-test="forgot"]').should('be.visible'); |
| 122 | +// |
| 123 | +// // Click link & you should go to Forgot Password page |
| 124 | +// cy.get('ds-themed-navbar [data-test="forgot"]').click(); |
| 125 | +// cy.location('pathname').should('eq', '/forgot'); |
| 126 | +// cy.get('ds-forgot-email').should('exist'); |
| 127 | +// }); |
| 128 | +// |
| 129 | +// it('should pass accessibility tests', () => { |
| 130 | +// cy.visit('/'); |
| 131 | +// |
| 132 | +// page.openLoginMenu(); |
| 133 | +// |
| 134 | +// cy.get('ds-log-in').should('exist'); |
| 135 | +// |
| 136 | +// // Analyze <ds-log-in> for accessibility issues |
| 137 | +// testA11y('ds-log-in'); |
| 138 | +// }); |
| 139 | +// }); |
0 commit comments