Skip to content

Commit

Permalink
Test: Refactor test names, add vote setup
Browse files Browse the repository at this point in the history
  • Loading branch information
mesudip committed Nov 15, 2024
1 parent 3091ba8 commit 484b8c6
Show file tree
Hide file tree
Showing 15 changed files with 300 additions and 117 deletions.
48 changes: 48 additions & 0 deletions integration_test/lib/_mock/wallets.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,53 @@
},
"dRepId": "drep1zz0swwxzmwfezqz4r4fa3cqcss7hgftdy6tsfavwhf2pu7d95jj",
"address": "addr_test1qzpxc66v0hk74h6fthnavvxjjgmujp6nkskyepzdh7x76wqsnurn3skmjwgsq4ga20vwqxyy846z2mfxjuz0tr462s0qw8jepc"
},
{
"payment": {
"private": "7094d6db1dcb756c5ca16dd78bb2b40e2a7ab44b9e0f9ba045c30c936cd91d4b",
"public": "2dcab974058989926304d0f811a207db91e8a5494fab0630c546e30672424481",
"pkh": "46db8ae386f2d8811f3be359d00a10b94a9af41e5d6266b6b35e19de"
},
"stake": {
"private": "f0b456be73948b0336ff1873e3abd6151540e632b76532535dddf63f67d91d4b",
"public": "e82dea6fbe5c866e8ae805a7d4c0824aac54daf5bff4c4224c76491ce63d42d7",
"pkh": "0cd61dcc68470aeb3f50de1a230460ab4982d81468dbd7ee94b0c814"
}
},
{
"payment": {
"private": "90b8338b3bd7e0069b2a3d8650706117287cc78fbc1329ad2f337fb161d91d4b",
"public": "f54d08863799fa95eab57623160aecec6e47604321ca8160f6c84b2b713555de",
"pkh": "2df75661915f3cf560f98fb0c54e2530146433f18a0b388e428947d1"
},
"stake": {
"private": "30eed77f86480ce26172e062fae8e7702db50f246ddc23089c77008160d91d4b",
"public": "a6ed4aa51b93523234776387010faca74669e08a0168b44d2dbdc525088f1b98",
"pkh": "3eb020543f2b97ee6baf14b5ce6754211803cd2f67a35ea5bf6427e5"
}
},
{
"payment": {
"private": "80cdcfa96c29cc5313c63b2f0c8ce647d6b8376f911239330cc23dbe65d91d4b",
"public": "6de9805440e25a1f77a32bf5b56e4b2fe38ff5a64eae0a686342aecb779265f6",
"pkh": "183ade5a8d284a9d2ee3859394e58b1c61837280cc71fcad565ceea5"
},
"stake": {
"private": "489f6ee7b556a171b8c8b6ddeee6927646c68f435ece2a7a265c616164d91d4b",
"public": "235208acfebcc3cf731908512f9e727cfc02462e05ab61c4d32f3b2564fec611",
"pkh": "a749bc9d6300c0aa57dd11851fbeb12ea9d8101f49ca4765f10de1a4"
}
},
{
"payment": {
"private": "b8a45789046b4671b22d52f385286c9327be57f8146d4056a985ccce63d91d4b",
"public": "e3f8be942173004d6eccef7e572b741bbbb7d08228125cb54e3ee7701b86adab",
"pkh": "89f2b776a14d1b7bb9f3a470840e3c6ebe4f231b4333e46e2333d419"
},
"stake": {
"private": "d809a1e7675450a2d20af2a0942562f059b7da3d36157ee28f34892f66d91d4b",
"public": "6bca2b86c77a170a96cbafa51c0f305cc5f72916762aa1d3b7968ced71979b0a",
"pkh": "8f3e346ff209f583a1409862f584361c18e0d39ff684b63409a924a3"
}
}
]
6 changes: 6 additions & 0 deletions integration_test/lib/constants/staticWallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ export const organizerWallet = staticWallets[0];

export const delegateWallet = staticWallets[1];
export const alternateWallet = staticWallets[2];

