Skip to content

Commit

Permalink
Merge pull request #1393 from IntersectMBO/fix/pdf-missing-testids
Browse files Browse the repository at this point in the history
Fix/pdf missing testids
  • Loading branch information
kneerose authored Jul 11, 2024
2 parents 0d32c61 + ec5cc28 commit 54b3286
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 190 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,41 @@ import { CommentResponse } from "@types";

export default class ProposalDiscussionDetailsPage {
// Buttons
readonly likeBtn = this.page.getByRole("button", {
name: "proposal likes",
});
readonly dislikeBtn = this.page.getByRole("button", {
name: "proposal dislikes",
});
readonly likeBtn = this.page.getByTestId("like-button");
readonly dislikeBtn = this.page.getByTestId("dislike-button");
readonly commentBtn = this.page.getByTestId("comment-button");
readonly addPollBtn = this.page.getByRole("button", { name: "Add Poll" }); // BUG missing test id
readonly replyCommentBtn = this.page.getByTestId("reply-comment-button");
readonly addPollBtn = this.page.getByTestId("add-poll-button");
readonly SubmitBtn = this.page.getByTestId("submit-button");
readonly menuBtn = this.page.getByTestId("menu-button");
readonly editProposalBtn = this.page.getByTestId("edit-proposal");
readonly deleteProposalBtn = this.page.getByTestId("delete-proposal");
readonly reviewVersionsBtn = this.page.getByTestId("review-versions");
readonly closePollBtn = this.page.getByRole("button", { name: "Close Poll" }); // BUG missing test id
readonly sortBtn = this.page
.locator("div")
.filter({ hasText: /^Comments$/ })
.getByRole("button"); // this.page.getByTestId("sort-button");
readonly closePollBtn = this.page.getByTestId("close-poll-button");
readonly sortBtn = this.page.getByTestId("sort-comments");
readonly proposeGovernanceAction = this.page.getByTestId("propose-GA-button");
readonly replyBtn = this.page.getByTestId("reply-button");
readonly pollYesBtn = this.page.getByRole("button", { name: "Yes" }); //BUG missing test id
readonly pollNoBtn = this.page.getByRole("button", { name: "No" }); //BUG missing test id
readonly pollYesBtn = this.page.getByTestId("poll-yes-button");
readonly pollNoBtn = this.page.getByTestId("poll-no-button");
readonly showReplyBtn = this.page.getByTestId("show-more-reply");
readonly closePollYesBtn = this.page.getByTestId("close-the-poll-button");
readonly changeVoteBtn = this.page.getByRole("button", {
name: "Change Vote",
});
readonly changeVoteBtn = this.page.getByTestId("change-vote-button");
readonly verifyIdentityBtn = this.page.getByRole("button", {
name: "Verify your identity",
});
}); // BUG
readonly submitAsGABtn = this.page.getByTestId("submit-as-GA-button");

// Indicators
readonly likesCounts = this.page.getByTestId("likes-count");
readonly dislikesCounts = this.page.getByTestId("dislikse-count");
readonly likeCount = this.likeBtn.getByTestId("like-count");
readonly dislikeCount = this.dislikeBtn.getByTestId("dislike-count");
readonly commentCount = this.page.getByTestId("comment-count");

// Cards
readonly pollVoteCard = this.page.getByTestId("poll-vote-card");
readonly pollResultCard = this.page.getByTestId("poll-result-card");
readonly commentCard =
this.proposeGovernanceAction.getByTestId("comment-card");

//inputs
readonly commentInput = this.page.getByRole("textbox");
readonly commentInput = this.page.getByTestId("comment-input");

constructor(private readonly page: Page) {}

