Skip to content

Commit

Permalink
Fix poll setup
Browse files Browse the repository at this point in the history
  • Loading branch information
mesudip committed Dec 2, 2024
1 parent 5982310 commit d35e890
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 13 deletions.
18 changes: 12 additions & 6 deletions integration_test/lib/pages/homePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { faker } from '@faker-js/faker';
import { extractPollIdFromUrl } from '@helpers/string';
import { blake } from 'libcardano';
import PollPage from './pollPage';
import Logger from '@helpers/logger';

export default class HomePage {
readonly heading = this.page.getByText(
Expand All @@ -15,8 +16,8 @@ export default class HomePage {

// input
readonly pollNameInput = this.page.locator(
'[data-testid="poll-name-input"] input'
);
'[data-testid="poll-name-input"] textarea'
).first();

readonly constitutionLinkInput = this.page
.locator('[data-testid="poll-link-input"] input')
Expand Down Expand Up @@ -48,12 +49,17 @@ export default class HomePage {

await this.submitPollBtn.click();

await expect(this.page.getByText(pollName)).toBeVisible({
timeout: 10_000,
await this.page.waitForURL(/\/polls\/(?!new)/, {
timeout: 10_000,
});

const currentPageUrl = this.page.url();
return extractPollIdFromUrl(currentPageUrl);
Logger.info("Current page Url: " + currentPageUrl);

const pollId = extractPollIdFromUrl(currentPageUrl);

// Return the extracted poll ID
return pollId;
}

async getOpenPollCard(): Promise<Locator> {
Expand Down
5 changes: 2 additions & 3 deletions integration_test/lib/pages/loginPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ export default class LoginPage {
await this.goto();

await this.connectWalletBtn.first().click();
await this.eternlWalletBtn.click({ force: false });
await expect(this.page.getByText("Welcome")).toBeVisible()

await this.eternlWalletBtn.click({ force: true });
await expect(this.page.getByTestId('connected-user-name')).toBeVisible({timeout: 30000})
}

async logout(): Promise<void> {
Expand Down
3 changes: 3 additions & 0 deletions integration_test/lib/pages/pollPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export default class PollPage {
async deletePoll(): Promise<void> {
await this.deletePollBtn.click();
await this.deletePollConfirm.click();
await this.page.waitForURL('/', {
timeout: 10_000,
});

}
async endVoting() {
Expand Down
10 changes: 6 additions & 4 deletions integration_test/tests/voted-poll-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import { importWallet, injectWalletExtension } from '@fixtures/importWallet';
import loadEternlExtension from '@fixtures/loadExtension';
import { setAllureEpic, setAllureStory } from '@helpers/allure';
import Logger from '@helpers/logger';
import HomePage from '@pages/homePage';
import LoginPage from '@pages/loginPage';
import PollPage from '@pages/pollPage';
Expand All @@ -31,11 +32,10 @@ async function pageWithInjectedWallet(browser:Browser, wallet:StaticWallet): Pro

const loginPage = new LoginPage(page);
await loginPage.login();
await sleep(2000)
return page;
}
test(`Create Voted Poll`, async ({browser }) => {
test.slow()
test.setTimeout(300000) // let's set it to 5 minute
const getPage=async (w:StaticWallet)=>await pageWithInjectedWallet(browser,w)


Expand All @@ -60,18 +60,20 @@ test(`Create Voted Poll`, async ({browser }) => {
let pollPage=new PollPage(page)
await pollPage.goto(pollId)

const isActive = await pollPage.voteYesBtn.waitFor({state: "visible",timeout: 20000}).then(()=>true).catch(()=>false)
const isActive = await pollPage.voteYesBtn.waitFor({state: "visible",timeout: 30000}).then(()=>true).catch(()=>false)

if(!isActive){
Logger.info("User is not active voter: "+wallet.stakeAddress)
await page.close()
wallet=alternateWallets[index]
page = await pageWithInjectedWallet(browser,alternateWallets[index])
pollPage=new PollPage(page)
await pollPage.goto(pollId)
}

const randomVote = Math.floor(Math.random() * 3);
await page.getByTestId(votes[randomVote]).click();
await expect(page.getByText('Vote recorded!')).toBeVisible()
await expect(page.getByText('Vote recorded!'),"Expected Vote to be recorded for user: "+wallet.stakeAddress).toBeVisible({timeout:10000})
await page.close()
});
const organizerPollPage=new PollPage(organizerPages[0])
Expand Down
1 change: 1 addition & 0 deletions src/components/buttons/connectWalletButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ export function ConnectWalletButton(props: Props): JSX.Element {
? theme.palette.secondary.contrastText
: '#FFFFFF',
}}
data-testid={session?.data?.user?.name?'connected-user-name':''}
>
{session.status === 'authenticated'
? session.data.user.name
Expand Down
2 changes: 2 additions & 0 deletions src/components/polls/pollResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export function PollResults(props: Props): JSX.Element {
>
<Typography variant="h6">Summary Transaction</Typography>
<Link
data-testid="summary-tx-link"
href={
process.env.NEXT_PUBLIC_NETWORK === 'mainnet'
? `https://cardanoscan.io/transaction/${summaryTxId}?tab=metadata`
Expand All @@ -209,6 +210,7 @@ export function PollResults(props: Props): JSX.Element {
>
<Typography variant="h6">{`Vote record Tx #${index + 1}`}</Typography>
<Link
data-testid={'vote-record-tx-link-'+(index+1)}
href={
process.env.NEXT_PUBLIC_NETWORK === 'mainnet'
? `https://cardanoscan.io/transaction/${txId}?tab=metadata`
Expand Down

0 comments on commit d35e890

Please sign in to comment.