Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Megha-Dev-19 committed Oct 30, 2024
1 parent 75c402f commit 0e398d5
Show file tree
Hide file tree
Showing 4 changed files with 329 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ return (
type="button"
data-bs-toggle="dropdown"
aria-expanded="false"
data-testid="dropdown-btn"
>
{selected.label}
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ const { href } = VM.require("${REPL_DEVHUB}/widget/core.lib.url") || {
href: () => {},
};

if (typeof getRoleWiseData !== "function") {
return <></>;
}
const [selectedGroup, setSelectedGroup] = useState(null);
const [selectedVoteOption, setSelectedVoteOption] = useState(null);
const [selectedVoteValue, setSelectedVoteValue] = useState(null);
Expand Down Expand Up @@ -57,9 +60,9 @@ function getLastProposalId() {
}

useEffect(() => {
if (typeof getRoleWiseData === "function") {
getRoleWiseData(treasuryDaoID).then((resp) => setRolesData(resp));
}
getRoleWiseData(treasuryDaoID).then((resp) => {
setRolesData(resp);
});
}, [refreshData]);

useEffect(() => {
Expand Down Expand Up @@ -230,7 +233,7 @@ function updateDaoPolicy() {
weight_kind: "RoleWeight",
quorum: "0",
threshold: isPercentageSelected
? [selectedVoteValue, 100]
? [parseInt(selectedVoteValue), 100]
: selectedVoteValue,
};
return policy;
Expand Down Expand Up @@ -350,7 +353,7 @@ return (
instance,
heading: "Are you sure?",
content: (
<div>
<div className="d-flex flex-column gap-2">
This action will result in significant changes to the system.
<div className="d-flex gap-3 warning px-3 py-2 rounded-3">
<i class="bi bi-exclamation-triangle h5"></i>
Expand Down Expand Up @@ -400,7 +403,10 @@ return (
<div className="d-flex flex-column gap-1">
{Array.isArray(selectedGroup.members) &&
selectedGroup.members.map((member) => (
<div className="p-1 px-3">
<div
className="p-1 px-3 text-truncate"
style={{ width: "85%" }}
>
<Widget
src="mob.near/widget/Profile.ShortInlineBlock"
props={{ accountId: member, tooltip: true }}
Expand Down Expand Up @@ -438,9 +444,11 @@ return (
src={`${REPL_BASE_DEPLOYMENT_ACCOUNT}/widget/components.Input`}
props={{
className: "flex-grow-1 p-0",
key: `threshold-input`,
onChange: (e) => {
setSelectedVoteValue(e.target.value);
const number = parseInt(e.target.value);
const value = e.target.value.replace(/[^0-9]/g, "");
setSelectedVoteValue(value);
const number = parseInt(value);
setValueError(null);
if (isPercentageSelected) {
if (number > 100)
Expand Down
197 changes: 197 additions & 0 deletions playwright-tests/tests/members/create-threshold-request.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
import { expect } from "@playwright/test";
import { test } from "../../util/test.js";

import { getTransactionModalObject } from "../../util/transaction.js";
import {
getMockedPolicy,
mockRpcRequest,
updateDaoPolicyMembers,
} from "../../util/rpcmock.js";

const lastProposalId = 3;

const votePolicy = {
weight_kind: "RoleWeight",
quorum: "0",
threshold: [0, 100],
};

async function updateLastProposalId(page) {
await mockRpcRequest({
page,
filterParams: {
method_name: "get_last_proposal_id",
},
modifyOriginalResultFunction: (originalResult) => {
originalResult = lastProposalId;
return originalResult;
},
});
}

async function checkForVoteApproveTxn(page) {
const txnLocator = await page
.locator("div.modal-body code")
.nth(1)
.innerText();
const dataReceived = JSON.parse(txnLocator);
expect(dataReceived).toEqual({
id: lastProposalId,
action: "VoteApprove",
});
}

test.describe("without login", function () {
test.beforeEach(async ({ page, instanceAccount }) => {
await updateDaoPolicyMembers({ page });
await page.goto(`/${instanceAccount}/widget/app?page=settings`);
await page.getByText("Voting Thresholds").click({ timeout: 20_000 });
});

test("should show members of different roles", async ({ page }) => {
test.setTimeout(60_000);
await expect(page.getByText("Permission Groups")).toBeVisible({
timeout: 20_000,
});
await expect(page.getByText("Members 6")).toBeVisible();
await expect(page.getByText("Voting Policy")).toBeVisible();
await expect(
page.getByText(
"@2dada969f3743a4a41cfdb1a6e39581c2844ce8fbe25948700c85c598090b3e1",
{ exact: true }
)
).toBeVisible();
await page.getByText("Manage Members").click();
await expect(
page.getByText("@megha19.near", { exact: true })
).toBeVisible();
await page.getByText("Vote", { exact: true }).click();
await expect(page.getByText("@test04.near", { exact: true })).toBeVisible();
});

test("should disable input and hide submit button for non authorised people", async ({
page,
}) => {
test.setTimeout(60_000);
await expect(page.getByText("Permission Groups")).toBeVisible({
timeout: 20_000,
});
await expect(page.getByTestId("dropdown-btn")).toBeDisabled();
await expect(page.getByText("Submit")).toBeHidden();
await expect(page.getByTestId("threshold-input")).toBeDisabled();
});
});

async function fillInput(page, value) {
const submitBtn = page.getByText("Submit");
const thresholdInput = page.getByTestId("threshold-input");
await thresholdInput.type(value);
expect(submitBtn).toBeVisible();
}

test.describe("admin connected", function () {
test.use({
storageState: "playwright-tests/storage-states/wallet-connected-admin.json",
});

test.beforeEach(async ({ page, instanceAccount }) => {
await updateLastProposalId(page);
await updateDaoPolicyMembers({ page });
await page.goto(`/${instanceAccount}/widget/app?page=settings`);
await page.getByText("Voting Thresholds").click({ timeout: 20_000 });
await expect(page.getByText("Submit")).toBeVisible({
timeout: 20_000,
});
await page.getByTestId("dropdown-btn").click();
});

test("should allow only valid input for threshold", async ({ page }) => {
test.setTimeout(20_000);
await page.getByRole("list").getByText("Number of votes").click();
await fillInput(page, "20097292");
await fillInput(page, "10.323");
await fillInput(page, "werwr");
await fillInput(page, "$&$^&%&");
await page.getByTestId("dropdown-btn").click();
await page.getByRole("list").getByText("Percentage of members").click();
await fillInput(page, "3423");
await fillInput(page, "13.123");
await fillInput(page, "wqeqewq");
await fillInput(page, "$&$^&%&");
});

test("should be able to update policy by fixed vote count", async ({
page,
}) => {
test.setTimeout(60_000);
const submitBtn = page.getByText("Submit");
await page.getByRole("list").getByText("Number of votes").click();
const thresholdInput = page.getByTestId("threshold-input");
await thresholdInput.fill("20");
await expect(page.getByText("Maximum members allowed is ")).toBeVisible();
await expect(submitBtn).toBeDisabled();
await thresholdInput.fill("2");
await submitBtn.click();
await expect(
page.getByText(
"Changing this setting will require 2 vote(s) to approve requests. You will no longer be able to approve requests with 1 vote(s)."
)
).toBeVisible();
await page.getByRole("button", { name: "Confirm" }).click();
const updatedPolicy = {
weight_kind: "RoleWeight",
quorum: "0",
threshold: "2",
};

expect(await getTransactionModalObject(page)).toEqual({
proposal: {
description: "Update Policy",
kind: {
ChangePolicy: {
policy: getMockedPolicy(updatedPolicy, votePolicy, votePolicy),
},
},
},
});
await checkForVoteApproveTxn(page);
});

test("should be able to update policy by percentage", async ({ page }) => {
test.setTimeout(60_000);
const submitBtn = page.getByText("Submit");
await page.getByRole("list").getByText("Percentage of members").click();
const thresholdInput = page.getByTestId("threshold-input");
await thresholdInput.fill("101");
await expect(
page.getByText("Maximum percentage allowed is ")
).toBeVisible();
await expect(submitBtn).toBeDisabled();
await thresholdInput.fill("20");
await expect(page.getByText("Heads up, Bro!")).toBeVisible();
await submitBtn.click();
await expect(
page.getByText(
"Changing this setting will require 2 vote(s) to approve requests. You will no longer be able to approve requests with 1 vote(s)."
)
).toBeVisible();
await page.getByRole("button", { name: "Confirm" }).click();
const updatedPolicy = {
weight_kind: "RoleWeight",
quorum: "0",
threshold: [20, 100],
};

await expect(await getTransactionModalObject(page)).toEqual({
proposal: {
description: "Update Policy",
kind: {
ChangePolicy: {
policy: getMockedPolicy(updatedPolicy, votePolicy, votePolicy),
},
},
},
});
await checkForVoteApproveTxn(page);
});
});
Loading

0 comments on commit 0e398d5

Please sign in to comment.