diff --git a/integration_test/lib/fixtures/poll.ts b/integration_test/lib/fixtures/poll.ts index 6eecdca..3e42b46 100644 --- a/integration_test/lib/fixtures/poll.ts +++ b/integration_test/lib/fixtures/poll.ts @@ -1,11 +1,19 @@ -import {delegateWallet, organizerWallet} from '@constants/staticWallets'; +import { delegateWallet, organizerWallet } from '@constants/staticWallets'; import { test as base } from '@fixtures/walletExtension'; -import {createNewPageWithWallet, newDelegate2Page, newDelegate3Page} from '@helpers/page'; +import { + createNewPageWithWallet, + newDelegate2Page, + newDelegate3Page, +} from '@helpers/page'; import HomePage from '@pages/homePage'; import PollPage from '@pages/pollPage'; -import {expect} from "@playwright/test"; +import { expect } from '@playwright/test'; -type pollEnableType = 'CreatePoll' | 'CreateAndBeginPoll' | 'NoAction' | 'VotedPoll'; +type pollEnableType = + | 'CreatePoll' + | 'CreateAndBeginPoll' + | 'NoAction' + | 'VotedPoll'; type TestOptions = { pollType: pollEnableType; @@ -33,28 +41,35 @@ export const test = base.extend({ if (pollType === 'CreateAndBeginPoll') { await homePage.beginVoteBtn.click(); } - if(pollType === 'VotedPoll'){ + 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 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() + 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(); } } @@ -67,5 +82,4 @@ export const test = base.extend({ // await pollPage.deletePoll(); } }, - }); diff --git a/integration_test/lib/helpers/page.ts b/integration_test/lib/helpers/page.ts index a7a3cb2..336163e 100644 --- a/integration_test/lib/helpers/page.ts +++ b/integration_test/lib/helpers/page.ts @@ -2,7 +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"; +import { delegate2Wallet, delegateWallet } from '@constants/staticWallets'; interface NewPageConfig { storageState?: string; @@ -32,36 +32,35 @@ export async function createNewPageWithWallet( return newPage; } -export async function newDelegatePage(browser){ +export async function newDelegatePage(browser) { return await createNewPageWithWallet(browser, { storageState: '.auth/delegate2.json', wallet: delegate2Wallet, }); } -export async function newDelegate2Page(browser){ +export async function newDelegate2Page(browser) { return await createNewPageWithWallet(browser, { storageState: '.auth/delegate2.json', wallet: delegate2Wallet, }); } -export async function newAlternate2Page(browser){ +export async function newAlternate2Page(browser) { return await createNewPageWithWallet(browser, { storageState: '.auth/alternate2.json', wallet: delegate2Wallet, }); } -export async function newDelegate3Page(browser){ +export async function newDelegate3Page(browser) { return await createNewPageWithWallet(browser, { storageState: '.auth/delegate3.json', wallet: delegate2Wallet, }); } -export async function newAlternate3Page(browser){ +export async function newAlternate3Page(browser) { return await createNewPageWithWallet(browser, { storageState: '.auth/alternate3.json', wallet: delegate2Wallet, }); } - diff --git a/integration_test/lib/pages/pollPage.ts b/integration_test/lib/pages/pollPage.ts index 8fafd21..bf63a74 100644 --- a/integration_test/lib/pages/pollPage.ts +++ b/integration_test/lib/pages/pollPage.ts @@ -9,7 +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') + readonly endVotingBtn = this.page.getByTestId('end-vote-button'); //chip or icon readonly pollPageStatusChip = this.page.getByTestId('poll-page-status-chip'); @@ -24,7 +24,7 @@ export default class PollPage { async deletePoll(): Promise { await this.deletePollBtn.click(); } - async endVoting(){ - await this.endVotingBtn.click() + async endVoting() { + await this.endVotingBtn.click(); } } diff --git a/integration_test/tests/0-common/comon.spec.ts b/integration_test/tests/0-common/comon.spec.ts index 63fee8c..36787d4 100644 --- a/integration_test/tests/0-common/comon.spec.ts +++ b/integration_test/tests/0-common/comon.spec.ts @@ -2,131 +2,138 @@ import { setAllureEpic } from '@helpers/allure'; import { expect } from '@playwright/test'; import { test } from '@fixtures/poll'; - - test.beforeEach(async () => { - await setAllureEpic('0. All Users'); + await setAllureEpic('0. All Users'); }); - 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('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-"]'); - - let pollCards = page.locator('[data-testid^="poll-card-"]'); - - let pollCardCount = await pollCards.count(); - expect(pollCardCount).toBeGreaterThan(0); - - // Check that each poll card has a 'poll-status-chip' with "Concluded" or "Pending" - for (let i = 0; i < pollCardCount; i++) { - const statusChip = pollCards.nth(i).locator('[data-testid="poll-status-chip"]'); - - await expect(statusChip).toBeVisible(); - - const statusText = await statusChip.textContent(); - expect(['Concluded', 'Pending','Voting']).toContain(statusText); - } - - }); - 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.describe('Polls',()=>{ - test.use({ - pollType: 'VotedPoll', - });// - - /** - * Description: After a poll is closed the results of the poll should be displayed* - * - * User Story: - * As an observer I want to know: - * - * How many yes, no & abstain votes there were - * How many people didn't vote - * The result - * Who voted for what - * ... when a poll is closed, so that I know the outcome - * - * Acceptance Criteria: Given that I am observing an open poll, when the poll is closed by a CO, then the results are displayed to me - * - * *results of a poll should never be displayed before the close of a poll - */ - 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'); - - }); - - /** - * Description: By going to the profile page of a delegate or alternate I can review their voting record - * - * User Story: As an observer I want to know how a given delegate or alternate has voted, so that I can examine their record - * - * Acceptance Criteria 1: Given that I am on the page listing delegates and alternates, when I press on a given delegate or alternate, then I will go to their profile page and see their voting record - * - * 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.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('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-"]'); + + let pollCards = page.locator('[data-testid^="poll-card-"]'); + + let pollCardCount = await pollCards.count(); + expect(pollCardCount).toBeGreaterThan(0); + + // Check that each poll card has a 'poll-status-chip' with "Concluded" or "Pending" + for (let i = 0; i < pollCardCount; i++) { + const statusChip = pollCards + .nth(i) + .locator('[data-testid="poll-status-chip"]'); + + await expect(statusChip).toBeVisible(); + + const statusText = await statusChip.textContent(); + expect(['Concluded', 'Pending', 'Voting']).toContain(statusText); + } + }); + 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.describe('Polls', () => { + test.use({ + pollType: 'VotedPoll', + }); // + + /** + * Description: After a poll is closed the results of the poll should be displayed* + * + * User Story: + * As an observer I want to know: + * + * How many yes, no & abstain votes there were + * How many people didn't vote + * The result + * Who voted for what + * ... when a poll is closed, so that I know the outcome + * + * Acceptance Criteria: Given that I am observing an open poll, when the poll is closed by a CO, then the results are displayed to me + * + * *results of a poll should never be displayed before the close of a poll + */ + 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'); + }); + + /** + * Description: By going to the profile page of a delegate or alternate I can review their voting record + * + * User Story: As an observer I want to know how a given delegate or alternate has voted, so that I can examine their record + * + * Acceptance Criteria 1: Given that I am on the page listing delegates and alternates, when I press on a given delegate or alternate, then I will go to their profile page and see their voting record + * + * 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.describe('User profile', () => { - /** - * Description: By going to the profile page of a delegate or alternate I can review their voting record - * - * User Story: As an observer I want to know how a given delegate or alternate has voted, so that I can examine their record - * - * Acceptance Criteria 1: Given that I am on the page listing delegates and alternates, when I press on a given delegate or alternate, then I will go to their profile page and see their voting record - * - * 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}) => { - throw new Error("Not Implemented") - }); - -}) - + /** + * Description: By going to the profile page of a delegate or alternate I can review their voting record + * + * User Story: As an observer I want to know how a given delegate or alternate has voted, so that I can examine their record + * + * Acceptance Criteria 1: Given that I am on the page listing delegates and alternates, when I press on a given delegate or alternate, then I will go to their profile page and see their voting record + * + * 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, + }) => { + throw new Error('Not Implemented'); + }); +}); diff --git a/integration_test/tests/auth.setup.ts b/integration_test/tests/auth.setup.ts index b55badc..641de07 100644 --- a/integration_test/tests/auth.setup.ts +++ b/integration_test/tests/auth.setup.ts @@ -3,20 +3,43 @@ import { delegateWallet, organizerWallet, } from '@constants/staticWallets'; -import * as wallets from '@constants/staticWallets' +import * as wallets from '@constants/staticWallets'; import { test as setup } from '@fixtures/walletExtension'; import { setAllureEpic, setAllureStory } from '@helpers/allure'; import { createAuth } from '@helpers/auth'; const authConfigurations = [ - { wallet: organizerWallet, authFile: '.auth/organizer.json', role: 'Organizer' }, + { + wallet: organizerWallet, + authFile: '.auth/organizer.json', + role: 'Organizer', + }, { wallet: delegateWallet, authFile: '.auth/delegate.json', role: 'Delegate' }, - { wallet: alternateWallet, authFile: '.auth/alternate.json', role: 'Alternate' }, - { wallet: wallets.delegate2Wallet, authFile: '.auth/delegate2.json', role: 'Delegate2' }, - { wallet: wallets.alternate2Wallet, authFile: '.auth/alternate2.json', role: 'Alternate2' }, - { wallet: wallets.delegate3Wallet, authFile: '.auth/delegate3.json', role: 'Delegate3' }, - { wallet: wallets.alternate3Wallet, authFile: '.auth/alternate3.json', role: 'Alternate3' }, - + { + wallet: alternateWallet, + authFile: '.auth/alternate.json', + role: 'Alternate', + }, + { + wallet: wallets.delegate2Wallet, + authFile: '.auth/delegate2.json', + role: 'Delegate2', + }, + { + wallet: wallets.alternate2Wallet, + authFile: '.auth/alternate2.json', + role: 'Alternate2', + }, + { + wallet: wallets.delegate3Wallet, + authFile: '.auth/delegate3.json', + role: 'Delegate3', + }, + { + wallet: wallets.alternate3Wallet, + authFile: '.auth/alternate3.json', + role: 'Alternate3', + }, ]; setup.beforeEach(async () => { diff --git a/src/lib/deriveStakeAddressFromPublicKey.ts b/src/lib/deriveStakeAddressFromPublicKey.ts index cd61b85..44497ab 100644 --- a/src/lib/deriveStakeAddressFromPublicKey.ts +++ b/src/lib/deriveStakeAddressFromPublicKey.ts @@ -17,7 +17,7 @@ export function deriveStakeAddressFromPublicKey(publicKey: PublicKey): string { const stakeCredential = Credential.from_keyhash(stakeKeyHash); // Generate the stake address (e.g., for mainnet) - const networkId = 1; // 1 for mainnet, 0 for testnet + const networkId = process.env.NEXT_PUBLIC_NETWORK?.toLowerCase() =='testnet'? 0 : 1; // 1 for mainnet, 0 for testnet const stakeAddress = RewardAddress.new( networkId, stakeCredential,