Skip to content

Commit

Permalink
Should not add custom labels to proposal with linked RFPs (#947)
Browse files Browse the repository at this point in the history
* should not add custom labels to proposal with linked RFPs

* added tests for link and unlink RFP proposal
  • Loading branch information
Megha-Dev-19 authored Sep 30, 2024
1 parent 2db2a47 commit c9d5ea4
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ const draftKey = "INFRA_PROPOSAL_EDIT";

const rfpLabelOptions = getGlobalLabels();

const pageLoader = (
<div
style={{ height: "50vh" }}
className="d-flex justify-content-center align-items-center w-100"
>
<Widget src={`${REPL_DEVHUB}/widget/devhub.components.molecule.Spinner`} />
</div>
);

if (!rfpLabelOptions?.length) {
return pageLoader;
}

if (isEditPage) {
editProposalData = Near.view(
"${REPL_INFRASTRUCTURE_COMMITTEE_CONTRACT}",
Expand Down Expand Up @@ -786,7 +799,7 @@ const onSubmit = ({ isDraft, isCancel }) => {
};
const args = {
labels:
typeof linkedRfp === "number"
typeof linkedRfp === "number" || typeof linkedRfp?.value === "number"
? []
: (labels ?? []).map((i) => i.value ?? i),
body: body,
Expand All @@ -810,16 +823,7 @@ function cleanDraft() {
}

if (loading) {
return (
<div
style={{ height: "50vh" }}
className="d-flex justify-content-center align-items-center w-100"
>
<Widget
src={`${REPL_DEVHUB}/widget/devhub.components.molecule.Spinner`}
/>
</div>
);
return pageLoader;
}

const [collapseState, setCollapseState] = useState({});
Expand Down Expand Up @@ -865,7 +869,6 @@ const CategoryDropdown = useMemo(() => {
onChange: (v) => setLabels(v),
disabled: linkedRfp, // when RFP is linked, labels are disabled
linkedRfp: linkedRfp,

availableOptions: rfpLabelOptions,
}}
/>
Expand Down
117 changes: 75 additions & 42 deletions playwright-tests/tests/infrastructure/proposal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,38 +64,43 @@ test.describe("Wallet is connected as admin", () => {
});
});

test("should create proposal", async ({ page }) => {
async function createProposal(page, linkRfp = false) {
const description = "The proposal description. This proposal should win.";
const summary = "The excellent proposal summary";
const title = "The title";
const amount = "2000";
const token = "USDC";
await page.goto("/infrastructure-committee.near/widget/app?page=proposals");

await page
.getByRole("button", { name: " Submit Proposal" })
.click({ timeout: 10000 });
await page.getByText("Select Category").click();
await expect(await page.getByText("Indexers")).toBeVisible({
timeout: 10000,
timeout: 30_000,
});
await page.getByText("Indexers").click();

await pauseIfVideoRecording(page);
await page.getByText("Search RFP").click();
await page.getByText("# 0 : A Cool RFP").click();
await expect(
await page.getByRole("link", { name: "# 0 : A Cool RFP" })
).toBeVisible();

await expect(await page.getByText("Indexers")).not.toBeVisible();
await expect(page.locator(".badge").first()).toHaveText("Other");

await page.getByRole("textbox").first().fill("The title");
if (linkRfp) {
await page.getByText("Search RFP").click();
await page.getByText("# 0 : A Cool RFP").click();
await expect(
await page.getByRole("link", { name: "# 0 : A Cool RFP" })
).toBeVisible();

await expect(await page.getByText("Indexers")).not.toBeVisible();
await expect(page.locator(".badge").first()).toHaveText("Other");
} else {
}
await page.getByRole("textbox").first().fill(title);

await page
.locator('textarea[type="text"]')
.fill("The excellent proposal summary");
await page.locator('textarea[type="text"]').fill(summary);
await page
.frameLocator("iframe")
.locator(".CodeMirror textarea")
.pressSequentially("The proposal description. This proposal should win.");
.pressSequentially(description);

await page.getByRole("textbox").nth(3).fill("2000");
await page.getByRole("textbox").nth(3).fill(amount);
await page.getByRole("checkbox").first().click();
await page.getByText("Submit Draft").click();

Expand All @@ -104,34 +109,62 @@ test.describe("Wallet is connected as admin", () => {
null,
1
);
await expect(transactionText).toEqual(
JSON.stringify(
{
labels: ["Other"],
body: {
proposal_body_version: "V1",
linked_rfp: 0,
category: "Infrastructure Committee",
name: "The title",
description: "The proposal description. This proposal should win.",
summary: "The excellent proposal summary",
linked_proposals: [],
requested_sponsorship_usd_amount: "2000",
requested_sponsorship_paid_in_currency: "USDC",
receiver_account: "theori.near",
requested_sponsor: "infrastructure-committee.near",
supervisor: null,
timeline: {
status: "DRAFT",
},

let data = {};
if (linkRfp) {
data = {
labels: [],
body: {
proposal_body_version: "V1",
linked_rfp: 0,
category: "Infrastructure Committee",
name: title,
description: description,
summary: summary,
linked_proposals: [],
requested_sponsorship_usd_amount: amount,
requested_sponsorship_paid_in_currency: token,
receiver_account: "theori.near",
requested_sponsor: "infrastructure-committee.near",
supervisor: null,
timeline: {
status: "DRAFT",
},
},
null,
1
)
);
};
} else {
data = {
labels: ["Indexers"],
body: {
proposal_body_version: "V1",
category: "Infrastructure Committee",
name: title,
description: description,
summary: summary,
linked_proposals: [],
requested_sponsorship_usd_amount: amount,
requested_sponsorship_paid_in_currency: token,
receiver_account: "theori.near",
requested_sponsor: "infrastructure-committee.near",
supervisor: null,
timeline: {
status: "DRAFT",
},
},
};
}

await expect(transactionText).toEqual(JSON.stringify(data, null, 1));

await pauseIfVideoRecording(page);
}

test("should create proposal and link an RFP", async ({ page }) => {
await createProposal(page, true);
});

test("should create a proposal without linking an RFP", async ({ page }) => {
await createProposal(page, false);
});

test("should show relevant users in mention autocomplete", async ({
Expand Down

0 comments on commit c9d5ea4

Please sign in to comment.