Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Romsters committed Nov 17, 2023
1 parent 24c7b6c commit f3dd4a9
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 39 deletions.
12 changes: 6 additions & 6 deletions packages/app/mock/transactions/Execute.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"symbol": "LINK",
"name": "ChainLink Token (goerli)",
"decimals": 18,
"usdPrice": "1"
"usdPrice": 1
},
"from": "0xcfa3DD0CBa60484d1C8D0cDd22C5432013368875",
"to": "0xde03a0B5963f75f1C8485B355fF6D30f3093BDE7",
Expand All @@ -48,7 +48,7 @@
"symbol": "LINK",
"name": "ChainLink Token (goerli)",
"decimals": 18,
"usdPrice": "1"
"usdPrice": 1
},
"from": "0xcfa3DD0CBa60484d1C8D0cDd22C5432013368875",
"to": "0x6c557bc88804254760Be210c01fd9B6B5dE96e53",
Expand All @@ -63,7 +63,7 @@
"symbol": "LINK",
"name": "ChainLink Token (goerli)",
"decimals": 18,
"usdPrice": "1"
"usdPrice": 1
},
"from": "0xcfa3DD0CBa60484d1C8D0cDd22C5432013368875",
"to": "0x6c557bc88804254760Be210c01fd9B6B5dE96e53",
Expand All @@ -78,7 +78,7 @@
"symbol": "ETH",
"name": "Ether",
"decimals": 18,
"usdPrice": "1"
"usdPrice": 1
},
"from": "0xcfa3DD0CBa60484d1C8D0cDd22C5432013368875",
"to": "0xde03a0B5963f75f1C8485B355fF6D30f3093BDE7",
Expand All @@ -95,7 +95,7 @@
"symbol": "LINK",
"name": "ChainLink Token (goerli)",
"decimals": 18,
"usdPrice": "1"
"usdPrice": 1
},
"from": "0xcfa3DD0CBa60484d1C8D0cDd22C5432013368875",
"to": "0x6c557bc88804254760Be210c01fd9B6B5dE96e53",
Expand All @@ -114,7 +114,7 @@
"symbol": "LINK",
"name": "ChainLink Token (goerli)",
"decimals": 18,
"usdPrice": "1"
"usdPrice": 1
},
"from": "0xcfa3DD0CBa60484d1C8D0cDd22C5432013368875",
"to": "0x6c557bc88804254760Be210c01fd9B6B5dE96e53",
Expand Down
3 changes: 1 addition & 2 deletions packages/app/src/components/transactions/EthAmountPrice.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import { computed, type PropType } from "vue";
import TokenAmountPrice from "@/components/TokenAmountPrice.vue";
import useToken from "@/composables/useToken";
import useToken, { type Token } from "@/composables/useToken";
import type { Token } from "@/composables/useToken";
import type { BigNumberish } from "ethers";
import { ETH_TOKEN_L2_ADDRESS } from "@/utils/constants";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<template>
<TokenAmountPrice :token="token" :amount="amount" v-slot="{ token, decimalAmount, priceAmount }">
<template v-if="token && decimalAmount">
<TokenAmountPrice :token="token" :amount="amount" v-slot="{ token: tokenInfo, decimalAmount, priceAmount }">
<template v-if="tokenInfo && decimalAmount">
<div class="token-amount-symbol">
<Tooltip class="token-amount-short" :disabled="decimalAmount.length < 10">
{{ shortenFitText(decimalAmount, "right", 100, 10) }}

<template #content>{{ decimalAmount }} {{ token.symbol }}</template>
<template #content>{{ decimalAmount }} {{ tokenInfo.symbol }}</template>
</Tooltip>
<div class="token-amount" :data-testid="$testId.tokenAmount">{{ decimalAmount }}</div>
<TokenIconLabel class="token-icon" :address="token.l2Address" :symbol="token.symbol" show-link-symbol />
<TokenIconLabel class="token-icon" :address="tokenInfo.l2Address" :symbol="tokenInfo.symbol" show-link-symbol />
</div>
<span v-if="showPrice" class="token-price" :data-testid="$testId.tokenAmountPrice">
{{ priceAmount }}
Expand Down
11 changes: 3 additions & 8 deletions packages/app/src/composables/useToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import { $fetch } from "ohmyfetch";
import useContext, { type Context } from "@/composables/useContext";
import useTokenLibrary from "@/composables/useTokenLibrary";

