From 4e833bedde9528b48c6f33d6babc67098521e25e Mon Sep 17 00:00:00 2001 From: Carine Dengler Date: Wed, 7 Feb 2024 13:56:44 +0100 Subject: [PATCH 01/16] test: test that buttons are not visible in form states when they are not active --- web/frontend/tests/forms.spec.ts | 66 ++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 21 deletions(-) diff --git a/web/frontend/tests/forms.spec.ts b/web/frontend/tests/forms.spec.ts index 3648a74ef..6c6f11975 100644 --- a/web/frontend/tests/forms.spec.ts +++ b/web/frontend/tests/forms.spec.ts @@ -62,96 +62,120 @@ async function assertIsOnlyVisibleToOwner(page: page, locator: locator) { }); } -async function assertIsOnlyVisibleToOwnerStates( +async function assertIsOnlyVisibleInStates( page: page, locator: locator, states: Array, + assert: Function, dkgActorsStatus?: number, initialized?: boolean ) { for (const i of states) { - await test.step(`Assert is only visible to owner in state ${i}`, async () => { + await test.step(`Assert is visible in state ${i}`, async () => { await setUpMocks(page, i, dkgActorsStatus === undefined ? 6 : dkgActorsStatus, initialized); await page.reload({ waitUntil: 'networkidle' }); - await assertIsOnlyVisibleToOwner(page, locator); + await assert(page, locator); + }); + } + for (const i of [0, 1, 2, 3, 4, 5].filter((x) => !states.includes(x))) { + await test.step(`Assert is not visible in state ${i}`, async () => { + await setUpMocks(page, i, dkgActorsStatus === undefined ? 6 : dkgActorsStatus, initialized); + await page.reload({ waitUntil: 'networkidle' }); + await expect(locator).toBeHidden(); }); } } test('Assert "Add voters" button is only visible to owner', async ({ page }) => { - await assertIsOnlyVisibleToOwnerStates(page, page.getByTestId('addVotersButton'), [0, 1]); + await assertIsOnlyVisibleInStates( + page, + page.getByTestId('addVotersButton'), + [0, 1], + assertIsOnlyVisibleToOwner + ); }); test('Assert "Initialize" button is only visible to owner', async ({ page }) => { - await assertIsOnlyVisibleToOwnerStates( + await assertIsOnlyVisibleInStates( page, page.getByRole('button', { name: i18n.t('initialize') }), [0], + assertIsOnlyVisibleToOwner, 0, false ); }); test('Assert "Setup" button is only visible to owner', async ({ page }) => { - await assertIsOnlyVisibleToOwnerStates( + await assertIsOnlyVisibleInStates( page, page.getByRole('button', { name: i18n.t('setup') }), [0], + assertIsOnlyVisibleToOwner, 0, true ); }); test('Assert "Open" button is only visible to owner', async ({ page }) => { - await assertIsOnlyVisibleToOwnerStates(page, page.getByRole('button', { name: i18n.t('open') }), [ - 0, - ]); + await assertIsOnlyVisibleInStates( + page, + page.getByRole('button', { name: i18n.t('open') }), + [0], + assertIsOnlyVisibleToOwner + ); }); test('Assert "Cancel" button is only visible to owner', async ({ page }) => { - await assertIsOnlyVisibleToOwnerStates( + await assertIsOnlyVisibleInStates( page, page.getByRole('button', { name: i18n.t('cancel') }), - [1] + [1], + assertIsOnlyVisibleToOwner ); }); test('Assert "Close" button is only visible to owner', async ({ page }) => { - await assertIsOnlyVisibleToOwnerStates( + await assertIsOnlyVisibleInStates( page, page.getByRole('button', { name: i18n.t('close') }), - [1] + [1], + assertIsOnlyVisibleToOwner ); }); test('Assert "Shuffle" button is only visible to owner', async ({ page }) => { - await assertIsOnlyVisibleToOwnerStates( + await assertIsOnlyVisibleInStates( page, page.getByRole('button', { name: i18n.t('shuffle') }), - [2] + [2], + assertIsOnlyVisibleToOwner ); }); test('Assert "Decrypt" button is only visible to owner', async ({ page }) => { - await assertIsOnlyVisibleToOwnerStates( + await assertIsOnlyVisibleInStates( page, page.getByRole('button', { name: i18n.t('decrypt') }), - [3] + [3], + assertIsOnlyVisibleToOwner ); }); test('Assert "Combine" button is only visible to owner', async ({ page }) => { - await assertIsOnlyVisibleToOwnerStates( + await assertIsOnlyVisibleInStates( page, page.getByRole('button', { name: i18n.t('combine') }), - [4] + [4], + assertIsOnlyVisibleToOwner ); }); test('Assert "Delete" button is only visible to owner', async ({ page }) => { - await assertIsOnlyVisibleToOwnerStates( + await assertIsOnlyVisibleInStates( page, page.getByRole('button', { name: i18n.t('delete') }), - [0, 1, 2, 3, 4] + [0, 1, 2, 3, 4], + assertIsOnlyVisibleToOwner ); }); From adb9a7bf909db283320404b62acba231226fb352 Mon Sep 17 00:00:00 2001 From: Carine Dengler Date: Wed, 7 Feb 2024 14:08:33 +0100 Subject: [PATCH 02/16] test: clean up test messages --- web/frontend/tests/forms.spec.ts | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/web/frontend/tests/forms.spec.ts b/web/frontend/tests/forms.spec.ts index 6c6f11975..2f15e8672 100644 --- a/web/frontend/tests/forms.spec.ts +++ b/web/frontend/tests/forms.spec.ts @@ -12,6 +12,15 @@ import { FORMID, mockDKGActors, mockFormsFormID } from './mocks/evoting'; initI18n(); +const prettyFormStates = new Map([ + [0, 'Initial'], + [1, 'Open'], + [2, 'Closed'], + [3, 'ShuffledBallots'], + [4, 'PubSharesSubmitted'], + [5, 'ResultAvailable'], +]); + // main elements async function setUpMocks( @@ -71,18 +80,21 @@ async function assertIsOnlyVisibleInStates( initialized?: boolean ) { for (const i of states) { - await test.step(`Assert is visible in state ${i}`, async () => { + await test.step(`Assert is visible in form state '${prettyFormStates.get(i)}'`, async () => { await setUpMocks(page, i, dkgActorsStatus === undefined ? 6 : dkgActorsStatus, initialized); await page.reload({ waitUntil: 'networkidle' }); await assert(page, locator); }); } for (const i of [0, 1, 2, 3, 4, 5].filter((x) => !states.includes(x))) { - await test.step(`Assert is not visible in state ${i}`, async () => { - await setUpMocks(page, i, dkgActorsStatus === undefined ? 6 : dkgActorsStatus, initialized); - await page.reload({ waitUntil: 'networkidle' }); - await expect(locator).toBeHidden(); - }); + await test.step( + `Assert is not visible in form state '${prettyFormStates.get(i)}'`, + async () => { + await setUpMocks(page, i, dkgActorsStatus === undefined ? 6 : dkgActorsStatus, initialized); + await page.reload({ waitUntil: 'networkidle' }); + await expect(locator).toBeHidden(); + } + ); } } From 1bac17be6f7c3e740d8a21ab19a3b056c274c7b7 Mon Sep 17 00:00:00 2001 From: Carine Dengler Date: Wed, 7 Feb 2024 14:55:03 +0100 Subject: [PATCH 03/16] test: add missing 'Canceled' state --- web/frontend/tests/forms.spec.ts | 4 +- .../tests/json/evoting/forms/canceled.json | 64 +++++++++++++++++++ web/frontend/tests/mocks/evoting.ts | 1 + 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 web/frontend/tests/json/evoting/forms/canceled.json diff --git a/web/frontend/tests/forms.spec.ts b/web/frontend/tests/forms.spec.ts index 2f15e8672..85bc7ca39 100644 --- a/web/frontend/tests/forms.spec.ts +++ b/web/frontend/tests/forms.spec.ts @@ -19,6 +19,7 @@ const prettyFormStates = new Map([ [3, 'ShuffledBallots'], [4, 'PubSharesSubmitted'], [5, 'ResultAvailable'], + [6, 'Canceled'], ]); // main elements @@ -184,10 +185,11 @@ test('Assert "Combine" button is only visible to owner', async ({ page }) => { }); test('Assert "Delete" button is only visible to owner', async ({ page }) => { + test.setTimeout(60000); // Firefox is exceeding the default timeout on this test await assertIsOnlyVisibleInStates( page, page.getByRole('button', { name: i18n.t('delete') }), - [0, 1, 2, 3, 4], + [0, 1, 2, 3, 4, 6], assertIsOnlyVisibleToOwner ); }); diff --git a/web/frontend/tests/json/evoting/forms/canceled.json b/web/frontend/tests/json/evoting/forms/canceled.json new file mode 100644 index 000000000..908e8885c --- /dev/null +++ b/web/frontend/tests/json/evoting/forms/canceled.json @@ -0,0 +1,64 @@ +{ + "FormID": "b63bcb854121051f2d8cff04bf0ac9b524b534b704509a16a423448bde3321b4", + "Configuration": { + "Title": { + "En": "Colours", + "Fr": "", + "De": "" + }, + "Scaffold": [ + { + "ID": "yOakwFnR", + "Title": { + "En": "Colours", + "Fr": "Couleurs", + "De": "Farben" + }, + "Order": [ + "CLgNiLbC" + ], + "Subjects": [], + "Selects": [ + { + "ID": "CLgNiLbC", + "Title": { + "En": "RGB", + "Fr": "RGB", + "De": "RGB" + }, + "MaxN": 2, + "MinN": 1, + "Choices": [ + "{\"en\":\"Red\",\"fr\":\"Rouge\",\"de\":\"Rot\"}", + "{\"en\":\"Green\",\"fr\":\"Vert\",\"de\":\"GrĂ¼n\"}", + "{\"en\":\"Blue\",\"fr\":\"Bleu\",\"de\":\"Blau\"}" + ], + "Hint": { + "En": "", + "Fr": "", + "De": "" + } + } + ], + "Ranks": [], + "Texts": [] + } + ] + }, + "Status": 2, + "Pubkey": "612fdc867be1a5faccf16e5aed946880005840ee04aaa382fe181a2b46dc9a24", + "Result": [], + "Roster": [ + "grpc://dela-worker-0:2000", + "grpc://dela-worker-1:2000", + "grpc://dela-worker-2:2000", + "grpc://dela-worker-3:2000" + ], + "ChunksPerBallot": 1, + "BallotSize": 23, + "Voters": [ + "oUItDdhhEE", + "WZyqP1gssL", + "K7ZNvumBVc" + ] +} diff --git a/web/frontend/tests/mocks/evoting.ts b/web/frontend/tests/mocks/evoting.ts index dfa5784cd..2f09e15dc 100644 --- a/web/frontend/tests/mocks/evoting.ts +++ b/web/frontend/tests/mocks/evoting.ts @@ -42,6 +42,7 @@ export async function mockFormsFormID(page: page, formStatus: number) { 'shuffled.json', 'decrypted.json', 'combined.json', + 'canceled.json', ][formStatus]; await route.fulfill({ path: `./tests/json/evoting/forms/${formFile}`, From 525aaa84fd8e6daface47763fa5cb48ee7d995a5 Mon Sep 17 00:00:00 2001 From: Carine Dengler Date: Wed, 7 Feb 2024 15:32:02 +0100 Subject: [PATCH 04/16] test: add 'Vote' button test cases --- web/frontend/tests/forms.spec.ts | 33 ++++++++++++++++++- .../tests/json/api/personal_info/654321.json | 7 ++++ web/frontend/tests/mocks/api.ts | 1 + 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 web/frontend/tests/json/api/personal_info/654321.json diff --git a/web/frontend/tests/forms.spec.ts b/web/frontend/tests/forms.spec.ts index 85bc7ca39..6216cfbdf 100644 --- a/web/frontend/tests/forms.spec.ts +++ b/web/frontend/tests/forms.spec.ts @@ -4,6 +4,7 @@ import { assertHasFooter, assertHasNavBar, initI18n, logIn, setUp } from './shar import { SCIPER_ADMIN, SCIPER_OTHER_ADMIN, + SCIPER_OTHER_USER, SCIPER_USER, mockPersonalInfo, mockProxies, @@ -185,7 +186,7 @@ test('Assert "Combine" button is only visible to owner', async ({ page }) => { }); test('Assert "Delete" button is only visible to owner', async ({ page }) => { - test.setTimeout(60000); // Firefox is exceeding the default timeout on this test + test.setTimeout(60000); // Firefox is exceeding the default timeout on this test await assertIsOnlyVisibleInStates( page, page.getByRole('button', { name: i18n.t('delete') }), @@ -193,3 +194,33 @@ test('Assert "Delete" button is only visible to owner', async ({ page }) => { assertIsOnlyVisibleToOwner ); }); + +test('Assert "Vote" button is visible to admin/non-admin voter user', async ({ page }) => { + await assertIsOnlyVisibleInStates( + page, + page.getByRole('button', { name: i18n.t('vote'), exact: true }), // by default name is not matched exactly which returns both the "Vote" and the "Add voters" button + [1], + // eslint-disable-next-line @typescript-eslint/no-shadow + async function (page: page, locator: locator) { + await test.step('Assert is hidden to unauthenticated user', async () => { + await expect(locator).toBeHidden(); + }); + await test.step('Assert is hidden to authenticated non-voter user', async () => { + await logIn(page, SCIPER_OTHER_USER); + await expect(locator).toBeHidden(); + }); + await test.step('Assert is visible to authenticated voter user', async () => { + await logIn(page, SCIPER_USER); + await expect(locator).toBeVisible(); + }); + await test.step('Assert is hidden to non-voter admin', async () => { + await logIn(page, SCIPER_OTHER_ADMIN); + await expect(locator).toBeHidden(); + }); + await test.step('Assert is visible to voter admin', async () => { + await logIn(page, SCIPER_ADMIN); + await expect(locator).toBeVisible(); + }); + } + ); +}); diff --git a/web/frontend/tests/json/api/personal_info/654321.json b/web/frontend/tests/json/api/personal_info/654321.json new file mode 100644 index 000000000..5650be68f --- /dev/null +++ b/web/frontend/tests/json/api/personal_info/654321.json @@ -0,0 +1,7 @@ +{ + "sciper": 654321, + "lastName": "654321", + "firstName": "sciper-#", + "isLoggedIn": true, + "authorization": {} +} diff --git a/web/frontend/tests/mocks/api.ts b/web/frontend/tests/mocks/api.ts index 4d5ec042f..208098609 100644 --- a/web/frontend/tests/mocks/api.ts +++ b/web/frontend/tests/mocks/api.ts @@ -1,6 +1,7 @@ export const SCIPER_ADMIN = '123456'; export const SCIPER_OTHER_ADMIN = '987654'; export const SCIPER_USER = '789012'; +export const SCIPER_OTHER_USER = '654321'; export async function mockProxy(page: page) { await page.route('/api/config/proxy', async (route) => { From 18e6069fd4b1cd0093ff50712c3387b83b2076d4 Mon Sep 17 00:00:00 2001 From: Carine Dengler Date: Wed, 7 Feb 2024 18:57:58 +0100 Subject: [PATCH 05/16] test: add initialization tests --- web/frontend/tests/forms.spec.ts | 24 +++++++++++++++++++ .../json/evoting/dkgActors/uninitialized.json | 2 +- web/frontend/tests/mocks/api.ts | 8 +++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/web/frontend/tests/forms.spec.ts b/web/frontend/tests/forms.spec.ts index 6216cfbdf..8a1117360 100644 --- a/web/frontend/tests/forms.spec.ts +++ b/web/frontend/tests/forms.spec.ts @@ -6,10 +6,15 @@ import { SCIPER_OTHER_ADMIN, SCIPER_OTHER_USER, SCIPER_USER, + mockDKGActors as mockAPIDKGActors, mockPersonalInfo, mockProxies, } from './mocks/api'; import { FORMID, mockDKGActors, mockFormsFormID } from './mocks/evoting'; +import Worker0 from './json/api/proxies/dela-worker-0.json'; +import Worker1 from './json/api/proxies/dela-worker-1.json'; +import Worker2 from './json/api/proxies/dela-worker-2.json'; +import Worker3 from './json/api/proxies/dela-worker-3.json'; initI18n(); @@ -38,6 +43,7 @@ async function setUpMocks( await mockProxies(page, i); } await mockDKGActors(page, dkgActorsStatus, initialized); + await mockAPIDKGActors(page); await mockPersonalInfo(page); } @@ -120,6 +126,24 @@ test('Assert "Initialize" button is only visible to owner', async ({ page }) => ); }); +test('Assert "Initialize" button calls route to initialize nodes', async ({ page, baseURL }) => { + await setUpMocks(page, 0, 0, false); + await logIn(page, SCIPER_OTHER_ADMIN); + // we expect one call per worker node + for (const worker of [Worker0, Worker1, Worker2, Worker3]) { + page.waitForRequest(async (request) => { + const body = await request.postDataJSON(); + return ( + request.url() === `${baseURL}/api/evoting/services/dkg/actors` && + request.method() === 'POST' && + body.FormID === FORMID && + body.Proxy === worker.Proxy + ); + }); + } + await page.getByRole('button', { name: i18n.t('initialize') }).click(); +}); + test('Assert "Setup" button is only visible to owner', async ({ page }) => { await assertIsOnlyVisibleInStates( page, diff --git a/web/frontend/tests/json/evoting/dkgActors/uninitialized.json b/web/frontend/tests/json/evoting/dkgActors/uninitialized.json index 1279f9f3c..355d98ecf 100644 --- a/web/frontend/tests/json/evoting/dkgActors/uninitialized.json +++ b/web/frontend/tests/json/evoting/dkgActors/uninitialized.json @@ -5,6 +5,6 @@ "Args": { "error": "actor not found", "method": "GET", - "url": "/evoting/services/dkg/actors/d3319c58a3bea17dafe61168610757b9a7bb0d922c1f2aa30b8ad537646b1c07" + "url": "/evoting/services/dkg/actors/b63bcb854121051f2d8cff04bf0ac9b524b534b704509a16a423448bde3321b4" } } diff --git a/web/frontend/tests/mocks/api.ts b/web/frontend/tests/mocks/api.ts index 208098609..1284aff98 100644 --- a/web/frontend/tests/mocks/api.ts +++ b/web/frontend/tests/mocks/api.ts @@ -3,6 +3,14 @@ export const SCIPER_OTHER_ADMIN = '987654'; export const SCIPER_USER = '789012'; export const SCIPER_OTHER_USER = '654321'; +export async function mockDKGActors(page: page) { + await page.route('/api/evoting/services/dkg/actors', async (route) => { + if (route.request().method() === 'POST') { + await route.fulfill({ status: 200 }); + } + }); +} + export async function mockProxy(page: page) { await page.route('/api/config/proxy', async (route) => { await route.fulfill({ From 312a3f93155eadc13ca702812f5ef6a01adf0d4c Mon Sep 17 00:00:00 2001 From: Carine Dengler Date: Thu, 8 Feb 2024 15:39:53 +0100 Subject: [PATCH 06/16] test: add 'Setup' route calling test --- .../form/components/ChooseProxyModal.tsx | 4 +++- web/frontend/tests/forms.spec.ts | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/web/frontend/src/pages/form/components/ChooseProxyModal.tsx b/web/frontend/src/pages/form/components/ChooseProxyModal.tsx index fe3bcc6c5..3fe98adb4 100644 --- a/web/frontend/src/pages/form/components/ChooseProxyModal.tsx +++ b/web/frontend/src/pages/form/components/ChooseProxyModal.tsx @@ -108,7 +108,9 @@ const ChooseProxyModal: FC = ({
-
+
{t('nodeSetup')} diff --git a/web/frontend/tests/forms.spec.ts b/web/frontend/tests/forms.spec.ts index 8a1117360..6f9667879 100644 --- a/web/frontend/tests/forms.spec.ts +++ b/web/frontend/tests/forms.spec.ts @@ -155,6 +155,28 @@ test('Assert "Setup" button is only visible to owner', async ({ page }) => { ); }); +test('Assert "Setup" button calls route to setup node', async ({ page, baseURL }) => { + await setUpMocks(page, 0, 0, true); + await logIn(page, SCIPER_OTHER_ADMIN); + // we expect one call with the chosen worker node + page.waitForRequest(async (request) => { + const body = await request.postDataJSON(); + return ( + request.url() === `${baseURL}/api/evoting/services/dkg/actors/${FORMID}` && + request.method() === 'PUT' && + body.Action === 'setup' && + body.Proxy === Worker1.Proxy + ); + }); + // open node selection window + await page.getByRole('button', { name: i18n.t('setup') }).click(); + await expect(page.getByTestId('nodeSetup')).toBeVisible(); + // choose second worker node + await page.getByLabel(Worker1.NodeAddr).check(); + // confirm + await page.getByRole('button', { name: i18n.t('setupNode') }).click(); +}); + test('Assert "Open" button is only visible to owner', async ({ page }) => { await assertIsOnlyVisibleInStates( page, From 7a80f958c79b93285d228392daaeeba341860d10 Mon Sep 17 00:00:00 2001 From: Carine Dengler Date: Thu, 8 Feb 2024 15:46:27 +0100 Subject: [PATCH 07/16] test: add 'Open' route calling test --- web/frontend/tests/forms.spec.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/web/frontend/tests/forms.spec.ts b/web/frontend/tests/forms.spec.ts index 6f9667879..2da67d67d 100644 --- a/web/frontend/tests/forms.spec.ts +++ b/web/frontend/tests/forms.spec.ts @@ -186,6 +186,20 @@ test('Assert "Open" button is only visible to owner', async ({ page }) => { ); }); +test('Assert "Open" button calls route to open form', async ({ page, baseURL }) => { + await setUpMocks(page, 0, 6); + await logIn(page, SCIPER_OTHER_ADMIN); + page.waitForRequest(async (request) => { + const body = await request.postDataJSON(); + return ( + request.url() === `${baseURL}/api/evoting/forms/${FORMID}` && + request.method() === 'PUT' && + body.Action === 'open' + ); + }); + await page.getByRole('button', { name: i18n.t('open') }).click(); +}); + test('Assert "Cancel" button is only visible to owner', async ({ page }) => { await assertIsOnlyVisibleInStates( page, From 857c1f7fd640d4bffd178bd7709fce3378bfbf80 Mon Sep 17 00:00:00 2001 From: Carine Dengler Date: Thu, 8 Feb 2024 16:03:58 +0100 Subject: [PATCH 08/16] test: add 'Cancel' route calling test --- web/frontend/tests/forms.spec.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/web/frontend/tests/forms.spec.ts b/web/frontend/tests/forms.spec.ts index 2da67d67d..ee127d6a9 100644 --- a/web/frontend/tests/forms.spec.ts +++ b/web/frontend/tests/forms.spec.ts @@ -209,6 +209,20 @@ test('Assert "Cancel" button is only visible to owner', async ({ page }) => { ); }); +test('Assert "Cancel" button calls route to cancel form', async ({ page, baseURL }) => { + await setUpMocks(page, 1, 6); + await logIn(page, SCIPER_OTHER_ADMIN); + page.waitForRequest(async (request) => { + const body = await request.postDataJSON(); + return ( + request.url() === `${baseURL}/api/evoting/forms/${FORMID}` && + request.method() === 'PUT' && + body.Action === 'cancel' + ); + }); + await page.getByRole('button', { name: i18n.t('cancel') }).click(); +}); + test('Assert "Close" button is only visible to owner', async ({ page }) => { await assertIsOnlyVisibleInStates( page, From f1784a14f1391530df53a9bdac4c330aee96835f Mon Sep 17 00:00:00 2001 From: Carine Dengler Date: Fri, 9 Feb 2024 15:22:08 +0100 Subject: [PATCH 09/16] test: refactor button tests and add tests for remaining buttons --- web/frontend/tests/forms.spec.ts | 82 +++++++++++++++++++++++--------- 1 file changed, 60 insertions(+), 22 deletions(-) diff --git a/web/frontend/tests/forms.spec.ts b/web/frontend/tests/forms.spec.ts index ee127d6a9..16b5c21c7 100644 --- a/web/frontend/tests/forms.spec.ts +++ b/web/frontend/tests/forms.spec.ts @@ -106,6 +106,23 @@ async function assertIsOnlyVisibleInStates( } } +async function assertRouteIsCalled(page: page, url: string, key: string, action: string, formStatus: number, confirmation: boolean, dkgActorsStatus?: number, initialized?: boolean) { + await setUpMocks(page, formStatus, dkgActorsStatus === undefined ? 6 : dkgActorsStatus, initialized); + await logIn(page, SCIPER_OTHER_ADMIN); + page.waitForRequest(async (request) => { + const body = await request.postDataJSON(); + return ( + request.url() === url && + request.method() === 'PUT' && + body.Action === action + ); + }); + await page.getByRole('button', { name: i18n.t(key) }).click(); + if (confirmation) { + await page.getByRole('button', { name: i18n.t('yes') }).click(); + } +} + test('Assert "Add voters" button is only visible to owner', async ({ page }) => { await assertIsOnlyVisibleInStates( page, @@ -187,17 +204,7 @@ test('Assert "Open" button is only visible to owner', async ({ page }) => { }); test('Assert "Open" button calls route to open form', async ({ page, baseURL }) => { - await setUpMocks(page, 0, 6); - await logIn(page, SCIPER_OTHER_ADMIN); - page.waitForRequest(async (request) => { - const body = await request.postDataJSON(); - return ( - request.url() === `${baseURL}/api/evoting/forms/${FORMID}` && - request.method() === 'PUT' && - body.Action === 'open' - ); - }); - await page.getByRole('button', { name: i18n.t('open') }).click(); + await assertRouteIsCalled(page, `${baseURL}/api/evoting/forms/${FORMID}`, 'open', 'open', 0, false, 6); }); test('Assert "Cancel" button is only visible to owner', async ({ page }) => { @@ -210,17 +217,7 @@ test('Assert "Cancel" button is only visible to owner', async ({ page }) => { }); test('Assert "Cancel" button calls route to cancel form', async ({ page, baseURL }) => { - await setUpMocks(page, 1, 6); - await logIn(page, SCIPER_OTHER_ADMIN); - page.waitForRequest(async (request) => { - const body = await request.postDataJSON(); - return ( - request.url() === `${baseURL}/api/evoting/forms/${FORMID}` && - request.method() === 'PUT' && - body.Action === 'cancel' - ); - }); - await page.getByRole('button', { name: i18n.t('cancel') }).click(); + await assertRouteIsCalled(page, `${baseURL}/api/evoting/forms/${FORMID}`, 'cancel', 'cancel', 1, true); }); test('Assert "Close" button is only visible to owner', async ({ page }) => { @@ -232,6 +229,10 @@ test('Assert "Close" button is only visible to owner', async ({ page }) => { ); }); +test('Assert "Close" button calls route to close form', async ({ page, baseURL }) => { + await assertRouteIsCalled(page, `${baseURL}/api/evoting/forms/${FORMID}`, 'close', 'close', 1, true); +}); + test('Assert "Shuffle" button is only visible to owner', async ({ page }) => { await assertIsOnlyVisibleInStates( page, @@ -241,6 +242,10 @@ test('Assert "Shuffle" button is only visible to owner', async ({ page }) => { ); }); +test('Assert "Shuffle" button calls route to shuffle form', async ({ page, baseURL }) => { + await assertRouteIsCalled(page, `${baseURL}/api/evoting/services/shuffle/${FORMID}`, 'shuffle', 'shuffle', 2, false); +}); + test('Assert "Decrypt" button is only visible to owner', async ({ page }) => { await assertIsOnlyVisibleInStates( page, @@ -250,6 +255,10 @@ test('Assert "Decrypt" button is only visible to owner', async ({ page }) => { ); }); +test('Assert "Decrypt" button calls route to decrypt form', async ({ page, baseURL }) => { + await assertRouteIsCalled(page, `${baseURL}/api/evoting/services/dkg/actors/${FORMID}`, 'decrypt', 'computePubshares', 3, false); +}); + test('Assert "Combine" button is only visible to owner', async ({ page }) => { await assertIsOnlyVisibleInStates( page, @@ -259,6 +268,10 @@ test('Assert "Combine" button is only visible to owner', async ({ page }) => { ); }); +test('Assert "Combine" button calls route to combine form', async ({ page, baseURL }) => { + await assertRouteIsCalled(page, `${baseURL}/api/evoting/forms/${FORMID}`, 'combine', 'combineShares', 4, false); +}); + test('Assert "Delete" button is only visible to owner', async ({ page }) => { test.setTimeout(60000); // Firefox is exceeding the default timeout on this test await assertIsOnlyVisibleInStates( @@ -269,6 +282,22 @@ test('Assert "Delete" button is only visible to owner', async ({ page }) => { ); }); +test('Assert "Delete" button calls route to delete form', async ({ page, baseURL }) => { + for (const i of [0, 1, 2, 3, 4, 6]) { + await setUpMocks(page, i, 6) + await logIn(page, SCIPER_OTHER_ADMIN); + page.waitForRequest(async (request) => { + const body = await request.postDataJSON(); + return ( + request.url() === `${baseURL}/api/evoting/forms/${FORMID}` && + request.method() === 'DELETE' + ); + }); + await page.getByRole('button', { name: i18n.t('delete') }).click(); + await page.getByRole('button', { name: i18n.t('yes') }).click(); + } +}); + test('Assert "Vote" button is visible to admin/non-admin voter user', async ({ page }) => { await assertIsOnlyVisibleInStates( page, @@ -298,3 +327,12 @@ test('Assert "Vote" button is visible to admin/non-admin voter user', async ({ p } ); }); + +test('Assert "Vote" button gets voting form', async ({ page }) => { + await setUpMocks(page, 1, 6) + for (const user of [SCIPER_USER, SCIPER_ADMIN]) { + await logIn(page, user); + page.waitForRequest(`${process.env.DELA_PROXY_URL}/evoting/forms/${FORMID}`) + await page.getByRole('button', { name: i18n.t('vote') }).click(); + } +}); From 65ed6659d9641f2e6422b520cee8b6b7cb5960b2 Mon Sep 17 00:00:00 2001 From: Carine Dengler Date: Fri, 9 Feb 2024 16:43:57 +0100 Subject: [PATCH 10/16] test: test adding voters --- .../pages/form/components/AddVotersModal.tsx | 1 + web/frontend/tests/forms.spec.ts | 28 +++++++++++++++++++ web/frontend/tests/mocks/api.ts | 6 ++++ 3 files changed, 35 insertions(+) diff --git a/web/frontend/src/pages/form/components/AddVotersModal.tsx b/web/frontend/src/pages/form/components/AddVotersModal.tsx index d54113f3f..4a619940f 100644 --- a/web/frontend/src/pages/form/components/AddVotersModal.tsx +++ b/web/frontend/src/pages/form/components/AddVotersModal.tsx @@ -169,6 +169,7 @@ export const AddVotersModal: FC = ({