export const delegate2Wallet = staticWallets[3];
export const alternate2Wallet = staticWallets[4];

export const delegate3Wallet = staticWallets[5];
export const alternate3Wallet = staticWallets[6];
46 changes: 0 additions & 46 deletions integration_test/lib/fixtures/organizer.ts

This file was deleted.

71 changes: 71 additions & 0 deletions integration_test/lib/fixtures/poll.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import {delegateWallet, organizerWallet} from '@constants/staticWallets';
import { test as base } from '@fixtures/walletExtension';
import {createNewPageWithWallet, newDelegate2Page, newDelegate3Page} from '@helpers/page';
import HomePage from '@pages/homePage';
import PollPage from '@pages/pollPage';
import {expect} from "@playwright/test";

type pollEnableType = 'CreatePoll' | 'CreateAndBeginPoll' | 'NoAction' | 'VotedPoll';

type TestOptions = {
pollType: pollEnableType;
};

export const test = base.extend<TestOptions & { pollId: number }>({
pollType: ['NoAction', { option: true }],

pollId: async ({ browser, pollType }, use) => {
// setup
const organizerPage = await createNewPageWithWallet(browser, {
storageState: '.auth/organizer.json',
wallet: organizerWallet,
});

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

let pollId: number | undefined;

if (pollType !== 'NoAction') {
await homePage.deleteOpenPollCards();
pollId = await homePage.createPoll();

if (pollType === 'CreateAndBeginPoll') {
await homePage.beginVoteBtn.click();
}
if(pollType === 'VotedPoll'){
await homePage.beginVoteBtn.click();

const delegatePage = await createNewPageWithWallet(browser, {
storageState: '.auth/delegate.json',
wallet: delegateWallet,
});
const delegate2Page= await newDelegate2Page(browser)
const delegate3Page = await newDelegate3Page(browser)

const votes=['vote-yes-button','vote-no-button','vote-abstain-button']

await Promise.all([delegatePage,delegate2Page,delegate3Page].map(async (userPage,index)=>{
const userPollPage = new PollPage(userPage);
await userPollPage.goto(pollId);
// cast vote
await userPage.getByTestId(votes[index]).click()
}))
const pollPage=new PollPage(organizerPage)
await pollPage.goto(pollId)
await pollPage.endVoting()

}
}

await use(pollId);

// cleanup
if (pollType !== 'NoAction') {
const pollPage = new PollPage(organizerPage);
await pollPage.goto(pollId);
// await pollPage.deletePoll();
}
},

});
35 changes: 35 additions & 0 deletions integration_test/lib/helpers/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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";