Expand All @@ -68,13 +58,13 @@ export default class ProposalDiscussionDetailsPage {

async addComment(comment: string) {
await this.commentInput.fill(comment);
await this.page.getByTestId("comment-button").click();
await this.commentBtn.click();
}

async replyComment(reply: string) {
await this.page.getByRole("button", { name: "Reply" }).click();
await this.page.getByPlaceholder("Add comment").fill(reply);
await this.page.getByTestId("reply-comment-button").click();
await this.replyBtn.click();
await this.page.getByTestId("reply-input").fill(reply);
await this.replyCommentBtn.click();
}

async sortAndValidate(
Expand All @@ -101,13 +91,13 @@ export default class ProposalDiscussionDetailsPage {
}

async voteOnPoll(vote: string) {
await this.page.getByRole("button", { name: `${vote}` }).click();
await this.page.getByTestId(`poll-${vote.toLowerCase()}-button`).click();
}

async deleteProposal() {
await this.page.waitForTimeout(2_000);

await this.page.locator("#menu-button").click();
await this.page.getByTestId("menu-button").click();
await this.page.getByTestId("delete-proposal").click();
await this.page.getByTestId("delete-proposal-yes-button").click();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,20 @@ import ProposalDiscussionDetailsPage from "./proposalDiscussionDetailsPage";

export default class ProposalDiscussionPage {
// Buttons
readonly proposalCreateBtn = this.page.getByRole("button", {
name: "Propose a Governance Action",
});
readonly continueBtn = this.page.getByRole("button", { name: "Continue" }); // #BUG test-id missing
readonly filterBtn = this.page.locator("#filters-button"); // this.page.getByTestId("filters-button");
readonly shareBtn = this.page
.locator(".MuiCardHeader-action > .MuiButtonBase-root")
.first(); //this.page.getByTestId("share-button");
readonly sortBtn = this.page.locator("button:nth-child(2)").first(); //this.page.getByTestId("sort-button");
readonly searchInput = this.page.getByPlaceholder("Search..."); // this.page.getByTestId("search-input");
readonly showAllBtn = this.page
.getByRole("button", { name: "Show all" })
.first(); //this.page.getByTestId("show-all-button");
readonly showLessBtn = this.page.getByRole("button", { name: "Show less" });
readonly infoRadio = this.page.getByLabel("Info");
readonly treasuryRadio = this.page.getByLabel("Treasury");
readonly proposalCreateBtn = this.page.getByTestId(
"propose-a-governance-action-button"
);
readonly continueBtn = this.page.getByTestId("continue-button");
readonly filterBtn = this.page.getByTestId("filter-button");
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",
});
readonly addLinkBtn = this.page.getByRole("button", { name: "Add link" });
}); // BUG
readonly addLinkBtn = this.page.getByTestId("add-link-button");
readonly infoRadio = this.page.getByTestId("Info-radio-wrapper");
readonly treasuryRadio = this.page.getByTestId("Treasury-radio-wrapper");

constructor(private readonly page: Page) {}

Expand All @@ -37,6 +31,7 @@ export default class ProposalDiscussionPage {
}

