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 Jan 3, 2025
1 parent da3aa90 commit dbd2e4d
Show file tree
Hide file tree
Showing 13 changed files with 341 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function BalanceBanner({ accountId, treasuryDaoID }) {
<i class="bi bi-exclamation-octagon error-icon h4 mb-0"></i>
<div>
<h5>Insufficient Funds</h5>
Hey {name}, your don't have enough NEAR to complete actions on your
Hey {name}, you don't have enough NEAR to complete actions on your
treasury. You need at least {INSUFFICIENT_BALANCE_LIMIT}N. Please
add more funds to your account and try again
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const WarningModal = () => (
</div>
</ModalHeader>
<ModalContent>
Hey {name}, your don't have enough NEAR to complete actions on your
Hey {name}, you don't have enough NEAR to complete actions on your
treasury. You need at least {INSUFFICIENT_BALANCE_LIMIT}. Please add more
funds to your account and try again.
</ModalContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ return (
src={`${REPL_DEVHUB}/widget/devhub.components.molecule.Button`}
props={{
classNames: { root: "theme-btn" },
label: "Save changes",
label: "Submit Request",
loading: isTxnCreated,
disabled: !hasCreatePermission || error || isTxnCreated,
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ return (
valueError ||
!hasCreatePermission ||
isTxnCreated,
label: "Submit",
label: "Submit Request",
loading: isTxnCreated,
}}
/>
Expand Down
69 changes: 67 additions & 2 deletions playwright-tests/tests/payments/create-payment-request.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
getTransactionModalObject,
mockTransactionSubmitRPCResponses,
} from "../../util/transaction";
import { updateDaoPolicyMembers } from "../../util/rpcmock";
import { mockNearBalances, updateDaoPolicyMembers } from "../../util/rpcmock";
import { getInstanceConfig } from "../../util/config.js";
import {
CurrentTimestampInNanoseconds,
Expand All @@ -18,6 +18,7 @@ import {
focusInputClearAndBlur,
focusInputReplaceAndBlur,
} from "../../util/forms.js";
import { InsufficientBalance } from "../../util/lib.js";

async function clickCreatePaymentRequestButton(page) {
const createPaymentRequestButton = await page.getByRole("button", {
Expand Down Expand Up @@ -120,14 +121,78 @@ test.afterEach(async ({ page }, testInfo) => {
await page.unrouteAll({ behavior: "ignoreErrors" });
});

test.describe("admin connected", function () {
test.describe("User is not logged in", function () {
test("should not see 'Create Request' action", async ({
page,
instanceAccount,
}) => {
await page.goto(`/${instanceAccount}/widget/app?page=payments`);
await expect(page.getByText("Pending Requests")).toBeVisible();
await expect(
page.getByRole("button", {
name: "Create Request",
})
).toBeHidden();
});
});

test.describe("User is logged in", function () {
const signedUser = "theori.near";
test.use({
contextOptions: {
permissions: ["clipboard-read", "clipboard-write"],
},
storageState: "playwright-tests/storage-states/wallet-connected-admin.json",
});

test("low account balance should show warning modal, and allow action ", async ({
page,
instanceAccount,
}) => {
test.setTimeout(60_000);
await mockNearBalances({
page,
accountId: signedUser,
balance: BigInt(0.6 * 10 ** 24).toString(),
storage: 8,
});
await page.goto(`/${instanceAccount}/widget/app?page=payments`);
await expect(
page.getByText(
"Please add more NEAR to your account soon to avoid any issues completing actions on your treasury"
)
).toBeVisible();
});

test("insufficient account balance should show warning modal, disallow action ", async ({
page,
instanceAccount,
}) => {
test.setTimeout(60_000);
await mockNearBalances({
page,
accountId: signedUser,
balance: InsufficientBalance,
storage: 8,
});
await page.goto(`/${instanceAccount}/widget/app?page=payments`);
await expect(
page.getByText(
"Hey Ori, you don't have enough NEAR to complete actions on your treasury."
)
).toBeVisible();
await page
.getByRole("button", {
name: "Create Request",
})
.click();
await expect(
page
.getByText("Please add more funds to your account and try again")
.nth(1)
).toBeVisible();
});

test("different amount values should not throw any error", async ({
page,
instanceAccount,
Expand Down
43 changes: 41 additions & 2 deletions playwright-tests/tests/payments/vote-on-request.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ import { expect } from "@playwright/test";
import { test } from "../../util/test.js";

import { mockTransactionSubmitRPCResponses } from "../../util/transaction";
import { mockRpcRequest, updateDaoPolicyMembers } from "../../util/rpcmock";
import {
mockNearBalances,
mockRpcRequest,
updateDaoPolicyMembers,
} from "../../util/rpcmock";
import { setDontAskAgainCacheValues } from "../../util/cache";
import { mockPikespeakFTTokensResponse } from "../../util/pikespeak.js";
import {
CurrentTimestampInNanoseconds,
TransferProposalData,
} from "../../util/inventory.js";
import { InsufficientBalance } from "../../util/lib.js";

async function mockWithFTBalance({ page, daoAccount, isSufficient }) {
await page.route(
Expand Down Expand Up @@ -153,7 +158,41 @@ test.describe("don't ask again", function () {
storageState:
"playwright-tests/storage-states/wallet-connected-admin-with-accesskey.json",
});
test("should throw insufficient balance error", async ({

test("should throw insufficient signed in account balance error", async ({
page,
instanceAccount,
daoAccount,
}) => {
test.setTimeout(60_000);
await updateDaoPolicyMembers({ page });
await mockNearBalances({
page,
accountId: "theori.near",
balance: InsufficientBalance,
storage: 8,
});
await voteOnProposal({
page,
daoAccount,
instanceAccount,
voteStatus: "Approved",
vote: "Approve",
});
const approveButton = page
.getByRole("button", {
name: "Approve",
})
.first();
await expect(approveButton).toBeEnabled({ timeout: 30_000 });
await approveButton.click();
await expect(
page
.getByText("Please add more funds to your account and try again")
.nth(1)
).toBeVisible();
});
test("should throw insufficient dao account balance error", async ({
page,
instanceAccount,
daoAccount,
Expand Down
39 changes: 32 additions & 7 deletions playwright-tests/tests/settings/create-member-request.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import {
getTransactionModalObject,
mockTransactionSubmitRPCResponses,
} from "../../util/transaction.js";
import { mockRpcRequest, updateDaoPolicyMembers } from "../../util/rpcmock.js";
import {
mockNearBalances,
mockRpcRequest,
updateDaoPolicyMembers,
} from "../../util/rpcmock.js";
import { mockInventory } from "../../util/inventory.js";
import { encodeToMarkdown } from "../../util/lib.js";
import { InsufficientBalance, encodeToMarkdown } from "../../util/lib.js";

const lastProposalId = 3;

Expand All @@ -32,7 +36,7 @@ async function updateLastProposalId(page) {

async function navigateToMembersPage({ page, instanceAccount }) {
await page.goto(`/${instanceAccount}/widget/app?page=settings`);
await page.waitForTimeout(2_000);
await page.waitForTimeout(5_000);
await page.getByText("Members").click();
await expect(page.getByText("All Members")).toBeVisible({ timeout: 10_000 });
}
Expand Down Expand Up @@ -74,18 +78,39 @@ test.describe("User is logged in", function () {
storageState: "playwright-tests/storage-states/wallet-connected-admin.json",
});

test.beforeEach(async ({ page, daoAccount, instanceAccount }) => {
test.beforeEach(async ({ page, daoAccount, instanceAccount }, testInfo) => {
await mockInventory({ page, account: daoAccount });
await updateDaoPolicyMembers({ page });
await updateLastProposalId(page);
if (testInfo.title.includes("insufficient account balance")) {
await mockNearBalances({
page,
accountId: "theori.near",
balance: InsufficientBalance,
storage: 8,
});
}
await navigateToMembersPage({ page, instanceAccount });
});

test("should show members of the DAO", async ({
test("insufficient account balance should show warning modal, disallow action ", async ({
page,
instanceAccount,
daoAccount,
}) => {
test.setTimeout(60_000);
await expect(
page.getByText(
"Hey Ori, you don't have enough NEAR to complete actions on your treasury."
)
).toBeVisible();
await page.getByRole("button", { name: " New Member" }).click();
await expect(
page
.getByText("Please add more funds to your account and try again")
.nth(1)
).toBeVisible();
});

test("should show members of the DAO", async ({ page }) => {
test.setTimeout(60_000);
await expect(page.getByText("Megha", { exact: true })).toBeVisible();
});
Expand Down
66 changes: 52 additions & 14 deletions playwright-tests/tests/settings/create-threshold-request.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { test } from "../../util/test.js";
import { getTransactionModalObject } from "../../util/transaction.js";
import {
getMockedPolicy,
mockNearBalances,
mockRpcRequest,
updateDaoPolicyMembers,
} from "../../util/rpcmock.js";
import { encodeToMarkdown } from "../../util/lib.js";
import { InsufficientBalance, encodeToMarkdown } from "../../util/lib.js";

const lastProposalId = 3;

Expand Down Expand Up @@ -51,11 +52,19 @@ test.afterEach(async ({ page }, testInfo) => {
await page.unrouteAll({ behavior: "ignoreErrors" });
});

async function navigateToThresholdPage({ page, instanceAccount }) {
await page.goto(`/${instanceAccount}/widget/app?page=settings`);
await page.waitForTimeout(5_000);
await page.getByText("Voting Threshold").click();
await expect(page.getByText("Permission Groups")).toBeVisible({
timeout: 10_000,
});
}

test.describe("User is not logged in", 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 });
await navigateToThresholdPage({ page, instanceAccount });
});

test("should show members of different roles", async ({ page }) => {
Expand Down Expand Up @@ -87,13 +96,13 @@ test.describe("User is not logged in", function () {
timeout: 20_000,
});
await expect(page.getByTestId("dropdown-btn")).toBeDisabled();
await expect(page.getByText("Submit")).toBeHidden();
await expect(page.getByText("Submit Request")).toBeHidden();
await expect(page.getByTestId("threshold-input")).toBeDisabled();
});
});

async function fillInput(page, value) {
const submitBtn = page.getByText("Submit");
const submitBtn = page.getByText("Submit Request");
const thresholdInput = page.getByTestId("threshold-input");
await thresholdInput.type(value);
expect(submitBtn).toBeVisible();
Expand All @@ -104,19 +113,46 @@ test.describe("User is logged in", function () {
storageState: "playwright-tests/storage-states/wallet-connected-admin.json",
});

test.beforeEach(async ({ page, instanceAccount }) => {
test.beforeEach(async ({ page, instanceAccount }, testInfo) => {
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();
if (testInfo.title.includes("insufficient account balance")) {
await mockNearBalances({
page,
accountId: "theori.near",
balance: InsufficientBalance,
storage: 8,
});
}
await navigateToThresholdPage({ page, instanceAccount });
});

test("insufficient account balance should show warning modal, disallow action ", async ({
page,
}) => {
test.setTimeout(60_000);

await expect(
page.getByText(
"Hey Ori, you don't have enough NEAR to complete actions on your treasury."
)
).toBeVisible();
await page.getByTestId("threshold-input").fill("1");
await page
.getByText("Submit Request", {
exact: true,
})
.click();
await expect(
page
.getByText("Please add more funds to your account and try again")
.nth(1)
).toBeVisible();
});

test("should allow only valid input for threshold", async ({ page }) => {
test.setTimeout(60_000);
await page.getByTestId("dropdown-btn").click();
await page.getByRole("list").getByText("Number of votes").click();
await fillInput(page, "20097292");
await fillInput(page, "10.323");
Expand All @@ -134,7 +170,8 @@ test.describe("User is logged in", function () {
page,
}) => {
test.setTimeout(150_000);
const submitBtn = page.getByText("Submit");
const submitBtn = page.getByText("Submit Request");
await page.getByTestId("dropdown-btn").click();
await page.getByRole("list").getByText("Number of votes").click();
const thresholdInput = page.getByTestId("threshold-input");
await thresholdInput.fill("20");
Expand Down Expand Up @@ -172,7 +209,8 @@ test.describe("User is logged in", function () {

test("should be able to update policy by percentage", async ({ page }) => {
test.setTimeout(150_000);
const submitBtn = page.getByText("Submit");
const submitBtn = page.getByText("Submit Request");
await page.getByTestId("dropdown-btn").click();
await page.getByRole("list").getByText("Percentage of members").click();
const thresholdInput = page.getByTestId("threshold-input");
await thresholdInput.fill("101");
Expand Down
Loading

0 comments on commit dbd2e4d

Please sign in to comment.