interface NewPageConfig {
storageState?: string;
Expand Down Expand Up @@ -30,3 +31,37 @@ export async function createNewPageWithWallet(

return newPage;
}

export async function newDelegatePage(browser){
return await createNewPageWithWallet(browser, {
storageState: '.auth/delegate2.json',
wallet: delegate2Wallet,
});
}
export async function newDelegate2Page(browser){
return await createNewPageWithWallet(browser, {
storageState: '.auth/delegate2.json',
wallet: delegate2Wallet,
});
}
export async function newAlternate2Page(browser){
return await createNewPageWithWallet(browser, {
storageState: '.auth/alternate2.json',
wallet: delegate2Wallet,
});
}

export async function newDelegate3Page(browser){
return await createNewPageWithWallet(browser, {
storageState: '.auth/delegate3.json',
wallet: delegate2Wallet,
});
}

export async function newAlternate3Page(browser){
return await createNewPageWithWallet(browser, {
storageState: '.auth/alternate3.json',
wallet: delegate2Wallet,
});
}

4 changes: 4 additions & 0 deletions integration_test/lib/pages/pollPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default class PollPage {
readonly voteYesBtn = this.page.getByTestId('vote-yes-button');
readonly voteNoBtn = this.page.getByTestId('vote-no-button');
readonly voteAbstainBtn = this.page.getByTestId('vote-abstain-button');
readonly endVotingBtn = this.page.getByTestId('end-vote-button')

//chip or icon
readonly pollPageStatusChip = this.page.getByTestId('poll-page-status-chip');
Expand All @@ -23,4 +24,7 @@ export default class PollPage {
async deletePoll(): Promise<void> {
await this.deletePollBtn.click();
}
async endVoting(){
await this.endVotingBtn.click()
}
}
57 changes: 37 additions & 20 deletions integration_test/tests/0-common/comon.spec.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import { setAllureEpic } from '@helpers/allure';
import { expect } from '@playwright/test';
import { test } from '@fixtures/organizer';
import { test } from '@fixtures/poll';



test.beforeEach(async () => {
await setAllureEpic('0. All Users');
});

test.use({
pollType: 'CreateAndBeginPoll',
});//

test.describe('Polls', () => {

test.use({
pollType: 'CreateAndBeginPoll',
});//

/**
* Description: Anyone can see what stage in its lifecycle a poll is
*
* User Story: As an observer, I want to know whether a poll is pending, open or closed, so that I know what to expect
*
* Acceptance Criteria: Given that I am looking at a given poll, when I look at it, then I can see its status
*/
test('01A. Given any user, can view poll status', async ({ page }) => {
test('0-1A-1. Given any user, can view poll status in home page', async ({ page,pollId }) => {
await page.goto('/');
await page.waitForSelector('[data-testid^="poll-card-"]');

Expand All @@ -40,25 +41,24 @@ test.describe('Polls', () => {
expect(['Concluded', 'Pending','Voting']).toContain(statusText);
}

const randomIndex = Math.floor(Math.random() * pollCardCount);
const pollCard = pollCards.nth(randomIndex)
const pollCardTestId = await pollCard.getAttribute('data-testid');
const pollId = pollCardTestId.split('-').pop();

});
test('0-1A-2. Given any user, can view poll status in poll page', async ({page,pollId}) => {
await page.goto(`/polls/${pollId}`);


const pollPageStatusChip = page.getByTestId('poll-page-status-chip');
await expect(pollPageStatusChip).toBeVisible();

const statusText = await pollPageStatusChip.textContent();
expect(['Concluded', 'Pending','Voting']).toContain(statusText);

});

test('01B. Given any user, can view poll status', async ({page}) => {
throw new Error("Not Implemented")
});

})
test.describe('Polls',()=>{
test.use({
pollType: 'VotedPoll',
});//

/**
* Description: After a poll is closed the results of the poll should be displayed*
*
Expand All @@ -75,8 +75,25 @@ test.describe('Polls', () => {
*
* *results of a poll should never be displayed before the close of a poll
*/
test('01C. Given any user, can view poll results', async ({page}) => {
throw new Error("Not Implemented")
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');
await expect(pollPageStatusChip).toBeVisible();

await expect(page.getByTestId('results-yes')).toBeVisible()
await page.getByTestId('results-no').isVisible()
await page.getByTestId('results-abstain').isVisible()
await page.goto(`/polls/${pollId}`);

const yesCount = page.getByTestId('yes-count');
const noCount = page.getByTestId('no-count');
const abstainCount = page.getByTestId('abstain-count');

// Assert the text content for each count
await expect(yesCount).toHaveText('1');
await expect(noCount).toHaveText('1');
await expect(abstainCount).toHaveText('1');

});

/**
Expand All @@ -101,13 +118,13 @@ 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('02A-1. Given Delegate or alternate profile page, can view voting hsitory', async ({page}) => {
test('0-2A-1. Given Delegate or alternate profile page, can view voting hsitory', async ({page}) => {
throw new Error("Not Implemented")
});
test('02A-1. Can navigate to user profile from delegate/alternate listing page', async ({page}) => {
test('0-2A-1. Can navigate to user profile from delegate/alternate listing page', async ({page}) => {
throw new Error("Not Implemented")
});
test('02A-1. Can navigate to user profile from voter view in poll results page', async ({page}) => {
test('0-2A-1. Can navigate to user profile from voter view in poll results page', async ({page}) => {
throw new Error("Not Implemented")
});

Expand Down
Loading

0 comments on commit 484b8c6

Please sign in to comment.