Skip to content

Commit

Permalink
Test: Implement 0-2A: User Profile tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mesudip committed Nov 17, 2024
1 parent d6c0e41 commit 464bd3c
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 31 deletions.
19 changes: 8 additions & 11 deletions integration_test/lib/fixtures/poll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -31,6 +31,7 @@ export const test = base.extend<TestOptions & { pollId: number }>({

const homePage = new HomePage(organizerPage);
await homePage.goto();
const organizerPollPage = new PollPage(organizerPage);

let pollId: number | undefined;

Expand All @@ -44,10 +45,7 @@ export const test = base.extend<TestOptions & { pollId: number }>({
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);

Expand All @@ -64,22 +62,21 @@ export const test = base.extend<TestOptions & { pollId: number }>({
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();
}
}

await use(pollId);

// cleanup
if (pollType !== 'NoAction') {
const pollPage = new PollPage(organizerPage);
await pollPage.goto(pollId);
// await pollPage.deletePoll();
await organizerPollPage.deletePoll();
}
},
});
10 changes: 10 additions & 0 deletions integration_test/lib/helpers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ export async function createAuth({
}: CreateUserProps): Promise<void> {
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();
Expand Down
19 changes: 13 additions & 6 deletions integration_test/lib/helpers/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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',
Expand All @@ -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,
});
}
81 changes: 68 additions & 13 deletions integration_test/tests/0-common/comon.spec.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand All @@ -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"
Expand Down Expand Up @@ -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*
Expand All @@ -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');
Expand All @@ -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
*
Expand All @@ -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
*
Expand All @@ -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+$/);

});
});
1 change: 1 addition & 0 deletions src/components/representatives/representativesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion src/components/representatives/votingHistoryTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function VotingHistoryTable(props: Props): JSX.Element {

if (polls.length > 0) {
return (
<Box display="flex" flexDirection="column" gap={1}>
<Box display="flex" flexDirection="column" gap={1} data-test-id="voting-history-table">
<Box display="flex" alignItems="center" justifyContent="space-between">
<Typography variant="h5" fontWeight="600">
Voting History
Expand Down

0 comments on commit 464bd3c

Please sign in to comment.