diff --git a/src/components/ListingComponent/__tests__/ListingComponent.spec.ts b/src/components/ListingComponent/__tests__/ListingComponent.spec.ts index e168bf5..d7312f1 100644 --- a/src/components/ListingComponent/__tests__/ListingComponent.spec.ts +++ b/src/components/ListingComponent/__tests__/ListingComponent.spec.ts @@ -10,6 +10,17 @@ describe("ListingComponent.vue", () => { setActivePinia(createPinia()); }); + test("Test Message when an empty array is received", () => { + const wrapper = mount(ListingComponent, { + props: { + walletTransactions: [], + isManageMode: true, + }, + }); + + expect(wrapper.html()).toContain("Não há nenhuma transação anterior"); + }); + test("Test Headers on List in Manage Mode", () => { const wrapper = mount(ListingComponent, { props: { diff --git a/src/components/LoadingComponent.vue b/src/components/LoadingComponent/LoadingComponent.vue similarity index 100% rename from src/components/LoadingComponent.vue rename to src/components/LoadingComponent/LoadingComponent.vue diff --git a/src/components/LoadingComponent/__tests__/LoadingComponent.spec.ts b/src/components/LoadingComponent/__tests__/LoadingComponent.spec.ts new file mode 100644 index 0000000..8864a65 --- /dev/null +++ b/src/components/LoadingComponent/__tests__/LoadingComponent.spec.ts @@ -0,0 +1,27 @@ +import { mount } from "@vue/test-utils"; +import LoadingComponent from "../LoadingComponent.vue"; + +describe("Loading.vue", () => { + test("Test loading content with received props", () => { + const wrapper = mount(LoadingComponent, { + props: { + title: "MockTitle", + message: "MockMessage", + }, + }); + + expect(wrapper.html()).toContain("MockTitle"); + expect(wrapper.html()).toContain("MockMessage"); + }); + + test("Test default text if props title isnt passed", () => { + const wrapper = mount(LoadingComponent, { + props: { + message: "MockMessage", + }, + }); + + expect(wrapper.html()).toContain("Confirme em sua carteira"); + expect(wrapper.html()).toContain("MockMessage"); + }); +}); diff --git a/src/model/mock/ValidDepositMock.ts b/src/model/mock/ValidDepositMock.ts index c35c059..3900321 100644 --- a/src/model/mock/ValidDepositMock.ts +++ b/src/model/mock/ValidDepositMock.ts @@ -1,40 +1,39 @@ -import { parseEther } from "ethers/lib/utils"; import type { ValidDeposit } from "../ValidDeposit"; export const MockValidDeposits: ValidDeposit[] = [ { blockNumber: 1, - depositID: parseEther("1"), + token: "1", remaining: 70, seller: "mockedSellerAddress", - pixKey: "123456789", + pixKey: 123456789, }, { blockNumber: 2, - depositID: parseEther("2"), + token: "2", remaining: 200, seller: "mockedSellerAddress", - pixKey: "123456789", + pixKey: 123456789, }, { blockNumber: 3, - depositID: parseEther("3"), + token: "3", remaining: 1250, seller: "mockedSellerAddress", - pixKey: "123456789", + pixKey: 123456789, }, { blockNumber: 4, - depositID: parseEther("4"), + token: "4", remaining: 4000, seller: "mockedSellerAddress", - pixKey: "123456789", + pixKey: 123456789, }, { blockNumber: 5, - depositID: parseEther("5"), + token: "5", remaining: 2000, seller: "mockedSellerAddress", - pixKey: "123456789", + pixKey: 123456789, }, ]; diff --git a/src/utils/__tests__/debounce.spec.ts b/src/utils/__tests__/debounce.spec.ts new file mode 100644 index 0000000..b9512c4 --- /dev/null +++ b/src/utils/__tests__/debounce.spec.ts @@ -0,0 +1,24 @@ +import { it, expect, vi, type Mock } from "vitest"; +import { debounce } from "../debounce"; + +vi.useFakeTimers(); + +describe("debounce function test", () => { + let mockFunction: Mock; + let debounceFunction: Function; + + beforeEach(() => { + mockFunction = vi.fn(); + debounceFunction = debounce(mockFunction, 1000); + }); + + it("debounce function will be executed just once", () => { + for (let i = 0; i < 100; i++) { + debounceFunction(); + } + + vi.runAllTimers(); + + expect(mockFunction).toBeCalledTimes(1); + }); +}); diff --git a/src/utils/__tests__/decimalCount.spec.ts b/src/utils/__tests__/decimalCount.spec.ts new file mode 100644 index 0000000..53ff890 --- /dev/null +++ b/src/utils/__tests__/decimalCount.spec.ts @@ -0,0 +1,12 @@ +import { it, expect } from "vitest"; +import { decimalCount } from "../decimalCount"; + +describe("decimalCount function test", () => { + it("decimalCount should return length 1 of decimal", () => { + expect(decimalCount("4.1")).toEqual(1); + }); + + it("decimalCount should return length 0 because no decimal found", () => { + expect(decimalCount("5")).toEqual(0); + }); +}); diff --git a/src/utils/__tests__/networkLiquidity.spec.ts b/src/utils/__tests__/networkLiquidity.spec.ts new file mode 100644 index 0000000..00dd9e7 --- /dev/null +++ b/src/utils/__tests__/networkLiquidity.spec.ts @@ -0,0 +1,25 @@ +import { MockValidDeposits } from "@/model/mock/ValidDepositMock"; +import { it, expect, vi } from "vitest"; +import { verifyNetworkLiquidity } from "../networkLiquidity"; + +vi.useFakeTimers(); + +describe("verifyNetworkLiquidity function test", () => { + it("verifyNetworkLiquidity should return an element from valid deposit list when searching for other deposits", () => { + const liquidityElement = verifyNetworkLiquidity( + MockValidDeposits[0].remaining, + "strangeWalletAddress", + MockValidDeposits + ); + expect(liquidityElement).toEqual(MockValidDeposits[0]); + }); + + it("verifyNetworkLiquidity should return undefined when all deposits on valid deposit list match connected wallet addres", () => { + const liquidityElement = verifyNetworkLiquidity( + MockValidDeposits[0].remaining, + MockValidDeposits[0].seller, + [MockValidDeposits[0]] + ); + expect(liquidityElement).toEqual(undefined); + }); +});