diff --git a/integration_test/lib/fixtures/poll.ts b/integration_test/lib/fixtures/poll.ts index 3e42b46..a54ded2 100644 --- a/integration_test/lib/fixtures/poll.ts +++ b/integration_test/lib/fixtures/poll.ts @@ -4,10 +4,10 @@ import { createNewPageWithWallet, newDelegate2Page, newDelegate3Page, + newDelegatePage, } from '@helpers/page'; import HomePage from '@pages/homePage'; import PollPage from '@pages/pollPage'; -import { expect } from '@playwright/test'; type pollEnableType = | 'CreatePoll' @@ -31,6 +31,7 @@ export const test = base.extend({ const homePage = new HomePage(organizerPage); await homePage.goto(); + const organizerPollPage = new PollPage(organizerPage); let pollId: number | undefined; @@ -44,10 +45,7 @@ export const test = base.extend({ if (pollType === 'VotedPoll') { await homePage.beginVoteBtn.click(); - const delegatePage = await createNewPageWithWallet(browser, { - storageState: '.auth/delegate.json', - wallet: delegateWallet, - }); + const delegatePage = await newDelegatePage(browser); const delegate2Page = await newDelegate2Page(browser); const delegate3Page = await newDelegate3Page(browser); @@ -64,12 +62,13 @@ export const test = base.extend({ await userPollPage.goto(pollId); // cast vote await userPage.getByTestId(votes[index]).click(); + await userPage.getByText('Vote recorded').isVisible() + await userPage.close(); } ) ); - const pollPage = new PollPage(organizerPage); - await pollPage.goto(pollId); - await pollPage.endVoting(); + await organizerPollPage.goto(pollId); + await organizerPollPage.endVoting(); } } @@ -77,9 +76,7 @@ export const test = base.extend({ // cleanup if (pollType !== 'NoAction') { - const pollPage = new PollPage(organizerPage); - await pollPage.goto(pollId); - // await pollPage.deletePoll(); + await organizerPollPage.deletePoll(); } }, }); diff --git a/integration_test/lib/helpers/auth.ts b/integration_test/lib/helpers/auth.ts index f64dbf9..9adc356 100644 --- a/integration_test/lib/helpers/auth.ts +++ b/integration_test/lib/helpers/auth.ts @@ -19,6 +19,16 @@ export async function createAuth({ }: CreateUserProps): Promise { await importWallet(page, wallet); + await page.route('/api/getUser/*', (route, request) => { + const userId = request.url().split('/').pop(); + if (userId) { + page.evaluate((id) => { + localStorage.setItem('userId', id); + }, userId); + } + route.continue(); + }); + const loginPage = new LoginPage(page); await loginPage.login(); await loginPage.isLoggedIn(); diff --git a/integration_test/lib/helpers/page.ts b/integration_test/lib/helpers/page.ts index 336163e..9d802e7 100644 --- a/integration_test/lib/helpers/page.ts +++ b/integration_test/lib/helpers/page.ts @@ -2,7 +2,13 @@ import { importWallet } from '@fixtures/importWallet'; import loadDemosExtension from '@fixtures/loadExtension'; import { Browser, Page } from '@playwright/test'; import { StaticWallet } from '@types'; -import { delegate2Wallet, delegateWallet } from '@constants/staticWallets'; +import { + alternate2Wallet, + alternate3Wallet, + delegate2Wallet, + delegate3Wallet, + delegateWallet, +} from '@constants/staticWallets'; interface NewPageConfig { storageState?: string; @@ -34,10 +40,11 @@ export async function createNewPageWithWallet( export async function newDelegatePage(browser) { return await createNewPageWithWallet(browser, { - storageState: '.auth/delegate2.json', - wallet: delegate2Wallet, + storageState: '.auth/delegate.json', + wallet: delegateWallet, }); } + export async function newDelegate2Page(browser) { return await createNewPageWithWallet(browser, { storageState: '.auth/delegate2.json', @@ -47,20 +54,20 @@ export async function newDelegate2Page(browser) { export async function newAlternate2Page(browser) { return await createNewPageWithWallet(browser, { storageState: '.auth/alternate2.json', - wallet: delegate2Wallet, + wallet: alternate2Wallet, }); } export async function newDelegate3Page(browser) { return await createNewPageWithWallet(browser, { storageState: '.auth/delegate3.json', - wallet: delegate2Wallet, + wallet: delegate3Wallet, }); } export async function newAlternate3Page(browser) { return await createNewPageWithWallet(browser, { storageState: '.auth/alternate3.json', - wallet: delegate2Wallet, + wallet: alternate3Wallet, }); } diff --git a/integration_test/tests/0-common/comon.spec.ts b/integration_test/tests/0-common/comon.spec.ts index 36787d4..5ebc345 100644 --- a/integration_test/tests/0-common/comon.spec.ts +++ b/integration_test/tests/0-common/comon.spec.ts @@ -1,5 +1,5 @@ import { setAllureEpic } from '@helpers/allure'; -import { expect } from '@playwright/test'; +import { expect, Page } from '@playwright/test'; import { test } from '@fixtures/poll'; test.beforeEach(async () => { @@ -25,9 +25,9 @@ test.describe('Polls', () => { await page.goto('/'); await page.waitForSelector('[data-testid^="poll-card-"]'); - let pollCards = page.locator('[data-testid^="poll-card-"]'); + const pollCards = page.locator('[data-testid^="poll-card-"]'); - let pollCardCount = await pollCards.count(); + const pollCardCount = await pollCards.count(); expect(pollCardCount).toBeGreaterThan(0); // Check that each poll card has a 'poll-status-chip' with "Concluded" or "Pending" @@ -58,7 +58,7 @@ test.describe('Polls', () => { test.describe('Polls', () => { test.use({ pollType: 'VotedPoll', - }); // + }); /** * Description: After a poll is closed the results of the poll should be displayed* @@ -79,7 +79,6 @@ test.describe('Polls', () => { test('0-1B. Given any user, can view poll results', async ({ page, pollId, - browser, }) => { await page.goto(`/polls/${pollId}`); const pollPageStatusChip = page.getByTestId('poll-page-status-chip'); @@ -100,6 +99,13 @@ test.describe('Polls', () => { await expect(abstainCount).toHaveText('1'); }); +}); + +test.describe('User profile', () => { + test.use({ + pollType: 'VotedPoll', + }); + /** * Description: By going to the profile page of a delegate or alternate I can review their voting record * @@ -109,9 +115,45 @@ test.describe('Polls', () => { * * Acceptance Criteria 2: Given that I am on the results page of a closed poll, when I press on the tile of a given voter, then I am taken to their profile page and can see their voting record */ -}); + test('0-2A-1. Given Delegate or alternate profile page, can view voting hsitory', async ({ + page, + pollId, + browser + }) => { + await page.goto('/polls/'+pollId); + + + const buttons = await page.locator('[data-testid^="representative-vote-"]').all(); + + if (buttons.length === 0) { + throw new Error('No representative vote buttons found'); + } + const pages:Page[]=[]; + for (const button of buttons) { + const testId = await button.getAttribute('data-testid'); + console.log(`Opening new tab for button with test id: ${testId}`); + + // Get the href attribute or construct the URL for navigation + const href = await button.getAttribute('href'); + if (!href) { + throw new Error(`Button with test id: ${testId} does not have an href attribute`); + } + + // Open a new tab + const newPage = await browser.newPage(); + await newPage.goto(href); + console.log(`Opened new tab for: ${href}`); + + pages.push(newPage); + } + await Promise.all(pages.map(async (voterPage)=>{ + const votingTable= voterPage.getByTestId('voting-history-table'); + await votingTable.getByTestId('user-votes-'+pollId).isVisible(); + })); + + }); + -test.describe('User profile', () => { /** * Description: By going to the profile page of a delegate or alternate I can review their voting record * @@ -121,19 +163,32 @@ test.describe('User profile', () => { * * Acceptance Criteria 2: Given that I am on the results page of a closed poll, when I press on the tile of a given voter, then I am taken to their profile page and can see their voting record */ - test('0-2A-1. Given Delegate or alternate profile page, can view voting hsitory', async ({ - page, - }) => { - throw new Error('Not Implemented'); - }); + test('0-2A-1. Can navigate to user profile from delegate/alternate listing page', async ({ page, }) => { + throw new Error('Not Implemented'); }); + + test('0-2A-1. Can navigate to user profile from voter view in poll results page', async ({ page, + pollId, }) => { - throw new Error('Not Implemented'); + await page.goto('polls/' + pollId); + + // Locate the buttons + const buttons = await page.locator('[data-testid^="representative-vote-"]').all(); + + if (buttons.length === 0) { + throw new Error('No representative vote buttons found'); + } + + // Click the first button + await buttons[0].click(); + + await page.waitForURL(/\/representatives\/\d+$/); + }); }); diff --git a/src/components/representatives/representativesTable.tsx b/src/components/representatives/representativesTable.tsx index 8b36a4f..ffdcdb5 100644 --- a/src/components/representatives/representativesTable.tsx +++ b/src/components/representatives/representativesTable.tsx @@ -199,6 +199,7 @@ export function RepresentativesTable(props: Props): JSX.Element { rows={workshops.filter( (workshop) => workshop.name !== 'Convention Organizer', )} + data-test-id="representatives-table" columns={columns} initialState={{ pagination: { diff --git a/src/components/representatives/votingHistoryTable.tsx b/src/components/representatives/votingHistoryTable.tsx index 25ce03a..489724b 100644 --- a/src/components/representatives/votingHistoryTable.tsx +++ b/src/components/representatives/votingHistoryTable.tsx @@ -79,7 +79,7 @@ export function VotingHistoryTable(props: Props): JSX.Element { if (polls.length > 0) { return ( - + Voting History