diff --git a/ui/cypress/e2e/admin.cy.js b/ui/cypress/e2e/admin.cy.js index bfb1e88..83e9862 100644 --- a/ui/cypress/e2e/admin.cy.js +++ b/ui/cypress/e2e/admin.cy.js @@ -6,125 +6,45 @@ describe('admin', () => { it('Create new user', () => { cy.visit('/') - cy.get('.hidden > :nth-child(1)').click(); - - cy.wait(100); - - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > :nth-child(1) > .input > #email').clear('ad'); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > :nth-child(1) > .input > #email').type('admin@test.nl'); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > :nth-child(2) > .input > #password').clear(); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > :nth-child(2) > .input > #password').type('admin'); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > .modal-action > .btn').click(); - - cy.wait(100); - - cy.get('.text').click(); - cy.get('p.text-success').click(); - cy.get('thead > tr > .text-end > .btn').click(); - - cy.wait(100); - - cy.get('#email').clear('te'); - cy.get('#email').type('test@test.nl'); - cy.get('#password').clear(); - cy.get('#password').type('Testing1'); - cy.get('.modal-action > .btn').click(); - - cy.wait(100); - - cy.get(':nth-child(3) > summary.btn').click(); - cy.wait(50); - cy.get('.menu > :nth-child(3) > .btn').click(); - cy.wait(50); - cy.get('.hidden > :nth-child(1)').click(); - cy.wait(50); - - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > :nth-child(1) > .input').click(); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > :nth-child(1) > .input > #email').type('test@test.nl'); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > :nth-child(2) > .input > #password').clear(); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > :nth-child(2) > .input > #password').type('Testing1'); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > .modal-action > .btn').click(); - - cy.wait(50); - + cy.login("admin@test.nl", "admin") + cy.navigateToAdminPanel() + cy.createUser("user@test.nl", "Testing1", false) + cy.logout() + cy.login("user@test.nl", "Testing1") cy.url().should('include', '/home') }) it('Create another admin', function() { - cy.visit('/'); - cy.get('.hidden > :nth-child(1)').click(); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > :nth-child(1) > .input > #email').type('admin@test.nl'); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > :nth-child(2) > .input > #password').clear(); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > :nth-child(2) > .input > #password').type('admin'); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > .modal-action > .btn').click(); - cy.get('.text').click(); - cy.get('p.text-success').click(); - cy.get('thead > tr > .text-end').click(); - cy.get('.modal-box').click(); - cy.get('#email').clear('ad'); - cy.get('#email').type('admin2@test.nl'); - cy.get('#password').clear(); - cy.get('#password').type('Testing1'); - cy.get('.checkbox').check(); - cy.get('.modal-action > .btn').click(); - cy.get('.text').click(); - cy.get('.menu > :nth-child(3) > .btn').click(); - cy.get('.hidden > :nth-child(1)').click(); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > :nth-child(1) > .input > #email').type('admin2@test.nl'); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > :nth-child(2) > .input > #password').clear(); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > :nth-child(2) > .input > #password').type('Testing1'); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > .modal-action > .btn').click(); - cy.get('.text').click(); - cy.get(':nth-child(2) > .btn > .fa-solid').click(); + cy.visit('/') + cy.login("admin@test.nl", "admin") + cy.navigateToAdminPanel() + cy.createUser("another@admin.nl", "AdminAwesome1", true) + cy.logout() + cy.login("another@admin.nl", "AdminAwesome1") + cy.navigateToAdminPanel() cy.url().should('include', '/admin-panel') }); it('Delete user', function() { cy.visit('/'); - cy.get('.hidden > :nth-child(1)').click(); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > :nth-child(1) > .input > #email').clear('ad'); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > :nth-child(1) > .input > #email').type('admin@test.nl'); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > :nth-child(2) > .input > #password').clear(); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > :nth-child(2) > .input > #password').type('admin'); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > .modal-action > .btn').click(); - cy.get('.text').click(); - cy.get('p.text-success').click(); - cy.get('thead > tr > .text-end > .btn > .fa-solid').click(); - cy.get('#email').clear('te'); - cy.get('#email').type('test@test.nl'); - cy.get('#password').clear(); - cy.get('#password').type('Testing1'); - cy.get('.modal-action > .btn').click(); - cy.get('.text').click(); - cy.get('.menu > :nth-child(3) > .btn').click(); - cy.get('.hidden > :nth-child(1)').click(); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > :nth-child(1) > .input > #email').clear('te'); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > :nth-child(1) > .input > #email').type('test@test.nl'); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > :nth-child(2) > .input > #password').clear(); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > :nth-child(2) > .input > #password').type('Testing1'); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > .modal-action > .btn').click(); - cy.get('.text').click(); - cy.get('[open=""] > .menu > :nth-child(2) > .btn').click(); - cy.get('.hidden > :nth-child(1)').click(); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > :nth-child(1) > .input > #email').clear('ad'); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > :nth-child(1) > .input > #email').type('admin@test.nl'); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > :nth-child(2) > .input > #password').clear(); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > :nth-child(2) > .input > #password').type('admin'); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > .modal-action > .btn').click(); - cy.get('.text').click(); - cy.get('p.text-success').click(); - cy.get(':nth-child(2) > .text-end > .btn > .fa-solid').click(); - cy.get('.btn-error').click(); - cy.get('.text').click(); - cy.get('.menu > :nth-child(3) > .btn > .fa-solid').click(); - cy.get('.hidden > :nth-child(1)').click(); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > :nth-child(1) > .input > #email').clear('te'); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > :nth-child(1) > .input > #email').type('test@test.nl'); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > :nth-child(2) > .input > #password').clear(); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > :nth-child(2) > .input > #password').type('Testing1'); - cy.get('.modal-open > .modal-box > form.w-full > .space-y-4 > .modal-action > .btn').click(); - cy.get('.alert span').should('contain.text', 'Could not login with the given email and password'); + cy.login("admin@test.nl", "admin") + cy.navigateToAdminPanel() + cy.createUser("user@test.nl", "Testing1", false) + cy.logout() + + cy.login("user@test.nl", "Testing1") + cy.url().should('include', '/home') + cy.logout() + + cy.login("admin@test.nl", "admin") + cy.navigateToAdminPanel() + + cy.deleteUser("user@test.nl") + cy.logout() + + cy.login("user@test.nl", "Testing1") + cy.get('[data-cy="login-error"]').should('contain.text', 'Could not login with the given email and password'); }); }) diff --git a/ui/cypress/support/commands.js b/ui/cypress/support/commands.js index 66ea16e..42edc1c 100644 --- a/ui/cypress/support/commands.js +++ b/ui/cypress/support/commands.js @@ -22,4 +22,34 @@ // // // -- This will overwrite an existing command -- -// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) \ No newline at end of file +// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) + +Cypress.Commands.addAll({ + login(email, password) { + cy.get('[data-cy="open-login-modal"]').click(); + cy.get('[data-cy="login-email"]').type(email); + cy.get('[data-cy="login-password"]').type(password); + cy.get('[data-cy="login-button"]').click(); + }, + logout() { + cy.get('[data-cy="toggle-profile-menu-dropdown"').click(); + cy.get('[data-cy="logout"]').click(); + }, + navigateToAdminPanel() { + cy.get('[data-cy="toggle-profile-menu-dropdown"').click(); + cy.get('[data-cy="admin-panel"]').click(); + }, + createUser(email, password, isAdmin) { + cy.get('[data-cy="create-new-user"]').click(); + cy.get('[data-cy="new-user-email"]').type(email); + cy.get('[data-cy="new-user-password"]').type(password); + if (isAdmin) { + cy.get('[data-cy="new-user-admin"]').check(); + } + cy.get('[data-cy="submit-new-user"]').click(); + }, + deleteUser(email) { + cy.get(`[data-cy="delete-user-${email}"]`).click(); + cy.get(`[data-cy="delete-user"]`).click(); + } +}) diff --git a/ui/src/components/Alert.tsx b/ui/src/components/Alert.tsx index d1dc8b0..46202ce 100644 --- a/ui/src/components/Alert.tsx +++ b/ui/src/components/Alert.tsx @@ -1,4 +1,4 @@ -import { JSXElement } from 'solid-js' +import { JSXElement, JSX } from 'solid-js' import { clsx } from 'clsx' import { TranslationKey, useLocale } from '../context/LocaleProvider' @@ -8,7 +8,9 @@ interface AlertProps { class?: string } -export function Alert(props: AlertProps): JSXElement { +export function Alert( + props: AlertProps & JSX.HTMLAttributes +): JSXElement { const { t } = useLocale() const translated = () => t((props.message as TranslationKey) ?? '') @@ -25,6 +27,7 @@ export function Alert(props: AlertProps): JSXElement { diff --git a/ui/src/components/ProfileMenu.tsx b/ui/src/components/ProfileMenu.tsx index dc5c200..0c91952 100644 --- a/ui/src/components/ProfileMenu.tsx +++ b/ui/src/components/ProfileMenu.tsx @@ -34,14 +34,18 @@ export function ProfileMenu(): JSXElement { return (