async closeUsernamePrompt() {
await this.page.waitForTimeout(5_000);
await this.page
.locator("div")
.filter({ hasText: /^Hey, setup your username$/ })
Expand All @@ -54,35 +49,20 @@ export default class ProposalDiscussionPage {

async getAllProposals() {
await this.page.waitForTimeout(4_000); // waits for proposals to render
// BUG Select all elements with data-testid attribute
const elements = await this.page.$$("[data-testid]");

// Regex pattern to match IDs starting with "proposal" and ending with numbers
const pattern = /^proposal-\d+$/;

// Extract the data-testid attributes
const proposalCards: Locator[] = [];
for (const element of elements) {
const dataTestId = await element.getAttribute("data-testid");
if (pattern.test(dataTestId)) {
proposalCards.push(this.page.getByTestId(dataTestId));
}
}

return proposalCards;
// BUG return this.page.locator('[data-testid$="-card"]').all();
return this.page
.locator('[data-testid^="proposal-"][data-testid$="-card"]')
.all();
}

async setUsername(name: string) {
await this.page.getByLabel("Username *").fill(name);
await this.page.getByTestId("username-input").fill(name);

const proceedBtn = this.page.getByRole("button", {
name: "Proceed with this username",
});
const proceedBtn = this.page.getByTestId("proceed-button");
await proceedBtn.click();
await proceedBtn.click();

await this.page.getByRole("button", { name: "Close" }).click();
await this.page.getByTestId("close-button").click();
}

async createProposal(): Promise<number> {
Expand All @@ -109,7 +89,7 @@ export default class ProposalDiscussionPage {
await this.fillForm(proposalRequest);

await this.continueBtn.click();
await this.page.getByRole("button", { name: "Submit" }).click();
await this.page.getByTestId("submit-button").click();

// Wait for redirection to `proposal-discussion-details` page
await this.page.waitForTimeout(2_000);
Expand All @@ -119,32 +99,34 @@ export default class ProposalDiscussionPage {
}

private async fillForm(data: ProposalCreateRequest) {
await this.page.getByLabel("Governance Action Type *").click();
await this.page.getByRole("option", { name: "Info" }).click();
await this.page.getByLabel("Title *").fill(data.prop_name);
await this.page.getByPlaceholder("Summary...").fill(data.prop_abstract);
await this.page.getByLabel("Motivation *").fill(data.prop_motivation);
await this.page.getByLabel("Rationale *").fill(data.prop_rationale);

for (const link of data.proposal_links) {
await this.page.getByTestId("governance-action-type").click();
await this.page.getByTestId("info-button").click();
await this.page.getByTestId("title-input").fill(data.prop_name);
await this.page.getByTestId("abstract-input").fill(data.prop_abstract);
await this.page.getByTestId("motivation-input").fill(data.prop_motivation);
await this.page.getByTestId("rationale-input").fill(data.prop_rationale);

for (let index = 0; index < data.proposal_links.length; index++) {
await this.addLinkBtn.click();

await this.page
.getByPlaceholder("https://website.com")
.fill(link.prop_link);
await this.page.getByPlaceholder("Text").fill(link.prop_link_text);
.getByTestId(`link-${index}-url-input`)
.fill(data.proposal_links[index].prop_link);
await this.page
.getByTestId(`link-${index}-text-input`)
.fill(data.proposal_links[index].prop_link_text);
}
}

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,41 +28,41 @@ export default class ProposalSubmissionPage {
);

// buttons
readonly proposalCreateBtn = this.page.getByRole("button", {
name: "Propose a Governance Action",
});
readonly proposalCreateBtn = this.page.getByTestId(
"propose-a-governance-action-button"
);
readonly registerBtn = this.page.getByTestId("register-button");
readonly skipBtn = this.page.getByTestId("skip-button");
readonly confirmBtn = this.page.getByTestId("confirm-modal-button");

readonly continueBtn = this.page.getByRole("button", { name: "Continue" }); //BUG testid = continue-button
readonly addLinkBtn = this.page.getByRole("button", { name: "Add link" }); // BUG testid= add-link-button
readonly infoBtn = this.page.getByRole("option", { name: "Info" }); // BUG missing test id
readonly treasuryBtn = this.page.getByRole("option", { name: "Treasury" }); // BUG missing test id
readonly continueBtn = this.page.getByTestId("continue-button");
readonly addLinkBtn = this.page.getByTestId("add-link-button");
readonly infoBtn = this.page.getByTestId("info-button");
readonly treasuryBtn = this.page.getByTestId("treasury-button");
readonly editSubmissionButton = this.page.getByTestId(
"edit-submission-button"
);
readonly verifyIdentityBtn = this.page.getByRole("button", {
name: "Verify your identity",
});
}); // BUG missing test id
readonly governanceActionType = this.page.getByLabel(
"Governance Action Type *"
); // BUG missing test id
);
readonly saveDraftBtn = this.page.getByTestId("save-draft-button");
readonly submitBtn = this.page.getByRole("button", { name: "Submit" }); // BUG missing test id
readonly createNewProposalBtn = this.page.getByRole("button", {
name: "Create new Proposal",
});
readonly submitBtn = this.page.getByTestId("submit-button");
readonly createNewProposalBtn = this.page.getByTestId(
"create-new-proposal-button"
);

// input fields
readonly titleInput = this.page.getByLabel("Title *"); // BUG testid = title-input
readonly abstractInput = this.page.getByLabel("Abstract *"); // BUG testid = abstract-input
readonly metadataUrlInput = this.page.getByPlaceholder("URL"); // BUG missing test id
readonly motivationInput = this.page.getByLabel("Motivation *"); // BUG testid = motivation-input
readonly rationaleInput = this.page.getByLabel("Rationale *"); // BUG testid = rationale-input
readonly linkInput = this.page.getByLabel("Link #1 URL"); // BUG testid = link-input
readonly linkText = this.page.getByLabel("Link #1 Text"); // BUG missing testid
readonly receivingAddressInput = this.page.getByLabel("Receiving address *"); // BUG missing testid
readonly titleInput = this.page.getByTestId("title-input");
readonly abstractInput = this.page.getByTestId("abstract-input");
readonly metadataUrlInput = this.page.getByTestId("url-input");
readonly motivationInput = this.page.getByTestId("motivation-input");
readonly rationaleInput = this.page.getByTestId("rationale-input");
readonly receivingAddressInput = this.page.getByTestId(
"receiving-address-input"
);
readonly amountInput = this.page.getByTestId("amount-input");
readonly closeDraftSuccessModalBtn = this.page.getByTestId(
"delete-proposal-yes-button"
Expand All @@ -82,11 +82,7 @@ export default class ProposalSubmissionPage {
}

async fillUpValidMetadata() {
this.page
.getByRole("button", {
name: "data.jsonld",
})
.click(); // BUG test id = metadata-download-button
this.page.getByTestId("download-button").click();

const dRepMetadata = await this.downloadVoteMetadata();
const url = await metadataBucketService.uploadMetadata(
Expand Down Expand Up @@ -144,8 +140,12 @@ export default class ProposalSubmissionPage {
if (i > 0) {
await this.addLinkBtn.click();
}
await this.linkInput.fill(proposal_links[i].prop_link);
await this.linkText.fill(proposal_links[i].prop_link_text);
await this.page
.getByTestId(`link-${i}-url-input`)
.fill(proposal_links[i].prop_link);
await this.page
.getByTestId(`link-${i}-text-input`)
.fill(proposal_links[i].prop_link_text);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ test.describe("Logged in user", () => {
await page.goto("/");
await page.getByTestId("proposal-discussion-link").click();
await page.getByRole("button", { name: "Verify your identity" }).click(); // BUG: Test id missing
await expect(page.getByText("Hey, setup your usernameBy")).toBeVisible(); //BUG Add modal testid instead should be username-modal

await expect(page.getByLabel("Username *")).toBeVisible(); // BUG use testid instead
await expect(page.getByTestId("setup-username-modal")).toBeVisible();
await expect(page.getByTestId("username-input")).toBeVisible();
});
});

Expand Down Expand Up @@ -143,11 +143,11 @@ test.describe("Temporary user", () => {
test("6K. Should accept valid username.", async () => {
for (let i = 0; i < 100; i++) {
await userPage
.getByLabel("Username *")
.getByTestId("username-input")
.fill(mockValid.username().toLowerCase());

await expect(
userPage.getByText("Invalid username. Only lower")
userPage.getByTestId("username-error-text")
).not.toBeVisible();
await expect(userPage.getByTestId("proceed-button")).toBeEnabled();
}
Expand All @@ -156,12 +156,10 @@ test.describe("Temporary user", () => {
test("6L. Should reject invalid username.", async () => {
for (let i = 0; i < 100; i++) {
await userPage
.getByLabel("Username *")
.getByTestId("username-input")
.fill(mockInvalid.username().toLowerCase());

await expect(
userPage.getByText("Invalid username. Only lower")
).toBeVisible();
await expect(userPage.getByTestId("username-error-text")).toBeVisible();
await expect(userPage.getByTestId("proceed-button")).toBeDisabled();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ test("7H. Should submit a proposal as governance action", async ({

await userPage.getByTestId("submit-as-GA-button").click();

await userPage.click("input#submission-checkbox"); // BUG missing test id
await userPage.getByTestId("agree-checkbox").click();
proposalSubmissionPage.continueBtn.click();

await proposalSubmissionPage.fillUpValidMetadata();
Expand Down
Loading

0 comments on commit 54b3286

Please sign in to comment.