From 12a26f596e969afaab244ae1476f4a418083a34d Mon Sep 17 00:00:00 2001 From: Sudip Bhattarai Date: Thu, 14 Nov 2024 13:12:08 +0545 Subject: [PATCH] test: Add poll creation test --- .../lib/fixtures/loadExtension.ts | 1 - integration_test/lib/helpers/auth.ts | 31 ++++++++++++++++++- integration_test/lib/helpers/mobile.ts | 1 - .../lib/pages/representativesPage.ts | 1 - .../conventionOrganizer.loggedin.spec.ts | 20 +++++++++++- ...onstitutionalDelegate.registration.spec.ts | 6 ++-- .../constitutionalDelegate.viewVote.spec.ts | 14 ++++++--- .../constitutionalDelegate.vote.spec.ts | 6 ++-- .../alternate.registration.spec.ts | 7 ++--- .../3-alternates/alternates.viewvote.spec.ts | 11 ++++--- .../3-alternates/alternates.vote.spec.ts | 10 +++--- .../communityMembers.pollStatus.spec.ts | 7 ++--- .../communityMembers.viewProfile.spec.ts | 16 +++++----- .../communityMembers.viewVote.spec.ts | 3 -- integration_test/tsconfig.json | 2 +- tsconfig.json | 2 +- 16 files changed, 93 insertions(+), 45 deletions(-) diff --git a/integration_test/lib/fixtures/loadExtension.ts b/integration_test/lib/fixtures/loadExtension.ts index 154fbe1..fe79b50 100644 --- a/integration_test/lib/fixtures/loadExtension.ts +++ b/integration_test/lib/fixtures/loadExtension.ts @@ -5,7 +5,6 @@ import { import environments from '@constants/environments'; import { Page } from '@playwright/test'; - // eslint-disable-next-line @typescript-eslint/no-require-imports import path = require('path'); diff --git a/integration_test/lib/helpers/auth.ts b/integration_test/lib/helpers/auth.ts index 9dae654..f64dbf9 100644 --- a/integration_test/lib/helpers/auth.ts +++ b/integration_test/lib/helpers/auth.ts @@ -1,7 +1,8 @@ import { importWallet } from '@fixtures/importWallet'; import LoginPage from '@pages/loginPage'; -import { BrowserContext, Page } from '@playwright/test'; +import { Browser, BrowserContext, Page } from '@playwright/test'; import { StaticWallet } from '@types'; +import loadEternlExtension from '@fixtures/loadExtension'; interface CreateUserProps { page: Page; @@ -24,3 +25,31 @@ export async function createAuth({ await context.storageState({ path: auth }); } + +interface NewPageConfig { + storageState?: string; + wallet: StaticWallet; + enableStakeSigning?: boolean; + supportedExtensions?: Record[]; +} + +export async function createNewPageWithWallet( + browser: Browser, + newPageConfig: NewPageConfig +): Promise { + const { storageState, wallet, ...extensionConfig } = newPageConfig; + + const context = await browser.newContext({ + storageState, + }); + const newPage = await context.newPage(); + + await loadEternlExtension( + newPage, + extensionConfig.enableStakeSigning, + extensionConfig.supportedExtensions + ); + await importWallet(newPage, wallet); + + return newPage; +} diff --git a/integration_test/lib/helpers/mobile.ts b/integration_test/lib/helpers/mobile.ts index 66bdb5b..c0d8556 100644 --- a/integration_test/lib/helpers/mobile.ts +++ b/integration_test/lib/helpers/mobile.ts @@ -6,4 +6,3 @@ export function isMobile(page: Page): boolean { return false; } - diff --git a/integration_test/lib/pages/representativesPage.ts b/integration_test/lib/pages/representativesPage.ts index 2a85754..dbddcab 100644 --- a/integration_test/lib/pages/representativesPage.ts +++ b/integration_test/lib/pages/representativesPage.ts @@ -3,7 +3,6 @@ import { Page, expect } from '@playwright/test'; const updateDelegateEmail = 'jamejones123@email.com'; const updatedAlternateEmail = 'sallysue123@email.com'; const representativeUpdatedToast = 'User info updated!'; - export default class RepresentativesPage { readonly updateDelegateBtn = this.page.getByTestId( 'edit-representative-info-2' diff --git a/integration_test/tests/1-convention-organizers/conventionOrganizer.loggedin.spec.ts b/integration_test/tests/1-convention-organizers/conventionOrganizer.loggedin.spec.ts index fd701e1..6be38c5 100644 --- a/integration_test/tests/1-convention-organizers/conventionOrganizer.loggedin.spec.ts +++ b/integration_test/tests/1-convention-organizers/conventionOrganizer.loggedin.spec.ts @@ -1,4 +1,4 @@ -import { organizerWallet } from '@constants/staticWallets'; +import { delegateWallet, organizerWallet } from '@constants/staticWallets'; import { setAllureEpic } from '@helpers/allure'; import { CCVT } from '@mock/index'; import { expect } from '@playwright/test'; @@ -21,6 +21,24 @@ test.describe('Recognise a Convention Organiser', () => { }); }); +test.describe('Polls', () => { + test('1XX, Can create poll with valid data', async ({ page, browser }) => { + await page.goto('/polls/new'); + await page + .locator('[data-testid="poll-name-input"] input') + .fill('Dummy Test Poll'); + await page + .locator('[data-testid="poll-description-input"] textarea') + .first() + .fill('Test Poll Description'); + await page.getByTestId('create-poll-button').click(); + + await expect(page.getByText('Dummy Test Poll')).toBeVisible(); + await expect( + page.getByTestId('poll-status-chip').getByText('Pending') + ).toBeVisible(); + }); +}); test.describe('Invitation', () => { test('1B. Could invite delegates', async ({ page }) => { await page.goto('/'); diff --git a/integration_test/tests/2-constitutional-delegates/constitutionalDelegate.registration.spec.ts b/integration_test/tests/2-constitutional-delegates/constitutionalDelegate.registration.spec.ts index 807a4b0..9539d6d 100644 --- a/integration_test/tests/2-constitutional-delegates/constitutionalDelegate.registration.spec.ts +++ b/integration_test/tests/2-constitutional-delegates/constitutionalDelegate.registration.spec.ts @@ -7,10 +7,10 @@ test.beforeEach(async () => { }); test.describe('Delegate Registration', () => { - test('2E. Must be able to view their registration status', async ({ page }) => { + test('2E. Must be able to view their registration status', async ({ + page, + }) => { await page.goto('/'); await expect(page).toHaveTitle(CCVT.title); }); - }); - diff --git a/integration_test/tests/2-constitutional-delegates/constitutionalDelegate.viewVote.spec.ts b/integration_test/tests/2-constitutional-delegates/constitutionalDelegate.viewVote.spec.ts index e7b5500..51d2c29 100644 --- a/integration_test/tests/2-constitutional-delegates/constitutionalDelegate.viewVote.spec.ts +++ b/integration_test/tests/2-constitutional-delegates/constitutionalDelegate.viewVote.spec.ts @@ -7,20 +7,24 @@ test.beforeEach(async () => { }); test.describe('Delegate View Vote', () => { - - test('2F. Must be able to view vote result and its count', async ({ page }) => { + test('2F. Must be able to view vote result and its count', async ({ + page, + }) => { await page.goto('/'); await expect(page).toHaveTitle(CCVT.title); }); - test('2G. Must be able to view own vote during open poll', async ({ page }) => { + test('2G. Must be able to view own vote during open poll', async ({ + page, + }) => { await page.goto('/'); await expect(page).toHaveTitle(CCVT.title); }); - test('2I. Should not be able to view poll result before poll closing', async ({ page }) => { + test('2I. Should not be able to view poll result before poll closing', async ({ + page, + }) => { await page.goto('/'); await expect(page).toHaveTitle(CCVT.title); }); }); - diff --git a/integration_test/tests/2-constitutional-delegates/constitutionalDelegate.vote.spec.ts b/integration_test/tests/2-constitutional-delegates/constitutionalDelegate.vote.spec.ts index 9b4ce02..710cf03 100644 --- a/integration_test/tests/2-constitutional-delegates/constitutionalDelegate.vote.spec.ts +++ b/integration_test/tests/2-constitutional-delegates/constitutionalDelegate.vote.spec.ts @@ -26,7 +26,9 @@ test.describe('Delegate Vote', () => { await expect(page).toHaveTitle(CCVT.title); }); - test('2H. Should be able to change vote during open poll', async ({ page }) => { + test('2H. Should be able to change vote during open poll', async ({ + page, + }) => { await page.goto('/'); await expect(page).toHaveTitle(CCVT.title); }); @@ -35,6 +37,4 @@ test.describe('Delegate Vote', () => { await page.goto('/'); await expect(page).toHaveTitle(CCVT.title); }); - }); - diff --git a/integration_test/tests/3-alternates/alternate.registration.spec.ts b/integration_test/tests/3-alternates/alternate.registration.spec.ts index 60b9057..dc6f7b8 100644 --- a/integration_test/tests/3-alternates/alternate.registration.spec.ts +++ b/integration_test/tests/3-alternates/alternate.registration.spec.ts @@ -7,11 +7,10 @@ test.beforeEach(async () => { }); test.describe('Alternate Registration', () => { - - test('3A. Must be able to view their registration status', async ({ page }) => { + test('3A. Must be able to view their registration status', async ({ + page, + }) => { await page.goto('/'); await expect(page).toHaveTitle(CCVT.title); }); - }); - diff --git a/integration_test/tests/3-alternates/alternates.viewvote.spec.ts b/integration_test/tests/3-alternates/alternates.viewvote.spec.ts index 63ebb29..a4359e2 100644 --- a/integration_test/tests/3-alternates/alternates.viewvote.spec.ts +++ b/integration_test/tests/3-alternates/alternates.viewvote.spec.ts @@ -7,16 +7,17 @@ test.beforeEach(async () => { }); test.describe('Alternate View Vote', () => { - - test('3C. Must be able to view vote result and its count.', async ({ page }) => { + test('3C. Must be able to view vote result and its count.', async ({ + page, + }) => { await page.goto('/'); await expect(page).toHaveTitle(CCVT.title); }); - test('3D. Must be able to view own vote during open poll', async ({ page }) => { + test('3D. Must be able to view own vote during open poll', async ({ + page, + }) => { await page.goto('/'); await expect(page).toHaveTitle(CCVT.title); }); - }); - diff --git a/integration_test/tests/3-alternates/alternates.vote.spec.ts b/integration_test/tests/3-alternates/alternates.vote.spec.ts index e30a359..87c0c90 100644 --- a/integration_test/tests/3-alternates/alternates.vote.spec.ts +++ b/integration_test/tests/3-alternates/alternates.vote.spec.ts @@ -7,13 +7,16 @@ test.beforeEach(async () => { }); test.describe('Alternate Vote', () => { - - test('3A. Must not be able to vote while delegate is present.', async ({ page }) => { + test('3A. Must not be able to vote while delegate is present.', async ({ + page, + }) => { await page.goto('/'); await expect(page).toHaveTitle(CCVT.title); }); - test('3E. Should be able to change vote during open poll', async ({ page }) => { + test('3E. Should be able to change vote during open poll', async ({ + page, + }) => { await page.goto('/'); await expect(page).toHaveTitle(CCVT.title); }); @@ -23,4 +26,3 @@ test.describe('Alternate Vote', () => { await expect(page).toHaveTitle(CCVT.title); }); }); - diff --git a/integration_test/tests/4-community-members/communityMembers.pollStatus.spec.ts b/integration_test/tests/4-community-members/communityMembers.pollStatus.spec.ts index 591586c..1fa883a 100644 --- a/integration_test/tests/4-community-members/communityMembers.pollStatus.spec.ts +++ b/integration_test/tests/4-community-members/communityMembers.pollStatus.spec.ts @@ -7,11 +7,10 @@ test.beforeEach(async () => { }); test.describe('View Poll Status', () => { - - test('4G. Must be able to view vote result and its count.', async ({ page }) => { + test('4G. Must be able to view vote result and its count.', async ({ + page, + }) => { await page.goto('/'); await expect(page).toHaveTitle(CCVT.title); }); - }); - diff --git a/integration_test/tests/4-community-members/communityMembers.viewProfile.spec.ts b/integration_test/tests/4-community-members/communityMembers.viewProfile.spec.ts index 93adda4..2e36a42 100644 --- a/integration_test/tests/4-community-members/communityMembers.viewProfile.spec.ts +++ b/integration_test/tests/4-community-members/communityMembers.viewProfile.spec.ts @@ -7,19 +7,21 @@ test.beforeEach(async () => { }); test.describe('View Voter Profile', () => { - test('4C. Must be able to view voters profile.', async ({ page }) => { await page.goto('/'); await expect(page).toHaveTitle(CCVT.title); }); - - test('4D. Must be able to view delegate workspace name in profile.', async ({ page }) => { + test('4D. Must be able to view delegate workspace name in profile.', async ({ + page, + }) => { await page.goto('/'); await expect(page).toHaveTitle(CCVT.title); }); - test('4E. Could associate email with delegate profiles.', async ({ page }) => { + test('4E. Could associate email with delegate profiles.', async ({ + page, + }) => { await page.goto('/'); await expect(page).toHaveTitle(CCVT.title); }); @@ -29,10 +31,10 @@ test.describe('View Voter Profile', () => { await expect(page).toHaveTitle(CCVT.title); }); - test('4I. Should be able to view public information of voter.', async ({ page }) => { + test('4I. Should be able to view public information of voter.', async ({ + page, + }) => { await page.goto('/'); await expect(page).toHaveTitle(CCVT.title); }); - }); - diff --git a/integration_test/tests/4-community-members/communityMembers.viewVote.spec.ts b/integration_test/tests/4-community-members/communityMembers.viewVote.spec.ts index cb50b0e..f640617 100644 --- a/integration_test/tests/4-community-members/communityMembers.viewVote.spec.ts +++ b/integration_test/tests/4-community-members/communityMembers.viewVote.spec.ts @@ -7,11 +7,8 @@ test.beforeEach(async () => { }); test.describe('View Vote Status', () => { - test('4H. Should be able to view poll status', async ({ page }) => { await page.goto('/'); await expect(page).toHaveTitle(CCVT.title); }); - }); - diff --git a/integration_test/tsconfig.json b/integration_test/tsconfig.json index 179a6c2..c05cc3c 100644 --- a/integration_test/tsconfig.json +++ b/integration_test/tsconfig.json @@ -10,7 +10,7 @@ "@pages/*": ["lib/pages/*"], "@constants/*": ["lib/constants/*"], "@datafactory/*": ["lib/datafactory/*"], - "@types": ["lib/types.ts"], + "@types": ["lib/types.ts"] } } } diff --git a/tsconfig.json b/tsconfig.json index fb68dc1..4343e24 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,5 +17,5 @@ } }, "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], - "exclude": ["node_modules"] + "exclude": ["node_modules","integration_test"] }