From fe76d93fe49dd58480826cf1eca60546c1a521a3 Mon Sep 17 00:00:00 2001 From: Robert Schlittler Date: Tue, 17 Dec 2024 16:19:43 +0100 Subject: [PATCH 1/3] feat(frontend): add tests for networkAddress --- .../tests/lib/derived/network.derived.spec.ts | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/frontend/src/tests/lib/derived/network.derived.spec.ts diff --git a/src/frontend/src/tests/lib/derived/network.derived.spec.ts b/src/frontend/src/tests/lib/derived/network.derived.spec.ts new file mode 100644 index 0000000000..04776a83cf --- /dev/null +++ b/src/frontend/src/tests/lib/derived/network.derived.spec.ts @@ -0,0 +1,49 @@ +import { getIcrcAccount } from '$icp/utils/icrc-account.utils'; +import { networkAddress } from '$lib/derived/network.derived'; +import { ethAddressStore } from '$lib/stores/address.store'; +import { authStore } from '$lib/stores/auth.store'; +import { mockEthAddress } from '$tests/mocks/eth.mocks'; +import { mockIdentity } from '$tests/mocks/identity.mock'; +import { mockPage } from '$tests/mocks/page.store.mock'; +import { encodeIcrcAccount } from '@dfinity/ledger-icrc'; +import { get } from 'svelte/store'; +import { describe, expect, test, beforeEach, vi } from 'vitest'; + +describe('network.derived', () => { + + beforeEach(() => { + vi.clearAllMocks(); + ethAddressStore.reset(); + mockPage.reset(); + authStore.setForTesting(mockIdentity); + }) + + const mockEthAddressWithCertified = { + data: mockEthAddress, + certified: true + }; + + const expectedIcrcAddress = encodeIcrcAccount( + getIcrcAccount(mockIdentity.getPrincipal()) + ); + + test.each([ + { + network: 'ICP', + expectedAddress: expectedIcrcAddress + }, + { + network: 'ETH', + expectedAddress: mockEthAddress + } + ])('returns $network address when network is $network', ({ network, expectedAddress }) => { + + + mockPage.mock({ network }); + ethAddressStore.set(mockEthAddressWithCertified); + + const actualAddress = get(networkAddress); + + expect(actualAddress).toBe(expectedAddress); + }); +}); From 9a0271bf6a8135a07707b21ba028cf06fe782fb4 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 17 Dec 2024 15:24:32 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=A4=96=20Apply=20formatting=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/tests/lib/derived/network.derived.spec.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/frontend/src/tests/lib/derived/network.derived.spec.ts b/src/frontend/src/tests/lib/derived/network.derived.spec.ts index 04776a83cf..c429dc5474 100644 --- a/src/frontend/src/tests/lib/derived/network.derived.spec.ts +++ b/src/frontend/src/tests/lib/derived/network.derived.spec.ts @@ -7,25 +7,22 @@ import { mockIdentity } from '$tests/mocks/identity.mock'; import { mockPage } from '$tests/mocks/page.store.mock'; import { encodeIcrcAccount } from '@dfinity/ledger-icrc'; import { get } from 'svelte/store'; -import { describe, expect, test, beforeEach, vi } from 'vitest'; +import { beforeEach, describe, expect, test, vi } from 'vitest'; describe('network.derived', () => { - - beforeEach(() => { - vi.clearAllMocks(); + beforeEach(() => { + vi.clearAllMocks(); ethAddressStore.reset(); mockPage.reset(); authStore.setForTesting(mockIdentity); - }) + }); const mockEthAddressWithCertified = { data: mockEthAddress, certified: true }; - const expectedIcrcAddress = encodeIcrcAccount( - getIcrcAccount(mockIdentity.getPrincipal()) - ); + const expectedIcrcAddress = encodeIcrcAccount(getIcrcAccount(mockIdentity.getPrincipal())); test.each([ { @@ -37,8 +34,6 @@ describe('network.derived', () => { expectedAddress: mockEthAddress } ])('returns $network address when network is $network', ({ network, expectedAddress }) => { - - mockPage.mock({ network }); ethAddressStore.set(mockEthAddressWithCertified); From f61b5804c5b8334e08a7900d7fb72a9dde22c829 Mon Sep 17 00:00:00 2001 From: Robert Schlittler Date: Wed, 18 Dec 2024 09:01:39 +0100 Subject: [PATCH 3/3] feat(frontend): MR feedback --- src/frontend/src/tests/lib/derived/network.derived.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/frontend/src/tests/lib/derived/network.derived.spec.ts b/src/frontend/src/tests/lib/derived/network.derived.spec.ts index c429dc5474..e65a1791d6 100644 --- a/src/frontend/src/tests/lib/derived/network.derived.spec.ts +++ b/src/frontend/src/tests/lib/derived/network.derived.spec.ts @@ -15,6 +15,7 @@ describe('network.derived', () => { ethAddressStore.reset(); mockPage.reset(); authStore.setForTesting(mockIdentity); + ethAddressStore.set(mockEthAddressWithCertified); }); const mockEthAddressWithCertified = { @@ -35,7 +36,6 @@ describe('network.derived', () => { } ])('returns $network address when network is $network', ({ network, expectedAddress }) => { mockPage.mock({ network }); - ethAddressStore.set(mockEthAddressWithCertified); const actualAddress = get(networkAddress);