import type { Address, Hash } from "@/types";
import type { Hash } from "@/types";

export type Token = Api.Response.Token & {
address: Address;
};
export type Token = Api.Response.Token;

export const retrieveToken = useMemoize(
(tokenAddress: Hash, context: Context = useContext()): Promise<Api.Response.Token> => {
Expand Down Expand Up @@ -40,10 +38,7 @@ export default () => {
await getTokens();
const tokenFromLibrary = getToken(address);
const token = tokenFromLibrary || (await retrieveToken(address));
tokenInfo.value = {
...token,
address: token.l2Address,
};
tokenInfo.value = token;
} catch {
isRequestFailed.value = true;
} finally {
Expand Down
3 changes: 3 additions & 0 deletions packages/app/src/composables/useTransfers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export default (address: ComputedRef<string>, context = useContext()) => {
name: null,
symbol: null,
decimals: 0,
usdPrice: null,
liquidity: null,
iconURL: null,
},
fromNetwork: transfer.type === "deposit" ? "L1" : "L2",
toNetwork: transfer.type === "withdrawal" ? "L1" : "L2",
Expand Down
2 changes: 1 addition & 1 deletion packages/app/tests/components/FeeData.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ vi.mock("@/composables/useToken", () => {
name: "Ether",
symbol: "ETH",
decimals: 18,
usdPrice: "150",
usdPrice: 150,
})),
}),
};
Expand Down
2 changes: 1 addition & 1 deletion packages/app/tests/components/token/TokenListTable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ vi.mock("@/composables/useToken", () => {
name: "Ether",
symbol: "ETH",
decimals: 18,
usdPrice: "150",
usdPrice: 150,
})),
}),
};
Expand Down
24 changes: 18 additions & 6 deletions packages/app/tests/components/transactions/GeneralInfo.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { nextTick } from "vue";
import { computed, nextTick } from "vue";
import { createI18n } from "vue-i18n";

import { describe, expect, it } from "vitest";
import { describe, expect, it, vi } from "vitest";

import { mount, RouterLinkStub } from "@vue/test-utils";

import { ETH_TOKEN_MOCK } from "../../mocks";

