Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dskloetd committed Feb 12, 2024
1 parent f0a98eb commit ee00305
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import { mockSnsToken, principal } from "$tests/mocks/sns-projects.mock";
import { DisburseMaturityModalPo } from "$tests/page-objects/DisburseMaturityModal.page-object";
import { JestPageObjectElement } from "$tests/page-objects/jest.page-object";
import { resetSnsProjects, setSnsProjects } from "$tests/utils/sns.test-utils";
import { decodeIcrcAccount } from "@dfinity/ledger-icrc";
import type { SnsNeuron } from "@dfinity/sns";
import { nonNullish } from "@dfinity/utils";
Expand Down Expand Up @@ -41,11 +42,15 @@ describe("SnsDisburseMaturityModal", () => {

beforeEach(() => {
vi.clearAllMocks();
resetSnsProjects();

authStore.setForTesting(mockIdentity);
tokensStore.setToken({
canisterId: rootCanisterId,
token: mockSnsToken,
});
setSnsProjects([
{
rootCanisterId,
tokenMetadata: mockSnsToken,
},
]);
snsAccountsStore.setAccounts({
rootCanisterId,
accounts: [mockSnsMainAccount],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { AppPath } from "$lib/constants/routes.constants";
import SnsIncreaseStakeNeuronModal from "$lib/modals/sns/neurons/SnsIncreaseStakeNeuronModal.svelte";
import { loadSnsAccounts } from "$lib/services/sns-accounts.services";
import { increaseStakeNeuron } from "$lib/services/sns-neurons.services";
import { startBusy } from "$lib/stores/busy.store";
import { snsAccountsStore } from "$lib/stores/sns-accounts.store";
import { tokensStore } from "$lib/stores/tokens.store";
import { page } from "$mocks/$app/stores";
import {
mockPrincipal,
Expand All @@ -22,12 +19,7 @@ import {
import { setSnsProjects } from "$tests/utils/sns.test-utils";
import { SnsSwapLifecycle } from "@dfinity/sns";
import { ICPToken } from "@dfinity/utils";
import {
fireEvent,
render,
waitFor,
type RenderResult,
} from "@testing-library/svelte";
import { fireEvent, waitFor, type RenderResult } from "@testing-library/svelte";
import type { SvelteComponent } from "svelte";

vi.mock("$lib/services/sns-neurons.services", () => {
Expand Down Expand Up @@ -55,6 +47,7 @@ describe("SnsIncreaseStakeNeuronModal", () => {
const snsProjectParams = {
lifecycle: SnsSwapLifecycle.Committed,
rootCanisterId,
tokenMetadata: mockSnsToken,
};

const props = {
Expand Down Expand Up @@ -82,48 +75,13 @@ describe("SnsIncreaseStakeNeuronModal", () => {
setSnsProjects([snsProjectParams]);
});

describe("accounts and params are not loaded", () => {
beforeEach(() => {
snsAccountsStore.reset();
tokensStore.reset();
});

it("should not display modal", async () => {
const { container } = await render(SnsIncreaseStakeNeuronModal, {
props,
});

expect(container.querySelector("div.modal")).toBeNull();
});

it("should call sync sns accounts on init", async () => {
await render(SnsIncreaseStakeNeuronModal, {
props,
});

expect(loadSnsAccounts).toBeCalled();
});

it("should display a spinner on init", async () => {
await render(SnsIncreaseStakeNeuronModal, {
props,
});

expect(startBusy).toHaveBeenCalled();
});
});

describe("accounts and params are loaded", () => {
beforeEach(() => {
snsAccountsStore.setAccounts({
rootCanisterId,
accounts: [mockSnsMainAccount],
certified: true,
});
tokensStore.setToken({
canisterId: rootCanisterId,
token: mockSnsToken,
});
});

it("should display modal", async () => {
Expand Down
22 changes: 0 additions & 22 deletions frontend/src/tests/lib/services/_public/sns.services.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
aggregatorMockSnsesDataDto,
aggregatorSnsMockDto,
aggregatorSnsMockWith,
aggregatorTokenMock,
} from "$tests/mocks/sns-aggregator.mock";
import { nervousSystemFunctionMock } from "$tests/mocks/sns-functions.mock";
import { principal } from "$tests/mocks/sns-projects.mock";
Expand Down Expand Up @@ -237,27 +236,6 @@ describe("SNS public services", () => {
expect(get(snsAggregatorStore).data).toEqual(aggregatorMockSnsesDataDto);
});

it("should load and map tokens", async () => {
vi.spyOn(aggregatorApi, "querySnsProjects").mockImplementation(() =>
Promise.resolve([aggregatorSnsMockDto, aggregatorSnsMockDto])
);

await loadSnsProjects();

const ledgerCanisterId =
aggregatorSnsMockDto.canister_ids.ledger_canister_id;

const tokens = get(tokensStore);
const token = tokens[ledgerCanisterId];
expect(token).not.toBeUndefined();
expect(token?.certified).toBeTruthy();
expect(token?.token).toEqual(aggregatorTokenMock);

const rootCanisterId = aggregatorSnsMockDto.canister_ids.root_canister_id;
const tokenForRootCanister = tokens[rootCanisterId];
expect(tokenForRootCanister).toEqual(token);
});

it("should load and map total token supply", async () => {
const rootCanisterId = principal(0);
const totalSupply = 2_000_000_000;
Expand Down
11 changes: 2 additions & 9 deletions frontend/src/tests/routes/app/tokens/page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,23 +162,16 @@ describe("Tokens route", () => {
{
rootCanisterId: rootCanisterIdTetris,
projectName: "Tetris",
tokenMetadata: tetrisToken,
lifecycle: SnsSwapLifecycle.Committed,
},
{
rootCanisterId: rootCanisterIdPacman,
projectName: "Pacman",
tokenMetadata: pacmanToken,
lifecycle: SnsSwapLifecycle.Committed,
},
]);
// Tokens are loaded in SNS aggregator
tokensStore.setTokens({
[rootCanisterIdTetris.toText()]: {
token: tetrisToken,
},
[rootCanisterIdPacman.toText()]: {
token: pacmanToken,
},
});
setCkETHCanisters();
icpAccountsStore.setForTesting({
main: { ...mockMainAccount, balanceUlps: icpBalanceE8s },
Expand Down

0 comments on commit ee00305

Please sign in to comment.