Skip to content

Commit 3c6404d

Browse files
committed
feat: add validation test for constitution proposal
1 parent 7636db4 commit 3c6404d

File tree

3 files changed

+51
-6
lines changed

3 files changed

+51
-6
lines changed

tests/govtool-frontend/playwright/lib/_mock/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ export const invalid = {
8080
return " ";
8181
},
8282

83+
constitutionUrl : () => {
84+
const choice = faker.number.int({ min: 1, max: 2 });
85+
if (choice === 1) {
86+
return invalid.url();
87+
}
88+
// empty invalid
89+
return " ";
90+
},
91+
8392
paragraph: (maxCharacter: number) => {
8493
const choice = faker.number.int({ min: 1, max: 2 });
8594
if (choice === 1) {

tests/govtool-frontend/playwright/lib/pages/proposalSubmissionPage.ts

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ const formErrors = {
2323
rationale: "rationale-helper-error",
2424
receivingAddress: "receiving-address-0-text-error",
2525
amount: "amount-0-text-error",
26+
constitutionalUrl: "prop=constitution-url-text-error", // BUG wrong test id
27+
guardrailsScriptUrl: "prop-guardrails-script-url-input-error",
2628
link: "link-0-url-input-error",
2729
};
2830

@@ -155,6 +157,10 @@ export default class ProposalSubmissionPage {
155157
if (governanceProposal.gov_action_type_id === 2) {
156158
await this.fillUpdateTheConstitutionFields(governanceProposal);
157159
}
160+
161+
if (governanceProposal.proposal_links != null) {
162+
await this.fillProposalLinks(governanceProposal.proposal_links);
163+
}
158164
}
159165

160166
async fillupForm(governanceProposal: ProposalCreateRequest) {
@@ -167,9 +173,7 @@ export default class ProposalSubmissionPage {
167173
} else {
168174
await this.updateTheConstitutionBtn.click();
169175
}
170-
if (governanceProposal.proposal_links != null) {
171-
await this.fillProposalLinks(governanceProposal.proposal_links);
172-
}
176+
173177
await this.fillupFormWithTypeSelected(governanceProposal);
174178
}
175179

@@ -194,8 +198,6 @@ export default class ProposalSubmissionPage {
194198
governanceProposal.prop_constitution_url
195199
);
196200

197-
await this.guardrailsScriptCheckbox.click();
198-
199201
await this.guardrailsScriptUrlInput.fill(
200202
governanceProposal.prop_guardrails_script_url
201203
);
@@ -278,6 +280,16 @@ export default class ProposalSubmissionPage {
278280
}
279281
}
280282

283+
if (governanceProposal.gov_action_type_id === 2) {
284+
await expect(
285+
this.page.getByTestId(formErrors.constitutionalUrl)
286+
).toBeHidden();
287+
288+
await expect(
289+
this.page.getByTestId(formErrors.guardrailsScriptUrl)
290+
).toBeHidden();
291+
}
292+
281293
await expect(this.page.getByTestId(formErrors.link)).toBeHidden();
282294

283295
await expect(this.continueBtn).toBeEnabled();
@@ -332,6 +344,16 @@ export default class ProposalSubmissionPage {
332344
await expect(this.page.getByTestId(formErrors.amount)).toBeVisible();
333345
}
334346

347+
if (governanceProposal.gov_action_type_id === 2) {
348+
await expect(
349+
this.page.getByTestId(formErrors.constitutionalUrl)
350+
).toBeVisible();
351+
352+
await expect(
353+
this.page.getByTestId(formErrors.guardrailsScriptUrl)
354+
).toBeVisible();
355+
}
356+
335357
await expect(this.continueBtn).toBeDisabled();
336358
}
337359

@@ -385,14 +407,20 @@ export default class ProposalSubmissionPage {
385407
prop_link_text: invalid.name(),
386408
},
387409
],
388-
gov_action_type_id: proposalType === ProposalType.info ? 0 : 1,
410+
gov_action_type_id: Object.values(ProposalType).indexOf(proposalType),
389411
is_draft: false,
390412
};
391413

392414
if (proposalType === ProposalType.treasury) {
393415
(proposal.prop_receiving_address = faker.location.streetAddress()),
394416
(proposal.prop_amount = invalid.amount());
395417
}
418+
419+
if (proposalType === ProposalType.updatesToTheConstitution) {
420+
proposal.prop_constitution_url = invalid.constitutionUrl();
421+
proposal.prop_guardrails_script_url = invalid.url();
422+
proposal.prop_guardrails_script_hash = faker.string.alphanumeric(64);
423+
}
396424
return proposal;
397425
}
398426

tests/govtool-frontend/playwright/tests/7-proposal-submission/proposalSubmission.loggedin.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ test.describe("Proposal created logged state", () => {
5454
await page.getByTestId(`${type.toLocaleLowerCase()}-button`).click();
5555
await proposalSubmissionPage.addLinkBtn.click();
5656

57+
if (type === ProposalType.updatesToTheConstitution) {
58+
await proposalSubmissionPage.guardrailsScriptCheckbox.click();
59+
}
60+
5761
for (let i = 0; i < 50; i++) {
5862
const rewardAddressBech32 = (
5963
await ShelleyWallet.generate()
@@ -106,6 +110,10 @@ test.describe("Proposal created logged state", () => {
106110
await page.getByTestId(`${type.toLocaleLowerCase()}-button`).click();
107111
await proposalSubmissionPage.addLinkBtn.click();
108112

113+
if (type === ProposalType.updatesToTheConstitution) {
114+
await proposalSubmissionPage.guardrailsScriptCheckbox.click();
115+
}
116+
109117
for (let i = 0; i < 50; i++) {
110118
const formFields: ProposalCreateRequest =
111119
proposalSubmissionPage.generateInValidProposalFormFields(type);

0 commit comments

Comments
 (0)