Skip to content

Commit

Permalink
cleant tets
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabib committed Jan 9, 2025
1 parent 1349eae commit da4a16e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 37 deletions.
3 changes: 0 additions & 3 deletions frontend/src/routes/(app)/(nns)/portfolio/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
loadSnsAccountsBalances,
resetBalanceLoading,
} from "$lib/services/accounts-balances.services";
import { loadCkBTCTokens } from "$lib/services/ckbtc-tokens.services";
import { loadIcpSwapTickers } from "$lib/services/icp-swap.services";
import { neuronsStore } from "$lib/stores/neurons.store";
import { snsNeuronsStore } from "$lib/stores/sns-neurons.store";
Expand All @@ -25,8 +24,6 @@
let tableProjects: TableProject[] = [];
resetBalanceLoading();
// maybe I can get rid of it as this is load when calling the loadAccountsBalances
loadCkBTCTokens();
loadIcpSwapTickers();
$: if ($authSignedInStore) {
Expand Down
67 changes: 33 additions & 34 deletions frontend/src/tests/routes/app/portfolio/page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import { setAccountsForTesting } from "$tests/utils/accounts.test-utils";
import { setCkETHCanisters } from "$tests/utils/cketh.test-utils";
import { setSnsProjects } from "$tests/utils/sns.test-utils";
import { runResolvedPromises } from "$tests/utils/timers.test-utils";
import { AnonymousIdentity } from "@dfinity/agent";
import { SnsSwapLifecycle } from "@dfinity/sns";
import { render } from "@testing-library/svelte";
import { get } from "svelte/store";
Expand All @@ -62,38 +61,6 @@ describe("Portfolio route", () => {

beforeEach(() => {
vi.spyOn(icpSwapApi, "queryIcpSwapTickers").mockResolvedValue(tickers);
vi.spyOn(icrcLedgerApi, "queryIcrcToken").mockImplementation(
async ({ canisterId }) => {
const tokenMap = {
[CKBTC_UNIVERSE_CANISTER_ID.toText()]: mockCkBTCToken,
[CKTESTBTC_UNIVERSE_CANISTER_ID.toText()]: mockCkTESTBTCToken,
[CKETH_UNIVERSE_CANISTER_ID.toText()]: mockCkETHToken,
[CKUSDC_UNIVERSE_CANISTER_ID.toText()]: mockCkUSDCToken,
};
return tokenMap[canisterId.toText()];
}
);
});

it.skip("should load CkBTC tokens", async () => {
const identity = new AnonymousIdentity();

expect(icrcLedgerApi.queryIcrcToken).toBeCalledTimes(0);

await renderPage();

expect(icrcLedgerApi.queryIcrcToken).toBeCalledTimes(2);
expect(icrcLedgerApi.queryIcrcToken).toHaveBeenNthCalledWith(1, {
canisterId: CKBTC_UNIVERSE_CANISTER_ID,
certified: false,
identity,
});

expect(icrcLedgerApi.queryIcrcToken).toHaveBeenNthCalledWith(2, {
canisterId: CKTESTBTC_UNIVERSE_CANISTER_ID,
certified: false,
identity,
});
});

it("should load ICP Swap tickers", async () => {
Expand Down Expand Up @@ -124,6 +91,18 @@ describe("Portfolio route", () => {
beforeEach(() => {
resetIdentity();

vi.spyOn(icrcLedgerApi, "queryIcrcToken").mockImplementation(
async ({ canisterId }) => {
const tokenMap = {
[CKBTC_UNIVERSE_CANISTER_ID.toText()]: mockCkBTCToken,
[CKTESTBTC_UNIVERSE_CANISTER_ID.toText()]: mockCkTESTBTCToken,
[CKETH_UNIVERSE_CANISTER_ID.toText()]: mockCkETHToken,
[CKUSDC_UNIVERSE_CANISTER_ID.toText()]: mockCkUSDCToken,
};
return tokenMap[canisterId.toText()];
}
);

vi.spyOn(icrcLedgerApi, "queryIcrcBalance").mockImplementation(
async ({ canisterId }) => {
const balancesMap = {
Expand Down Expand Up @@ -152,6 +131,27 @@ describe("Portfolio route", () => {
setSnsProjects([tetrisSNS]);
});

it("should load all ckBtc tokens", async () => {
const identity = mockIdentity;

expect(icrcLedgerApi.queryIcrcToken).toBeCalledTimes(0);

await renderPage();

expect(icrcLedgerApi.queryIcrcToken).toBeCalledTimes(2);
expect(icrcLedgerApi.queryIcrcToken).toHaveBeenNthCalledWith(1, {
canisterId: CKBTC_UNIVERSE_CANISTER_ID,
certified: false,
identity,
});

expect(icrcLedgerApi.queryIcrcToken).toHaveBeenNthCalledWith(2, {
canisterId: CKTESTBTC_UNIVERSE_CANISTER_ID,
certified: false,
identity,
});
});

it("should load all accounts balances for both ckBTC and icrc(ckETH, ckUSDC, Tetris(SNS token))", async () => {
const identity = mockIdentity;
const account = {
Expand Down Expand Up @@ -205,7 +205,6 @@ describe("Portfolio route", () => {
setAccountsForTesting({
main: { ...mockMainAccount, balanceUlps: icpBalanceE8s },
});
vi.spyOn(icrcLedgerApi, "icrcTransfer").mockResolvedValue(1234n);
icpSwapTickersStore.set([
{
...mockIcpSwapTicker,
Expand Down

0 comments on commit da4a16e

Please sign in to comment.