Skip to content

Commit

Permalink
Merge pull request #1992 from IntersectMBO/bugfix/proposal-character-…
Browse files Browse the repository at this point in the history
…validation

Bugfix/proposal-character-validation
  • Loading branch information
kneerose authored Sep 18, 2024
2 parents adf6289 + c826179 commit 70b9719
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
6 changes: 3 additions & 3 deletions tests/govtool-frontend/playwright/lib/_mock/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { faker } from "@faker-js/faker";
import { generateExactLengthText } from "@helpers/string";

export const invalid = {
url: () => {
Expand Down Expand Up @@ -74,11 +75,10 @@ export const invalid = {
return " ";
},

paragraph: () => {
paragraph: (maxCharacter: number) => {
const choice = faker.number.int({ min: 1, max: 2 });
if (choice === 1) {
// maximum 500 words
return faker.lorem.paragraphs(40);
return generateExactLengthText(maxCharacter);
}
// empty invalid
return " ";
Expand Down
14 changes: 14 additions & 0 deletions tests/govtool-frontend/playwright/lib/helpers/string.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
import { faker } from "@faker-js/faker";

export function extractProposalIdFromUrl(url: string) {
return parseInt(url.split("/").pop());
}

export function generateExactLengthText(characterLength:number) {
let text = '';

// Keep generating paragraphs until we exceed the required length
while (text.length < characterLength) {
text += faker.lorem.paragraphs(10);
}

// Truncate to the exact number of characters needed
return text.substring(0, characterLength);
}
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,9 @@ export default class ProposalSubmissionPage {
generateInValidProposalFormFields(proposalType: ProposalType) {
const proposal: ProposalCreateRequest = {
prop_name: invalid.proposalTitle(),
prop_abstract: invalid.paragraph(),
prop_motivation: invalid.paragraph(),
prop_rationale: invalid.paragraph(),
prop_abstract: invalid.paragraph(2510),
prop_motivation: invalid.paragraph(12020),
prop_rationale: invalid.paragraph(12020),

proposal_links: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ test.describe("Proposal created logged state", () => {
}) => {
await skipIfTreasuryAndBootstrapping(type);

test.slow(); // Brute-force testing with 100 random data
test.slow(); // Brute-force testing with 50 random data

const proposalSubmissionPage = new ProposalSubmissionPage(page);

Expand Down Expand Up @@ -79,7 +79,7 @@ test.describe("Proposal created logged state", () => {
}) => {
await skipIfTreasuryAndBootstrapping(type);

test.slow(); // Brute-force testing with 100 random data
test.slow(); // Brute-force testing with 50 random data

const proposalSubmissionPage = new ProposalSubmissionPage(page);
await proposalSubmissionPage.goto();
Expand Down

0 comments on commit 70b9719

Please sign in to comment.