From 0fcbbbf27f46fa3a2f028d38977ddc72f8a7814a Mon Sep 17 00:00:00 2001 From: arttu Date: Mon, 5 Aug 2024 20:02:01 +0300 Subject: [PATCH] Add simple tests to check frontend email user rights #no-deploy --- cypress/e2e/asAdmin.cy.js | 1 - cypress/e2e/userRights.cy.js | 8 ++++++++ frontend/src/components/EmailPage.tsx | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cypress/e2e/asAdmin.cy.js b/cypress/e2e/asAdmin.cy.js index 9ec76612..ca80955a 100644 --- a/cypress/e2e/asAdmin.cy.js +++ b/cypress/e2e/asAdmin.cy.js @@ -33,6 +33,5 @@ describe('Open each page, table view and detail view, and check at least some co cy.get('[data-cy="detailview-button-langhian"]').first().click() cy.contains('Sequence') cy.contains('gcss') - }) }) diff --git a/cypress/e2e/userRights.cy.js b/cypress/e2e/userRights.cy.js index e50f19c2..feb23841 100644 --- a/cypress/e2e/userRights.cy.js +++ b/cypress/e2e/userRights.cy.js @@ -35,6 +35,11 @@ describe('Broadly test what different user rights see', () => { cy.contains('Bound') cy.contains('1.778') }) + it('Email page opens', () => { + cy.get('div[id="/admin-menu-button"]').click() + cy.contains('Email').click() + cy.contains('Send email') + }) }) describe('Test unlogged visibility', () => { beforeEach('Ensure logout', () => { @@ -53,5 +58,8 @@ describe('Broadly test what different user rights see', () => { cy.pageForbidden('/time-bound') cy.pageForbidden('/project') }) + it('Does not see email page', () => { + cy.pageForbidden('/email') + }) }) }) diff --git a/frontend/src/components/EmailPage.tsx b/frontend/src/components/EmailPage.tsx index cd3b4644..e978f5a6 100644 --- a/frontend/src/components/EmailPage.tsx +++ b/frontend/src/components/EmailPage.tsx @@ -10,7 +10,7 @@ export const EmailPage = () => { const [message, setMessage] = useState('') const [recipients, setRecipients] = useState('') const [sendEmailMutation, { isSuccess, isLoading, isError }] = useEmailMutation() - if (user.role !== Role.Admin) return This page is visible only to admins + if (user.role !== Role.Admin) return Your user is not authorized to view this page. const parseRecipients = () => { return recipients.replace(' ', '').replace('\n', ',').replace(',', '\n').split(';')