Skip to content

Commit

Permalink
Merge pull request #1673 from IntersectMBO/test
Browse files Browse the repository at this point in the history
chore: bump @intersect.mbo/pdf-ui@0.3.3
  • Loading branch information
MSzalowski authored Aug 2, 2024
2 parents f133408 + 7dd66e3 commit bd520c3
Show file tree
Hide file tree
Showing 18 changed files with 12,983 additions and 161 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ changes.
- Change link to propose a governace action docs [Issue 1132](https://github.com/IntersectMBO/govtool/issues/1132)
- Change link to docs regarding DReps [Issue 1130](https://github.com/IntersectMBO/govtool/issues/1130)
- Change link to view governance actions docs [Issue 1131](https://github.com/IntersectMBO/govtool/issues/1131)
- Change link to delegate voting power docs, [Issue 1654](https://github.com/IntersectMBO/govtool/issues/1654)
- Make all the frontend build arguments mandatory [Issue 1642](https://github.com/IntersectMBO/govtool/issues/1642), [Issue 1643](https://github.com/IntersectMBO/govtool/issues/1643)
- Breaking! Remove usage of metadata validation service in Haskell Backend
- Bump @intersect.mbo/pdf-ui to v0.3.3

## [sancho-v1.0.11](https://github.com/IntersectMBO/govtool/releases/tag/sancho-v1.0.11) 2024-07-30

Expand Down
8 changes: 4 additions & 4 deletions govtool/frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion govtool/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@emurgo/cardano-serialization-lib-asmjs": "12.0.0-beta.2",
"@hookform/resolvers": "^3.3.1",
"@intersect.mbo/intersectmbo.org-icons-set": "^1.0.8",
"@intersect.mbo/pdf-ui": "^0.3.2",
"@intersect.mbo/pdf-ui": "^0.3.3",
"@mui/icons-material": "^5.14.3",
"@mui/material": "^5.14.4",
"@rollup/plugin-babel": "^6.0.4",
Expand Down
2 changes: 1 addition & 1 deletion govtool/frontend/src/components/organisms/HomeCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const HomeCards = () => {

const onClickLearnMoreAboutDelegation = () =>
openInNewTab(
"https://docs.sanchogov.tools/faqs/ways-to-use-your-voting-power",
"https://docs.sanchogov.tools/how-to-use-the-govtool/using-govtool/delegating",
);

const onClickLearnMoreAboutDRepRegistration = () =>
Expand Down
12,853 changes: 12,853 additions & 0 deletions govtool/frontend/yarn.lock

Large diffs are not rendered by default.

8 changes: 1 addition & 7 deletions tests/govtool-frontend/playwright/lib/_mock/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,7 @@ export const invalid = {
},

amount: () => {
const choice = faker.number.int({ min: 1, max: 2 });
if (choice === 1) {
// only number is allowed
return faker.lorem.word();
}
// empty invalid
return " ";
return faker.lorem.word();
},
};

Expand Down
8 changes: 4 additions & 4 deletions tests/govtool-frontend/playwright/lib/constants/docsUrl.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import environments from "./environments";

export const DELEGATION_DOC_URL = `${environments.docsUrl}/faqs/ways-to-use-your-voting-power`;
export const REGISTER_DREP_DOC_URL = `${environments.docsUrl}/faqs/what-does-it-mean-to-register-as-a-drep`;
export const DELEGATION_DOC_URL = `${environments.docsUrl}/how-to-use-the-govtool/using-govtool/delegating`;
export const REGISTER_DREP_DOC_URL = `${environments.docsUrl}/how-to-use-the-govtool/using-govtool/dreps`;
export const DIRECT_VOTER_DOC_URL = `${environments.docsUrl}/how-to-use-the-govtool/using-govtool/direct-voting`;
export const GOVERNANCE_ACTION_DOC_URL = `${environments.docsUrl}/how-to-use-the-govtool/using-govtool/governance-actions/governance-actions-how-to-vote`;
export const PROPOSE_GOVERNANCE_ACTION_DOC_URL = `${environments.docsUrl}/how-to-use-the-govtool/using-govtool/governance-actions`;
export const GOVERNANCE_ACTION_DOC_URL = `${environments.docsUrl}/how-to-use-the-govtool/using-govtool/governance-actions`;
export const PROPOSE_GOVERNANCE_ACTION_DOC_URL = `${environments.docsUrl}/how-to-use-the-govtool/using-govtool/governance-actions/propose-a-governance-action`;
export const ABSTAIN_VOTE_DOC_URL = `${environments.docsUrl}/how-to-use-the-govtool/using-govtool/delegating/abstain-from-every-vote`;
export const SIGNAL_NO_CONFIDENCE_VOTE_DOC_URL = `${environments.docsUrl}/how-to-use-the-govtool/using-govtool/delegating/signal-no-confidence-on-every-vote`;
export const FAQS_DOC_URL = `${environments.docsUrl}/faqs`;
Expand Down
6 changes: 2 additions & 4 deletions tests/govtool-frontend/playwright/lib/helpers/auth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { faker } from "@faker-js/faker";
import { importWallet } from "@fixtures/importWallet";
import { valid as mockValid } from "@mock/index";
import LoginPage from "@pages/loginPage";
import ProposalDiscussionPage from "@pages/proposalDiscussionPage";
import { BrowserContext, Page } from "@playwright/test";
Expand Down Expand Up @@ -43,9 +43,7 @@ export async function createAuthWithUserName({
await proposalDiscussionPage.goto();
await proposalDiscussionPage.verifyIdentityBtn.click();

await proposalDiscussionPage.setUsername(
faker.internet.userName().toLowerCase()
);
await proposalDiscussionPage.setUsername(mockValid.username());

await context.storageState({ path: auth });
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ export default class ProposalDiscussionDetailsPage {
readonly showReplyBtn = this.page.getByTestId("show-more-reply");
readonly closePollYesBtn = this.page.getByTestId("close-the-poll-button");
readonly changeVoteBtn = this.page.getByTestId("change-vote-button");
readonly verifyIdentityBtn = this.page.getByRole("button", {
name: "Verify your identity",
}); // BUG
readonly verifyIdentityBtn = this.page.getByTestId("verify-identity-button");
readonly submitAsGABtn = this.page.getByTestId("submit-as-GA-button");

// Indicators
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { expect, Locator, Page } from "@playwright/test";
import { ProposalCreateRequest, ProposedGovAction } from "@types";
import environments from "lib/constants/environments";
import ProposalDiscussionDetailsPage from "./proposalDiscussionDetailsPage";
import { isMobile } from "@helpers/mobile";

export default class ProposalDiscussionPage {
// Buttons
Expand All @@ -16,9 +17,7 @@ export default class ProposalDiscussionPage {
readonly sortBtn = this.page.getByTestId("sort-button");
readonly searchInput = this.page.getByTestId("search-input");
readonly showAllBtn = this.page.getByTestId("show-all-button").first(); //this.page.getByTestId("show-all-button");
readonly verifyIdentityBtn = this.page.getByRole("button", {
name: "Verify your identity",
}); // BUG
readonly verifyIdentityBtn = this.page.getByTestId("verify-identity-button");
readonly addLinkBtn = this.page.getByTestId("add-link-button");
readonly infoRadio = this.page.getByTestId("Info-radio-wrapper");
readonly treasuryRadio = this.page.getByTestId("Treasury-radio-wrapper");
Expand All @@ -30,6 +29,15 @@ export default class ProposalDiscussionPage {

async goto() {
await this.page.goto(`${environments.frontendUrl}/proposal_discussion`);
// Temporary fix for blank proposals issue in proposal view during disconnected state
// This code handles the blank proposals error, which is causing failing tests.
// It will be removed once the underlying issue is resolved.
await this.page.getByTestId("logo-button").click();
if (isMobile(this.page)) {
await this.page.getByTestId("open-drawer-button").click();
}
await this.page.getByText("Proposals", { exact: true }).click();

await this.page.waitForTimeout(2_000);
}

Expand Down Expand Up @@ -142,16 +150,21 @@ export default class ProposalDiscussionPage {
}
}

async filterProposalByNames(names: string[]) {
async clickRadioButtonsByNames(names: string[]) {
for (const name of names) {
await this.page.getByLabel(name).click(); // test id is not in proper format for all filter type
const replaceSpaceWithUnderScore = name.toLowerCase().replace(/ /g, "-");
await this.page
.getByTestId(`${replaceSpaceWithUnderScore}-radio`)
.click();
}
}

async filterProposalByNames(names: string[]) {
await this.clickRadioButtonsByNames(names);
}

async unFilterProposalByNames(names: string[]) {
for (const name of names) {
await this.page.getByLabel(name).click(); // test id is not in proper format for all filter type
}
await this.clickRadioButtonsByNames(names);
}

async validateFilters(
Expand Down Expand Up @@ -203,12 +216,13 @@ export default class ProposalDiscussionPage {
proposalCard: Locator,
filters: string[]
): Promise<boolean> {
const govActionType = await proposalCard
.locator('[data-test^="proposal-"][data-testid$="-status"]')
let govActionType = await proposalCard
.locator('[data-testid^="proposal-"][data-testid$="-status"]')
.textContent();
if (govActionType === "Active") {
govActionType = "Active proposal";
}

return filters
.map((filter) => filter.toLowerCase())
.includes(govActionType.toLowerCase());
return filters.includes(govActionType);
}
}
136 changes: 49 additions & 87 deletions tests/govtool-frontend/playwright/lib/pages/proposalSubmissionPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import { expectWithInfo } from "@helpers/exceptionHandler";
import { downloadMetadata } from "@helpers/metadata";
import { extractProposalIdFromUrl } from "@helpers/string";
import { invalid } from "@mock/index";
import { Download, Page, expect } from "@playwright/test";
import { Download, Locator, Page, expect } from "@playwright/test";
import metadataBucketService from "@services/metadataBucketService";
import { ProposalCreateRequest, ProposalLink, ProposalType } from "@types";

const formErrors = {
proposalTitle: ["max-80-characters-error", "this-field-is-required-error"],
abstract: "this-field-is-required-error",
motivation: "this-field-is-required-error",
Rationale: "this-field-is-required-error",
receivingAddress: "invalid-bech32-address-error",
amount: ["only-number-is-allowed-error", "this-field-is-required-error"],
link: "invalid-url-error",
proposalTitle: "title-input-error",
abstract: "abstract-helper-error",
motivation: "motivation-helper-error",
rationale: "rationale-helper-error",
receivingAddress: "receiving-address-text-error",
amount: "amount-text-error",
link: "link-0-url-input-error",
};

export default class ProposalSubmissionPage {
Expand All @@ -43,9 +43,7 @@ export default class ProposalSubmissionPage {
readonly editSubmissionButton = this.page.getByTestId(
"edit-submission-button"
);
readonly verifyIdentityBtn = this.page.getByRole("button", {
name: "Verify your identity",
}); // BUG missing test id
readonly verifyIdentityBtn = this.page.getByTestId("verify-identity-button");
readonly governanceActionType = this.page.getByLabel(
"Governance Action Type *"
);
Expand All @@ -65,9 +63,7 @@ export default class ProposalSubmissionPage {
"receiving-address-input"
);
readonly amountInput = this.page.getByTestId("amount-input");
readonly closeDraftSuccessModalBtn = this.page.getByTestId(
"delete-proposal-yes-button"
); //BUG Improper test ids
readonly closeDraftSuccessModalBtn = this.page.getByTestId("close-button");

constructor(private readonly page: Page) {}

Expand Down Expand Up @@ -215,88 +211,54 @@ export default class ProposalSubmissionPage {
await expect(this.continueBtn).toBeEnabled();
}

async inValidateForm(governanceProposal: ProposalCreateRequest) {
await this.fillupFormWithTypeSelected(governanceProposal);

function convertTestIdToText(testId: string) {
let text = testId.replace("-error", "");
text = text.replace(/-/g, " ");
return text[0].toUpperCase() + text.substring(1);
}

// Helper function to generate regex pattern from form errors
function generateRegexPattern(errors: string[]) {
return new RegExp(errors.map(convertTestIdToText).join("|"));
async assertFieldValidation(
input: Locator,
errorField: string,
value: string,
logMessage: string
) {
if (value === " ") {
await expect(this.page.getByTestId(errorField)).toBeVisible();
} else {
expectWithInfo(
async () => expect(await input.textContent()).not.toEqual(value),
`${logMessage}: ${value}`
);
}
}

// Helper function to get errors based on regex pattern
async function getErrorsByPattern(page: Page, regexPattern: RegExp) {
return await page
.locator('[data-testid$="-error"]')
.filter({ hasText: regexPattern })
.all();
}
async inValidateForm(governanceProposal: ProposalCreateRequest) {
await this.fillupFormWithTypeSelected(governanceProposal);
await expect(this.page.getByTestId(formErrors.proposalTitle)).toBeVisible();

const proposalTitlePattern = generateRegexPattern(formErrors.proposalTitle);
const proposalTitleErrors = await getErrorsByPattern(
this.page,
proposalTitlePattern
await this.assertFieldValidation(
this.abstractInput,
formErrors.abstract,
governanceProposal.prop_abstract,
"valid abstract"
);

expectWithInfo(
async () => expect(proposalTitleErrors.length).toEqual(1),
`valid title: ${governanceProposal.prop_name}`
await this.assertFieldValidation(
this.motivationInput,
formErrors.motivation,
governanceProposal.prop_motivation,
"valid motivation"
);

if (governanceProposal.gov_action_type_id === 1) {
const receiverAddressErrors = await getErrorsByPattern(
this.page,
new RegExp(convertTestIdToText(formErrors.receivingAddress))
);

expectWithInfo(
async () => expect(receiverAddressErrors.length).toEqual(1),
`valid address: ${governanceProposal.prop_receiving_address}`
);

const amountPattern = generateRegexPattern(formErrors.amount);
const amountErrors = await getErrorsByPattern(this.page, amountPattern);

expectWithInfo(
async () => expect(amountErrors.length).toEqual(1),
`valid amount: ${governanceProposal.prop_amount}`
);
}

expectWithInfo(
async () =>
expect(await this.abstractInput.textContent()).not.toEqual(
governanceProposal.prop_abstract
),
`valid abstract: ${governanceProposal.prop_abstract}`
await this.assertFieldValidation(
this.rationaleInput,
formErrors.rationale,
governanceProposal.prop_rationale,
"valid rationale"
);

expectWithInfo(
async () =>
expect(await this.abstractInput.textContent()).not.toEqual(
governanceProposal.prop_motivation
),
`valid motivation: ${governanceProposal.prop_motivation}`
);
await expect(this.page.getByTestId(formErrors.link)).toBeVisible();

expectWithInfo(
async () =>
expect(await this.abstractInput.textContent()).not.toEqual(
governanceProposal.prop_rationale
),
`valid rationale: ${governanceProposal.prop_rationale}`
);
if (governanceProposal.gov_action_type_id === 1) {
await expect(
this.page.getByTestId(formErrors.receivingAddress)
).toBeVisible();

expectWithInfo(
async () =>
await expect(this.page.getByTestId(formErrors.link)).toBeVisible(),
`valid link: ${governanceProposal.proposal_links[0].prop_link}`
);
await expect(this.page.getByTestId(formErrors.amount)).toBeVisible();
}

await expect(this.continueBtn).toBeDisabled();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,16 @@ test("2N. Should show DRep information on details page", async ({
await expect(dRepPage.getByTestId("copy-drep-id-button")).toHaveText(
wallet.dRepId
);
await expect(dRepPage.getByText("Active", { exact: true })).toBeVisible();
await expect(dRepPage.locator("dl").getByText("₳ 0")).toBeVisible();
await expect(dRepPage.getByText(email, { exact: true })).toBeVisible();
await expect(dRepPage.getByTestId("Active-pill")).toHaveText("Active");
await expect(dRepPage.getByTestId("voting-power")).toHaveText("₳ 0");
await expect(
dRepPage.getByTestId(`${email.toLowerCase()}-link`)
).toBeVisible();

for (const link of links) {
await expect(dRepPage.getByText(link, { exact: true })).toBeVisible();
await expect(
dRepPage.getByTestId(`${link.toLowerCase()}-link`)
).toBeVisible();
}
await expect(dRepPage.getByText(bio, { exact: true })).toBeVisible();
});
Expand Down
Loading

0 comments on commit bd520c3

Please sign in to comment.