import Badge from "@/components/common/Badge.vue";
import Tooltip from "@/components/common/Tooltip.vue";
import Table from "@/components/transactions/infoTable/GeneralInfo.vue";
Expand Down Expand Up @@ -46,9 +48,9 @@ const transaction: TransactionItem = {
toNetwork: "L2",
type: "refund",
tokenInfo: {
address: "0x0000000000000000000000000000000000000000",
address: "0x000000000000000000000000000000000000800A",
l1Address: "0x0000000000000000000000000000000000000000",
l2Address: "0x0000000000000000000000000000000000000000",
l2Address: "0x000000000000000000000000000000000000800A",
symbol: "ETH",
name: "Ether",
decimals: 18,
Expand All @@ -62,9 +64,9 @@ const transaction: TransactionItem = {
toNetwork: "L2",
type: "refund",
tokenInfo: {
address: "0x0000000000000000000000000000000000000000",
address: "0x000000000000000000000000000000000000800A",
l1Address: "0x0000000000000000000000000000000000000000",
l2Address: "0x0000000000000000000000000000000000000000",
l2Address: "0x000000000000000000000000000000000000800A",
symbol: "ETH",
name: "Ether",
decimals: 18,
Expand Down Expand Up @@ -170,6 +172,16 @@ const transaction: TransactionItem = {
],
};

vi.mock("@/composables/useToken", () => {
return {
default: () => ({
getTokenInfo: vi.fn(),
tokenInfo: computed(() => ETH_TOKEN_MOCK),
isRequestPending: computed(() => false),
}),
};
});

describe("Transaction info table", () => {
const i18n = createI18n({
locale: "en",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe("TransferTableCell:", () => {
l2Address: "0x4732c03b2cf6ede46500e799de79a15df44929eb",
name: "ChainLink Token (goerli)",
symbol: "LINK",
usdPrice: "1",
usdPrice: 1,
},
},
},
Expand Down
1 change: 0 additions & 1 deletion packages/app/tests/composables/useToken.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ describe("useToken:", () => {
const { getTokenInfo, tokenInfo } = useToken();
await getTokenInfo(token.l2Address);
expect(tokenInfo.value).toEqual({
address: "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeb",
symbol: "ETH",
name: "Ether",
decimals: 18,
Expand Down
6 changes: 3 additions & 3 deletions packages/app/tests/composables/useTransaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ describe("useTransaction:", () => {
symbol: "LINK",
name: "ChainLink Token (goerli)",
decimals: 18,
usdPrice: "1",
usdPrice: 1,
},
from: "0xcfa3dd0cba60484d1c8d0cdd22c5432013368875",
to: "0xde03a0b5963f75f1c8485b355ff6d30f3093bde7",
Expand All @@ -299,7 +299,7 @@ describe("useTransaction:", () => {
symbol: "LINK",
name: "ChainLink Token (goerli)",
decimals: 18,
usdPrice: "1",
usdPrice: 1,
},
from: "0xcfa3dd0cba60484d1c8d0cdd22c5432013368875",
to: "0xde03a0b5963f75f1c8485b355ff6d30f3093bde7",
Expand All @@ -322,7 +322,7 @@ describe("useTransaction:", () => {
symbol: "LINK",
name: "ChainLink Token (goerli)",
decimals: 18,
usdPrice: "1",
usdPrice: 1,
},
from: "0xcfa3dd0cba60484d1c8d0cdd22c5432013368875",
to: "0xde03a0b5963f75f1c8485b355ff6d30f3093bde7",
Expand Down
6 changes: 6 additions & 0 deletions packages/app/tests/composables/useTransfers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const baseTransferPayload = {
name: "token name",
symbol: "token symbol",
decimals: 18,
iconURL: null,
usdPrice: null,
liquidity: null,
},
tokenAddress: "tokenAddress",
};
Expand Down Expand Up @@ -90,6 +93,9 @@ describe("useTransfers:", () => {
l2Address: "tokenAddress",
name: null,
symbol: null,
iconURL: null,
usdPrice: null,
liquidity: null,
},
type: "transfer",
fromNetwork: "L2",
Expand Down
10 changes: 6 additions & 4 deletions packages/app/tests/utils/formatters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,18 @@ describe("formatters:", () => {
});
describe("convert:", () => {
const token = {
address: "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" as Address,
l2Address: "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" as Address,
l1Address: null,
symbol: "ETH",
name: "ETH",
decimals: 18,

usdPrice: "3500",
usdPrice: 3500,
liquidity: null,
iconURL: null,
};

it("return correct price", () => {
expect(convert("0x56bc75e2d63100000", token, token.usdPrice!)).toBe("350000.0");
expect(convert("0x56bc75e2d63100000", token, token.usdPrice.toString())).toBe("350000.0");
});
it("handles float price", () => {
expect(convert("0x56bc75e2d63100000", token, "0.001")).toBe("0.1");
Expand Down
14 changes: 12 additions & 2 deletions packages/app/tests/views/HomeView.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ref } from "vue";
import { computed, ref } from "vue";
import { createI18n } from "vue-i18n";

import { describe, expect, it, vi } from "vitest";
Expand All @@ -7,7 +7,7 @@ import { render } from "@testing-library/vue";
import { useTimeAgo } from "@vueuse/core";
import { $fetch } from "ohmyfetch";

import { useBatchesMock } from "../mocks";
import { ETH_TOKEN_MOCK, useBatchesMock } from "../mocks";
import { useTransactionsMock } from "../mocks";

import ExecuteTx from "../../mock/transactions/Execute.json";
Expand Down Expand Up @@ -38,6 +38,16 @@ vi.mock("vue-router", () => ({
useRoute: () => vi.fn(),
}));

vi.mock("@/composables/useToken", () => {
return {
default: () => ({
getTokenInfo: vi.fn(),
tokenInfo: computed(() => ETH_TOKEN_MOCK),
isRequestPending: computed(() => false),
}),
};
});

describe("HomeView:", () => {
const i18n = createI18n({
locale: "en",
Expand Down

0 comments on commit f3dd4a9

Please sign in to comment.