diff --git a/explorer/src/lib/components/__tests__/BlocksCard.spec.js b/explorer/src/lib/components/__tests__/BlocksCard.spec.js index e7ac63701c..87a9b7ab4e 100644 --- a/explorer/src/lib/components/__tests__/BlocksCard.spec.js +++ b/explorer/src/lib/components/__tests__/BlocksCard.spec.js @@ -5,6 +5,12 @@ import { transformBlock } from "$lib/chain-info"; import { BlocksCard } from ".."; import { mapWith, slice } from "lamb"; +global.ResizeObserver = vi.fn().mockImplementation(() => ({ + disconnect: vi.fn(), + observe: vi.fn(), + unobserve: vi.fn(), +})); + const transformBlocks = mapWith(transformBlock); const data = slice(transformBlocks(apiBlocks.data.blocks), 0, 10); diff --git a/explorer/src/lib/components/__tests__/TransactionsCard.spec.js b/explorer/src/lib/components/__tests__/TransactionsCard.spec.js new file mode 100644 index 0000000000..d6e96198d3 --- /dev/null +++ b/explorer/src/lib/components/__tests__/TransactionsCard.spec.js @@ -0,0 +1,77 @@ +import { afterAll, afterEach, describe, expect, it, vi } from "vitest"; +import { cleanup, fireEvent, render } from "@testing-library/svelte"; +import { apiTransactions } from "$lib/mock-data"; +import { transformTransaction } from "$lib/chain-info"; +import { TransactionsCard } from ".."; +import { mapWith, slice } from "lamb"; + +global.ResizeObserver = vi.fn().mockImplementation(() => ({ + disconnect: vi.fn(), + observe: vi.fn(), + unobserve: vi.fn(), +})); + +const transformTransactions = mapWith(transformTransaction); +const data = slice(transformTransactions(apiTransactions.data), 0, 10); + +describe("Transactions Card", () => { + vi.useFakeTimers(); + vi.setSystemTime(new Date(2024, 4, 20)); + const baseProps = { + txs: data, + error: null, + loading: false, + }; + const baseOptions = { + props: baseProps, + target: document.body, + }; + + afterEach(cleanup); + + afterAll(() => { + vi.useRealTimers(); + }); + + it("should render the `TransactionsCard` component", () => { + const { container } = render(TransactionsCard, baseOptions); + + expect(container.firstChild).toMatchSnapshot(); + }); + + it("should disable the `Show More` button is the card is in the loading state", () => { + const loading = true; + + const { container, getByRole } = render(TransactionsCard, { + ...baseOptions, + props: { ...baseProps, loading }, + }); + + expect(getByRole("button")).toBeDisabled(); + + expect(container.firstChild).toMatchSnapshot(); + }); + + it("should disable the `Show More` button if there is no more data to display", async () => { + const loading = true; + + const { container, getByRole } = render(TransactionsCard, { + ...baseOptions, + props: { ...baseProps, loading }, + }); + + const button = getByRole("button"); + + const showMoreIncrement = 15; + + const clicks = Math.ceil(data.length / showMoreIncrement) - 1; + + Array.from({ length: clicks }).forEach(async () => { + await fireEvent.click(button); + }); + + expect(button).toBeDisabled(); + + expect(container.firstChild).toMatchSnapshot(); + }); +}); diff --git a/explorer/src/lib/components/__tests__/__snapshots__/TransactionsCard.spec.js.snap b/explorer/src/lib/components/__tests__/__snapshots__/TransactionsCard.spec.js.snap new file mode 100644 index 0000000000..f10bfcc1a0 --- /dev/null +++ b/explorer/src/lib/components/__tests__/__snapshots__/TransactionsCard.spec.js.snap @@ -0,0 +1,2971 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`Transactions Card > should disable the \`Show More\` button if there is no more data to display 1`] = ` +
+ Hash + | + + + ++ Gas + | + + + ++ Fee + | + + + ++ Status + | + + + ++ Type + | + + +
---|---|---|---|---|
+ + 3c6e4018cf...308e07bd2d + + + + + + last month + + | + + + +
+
+ PRICE:
+
+
+ 1
+ + + + LIMIT: + + + 500,000,000 + |
+
+
+
+ + + 0.000290766 Dusk + + + | + + + ++ + success + + + | + + + ++ + transfer + + + | + + + +
+ + 40d3e59a9b...5e8ade4d3b + + + + + + last month + + | + + + +
+
+ PRICE:
+
+
+ 1
+ + + + LIMIT: + + + 500,000,000 + |
+
+
+
+ + + 0.000290053 Dusk + + + | + + + ++ + success + + + | + + + ++ + transfer + + + | + + + +
+ + ea86c56ffa...8914074fe3 + + + + + + last month + + | + + + +
+
+ PRICE:
+
+
+ 1
+ + + + LIMIT: + + + 500,000,000 + |
+
+
+
+ + + 0.000290219 Dusk + + + | + + + ++ + success + + + | + + + ++ + transfer + + + | + + + +
+ + ea86c56ffa...8914074fe3 + + + + + + last month + + | + + + +
+
+ PRICE:
+
+
+ 1
+ + + + LIMIT: + + + 500,000,000 + |
+
+
+
+ + + 0.00029046 Dusk + + + | + + + ++ + success + + + | + + + ++ + transfer + + + | + + + +
+ + a85a0f5cc2...f0bb827312 + + + + + + last month + + | + + + +
+
+ PRICE:
+
+
+ 1
+ + + + LIMIT: + + + 500,000,000 + |
+
+
+
+ + + 0.000291263 Dusk + + + | + + + ++ + success + + + | + + + ++ + transfer + + + | + + + +
+ + 646bd535ae...67c1cb0906 + + + + + + last month + + | + + + +
+
+ PRICE:
+
+
+ 1
+ + + + LIMIT: + + + 500,000,000 + |
+
+
+
+ + + 0.000290735 Dusk + + + | + + + ++ + success + + + | + + + ++ + transfer + + + | + + + +
+ + fbcda951c6...4bec844f78 + + + + + + last month + + | + + + +
+
+ PRICE:
+
+
+ 1
+ + + + LIMIT: + + + 500,000,000 + |
+
+
+
+ + + 0.000289627 Dusk + + + | + + + ++ + success + + + | + + + ++ + transfer + + + | + + + +
+ + a90821aca4...11467eb9c6 + + + + + + last month + + | + + + +
+
+ PRICE:
+
+
+ 1
+ + + + LIMIT: + + + 500,000,000 + |
+
+
+
+ + + 0.00029061 Dusk + + + | + + + ++ + success + + + | + + + ++ + transfer + + + | + + + +
+ + 4db9e793b1...e2ab163e74 + + + + + + last month + + | + + + +
+
+ PRICE:
+
+
+ 1
+ + + + LIMIT: + + + 500,000,000 + |
+
+
+
+ + + 0.000291347 Dusk + + + | + + + ++ + success + + + | + + + ++ + transfer + + + | + + + +
+ + 47c9f1349f...e7ce5103db + + + + + + last month + + | + + + +
+
+ PRICE:
+
+
+ 1
+ + + + LIMIT: + + + 500,000,000 + |
+
+
+
+ + + 0.000290416 Dusk + + + | + + + ++ + success + + + | + + + ++ + transfer + + + | + + + +
+ Hash + | + + + ++ Gas + | + + + ++ Fee + | + + + ++ Status + | + + + ++ Type + | + + +
---|---|---|---|---|
+ + 3c6e4018cf...308e07bd2d + + + + + + last month + + | + + + +
+
+ PRICE:
+
+
+ 1
+ + + + LIMIT: + + + 500,000,000 + |
+
+
+
+ + + 0.000290766 Dusk + + + | + + + ++ + success + + + | + + + ++ + transfer + + + | + + + +
+ + 40d3e59a9b...5e8ade4d3b + + + + + + last month + + | + + + +
+
+ PRICE:
+
+
+ 1
+ + + + LIMIT: + + + 500,000,000 + |
+
+
+
+ + + 0.000290053 Dusk + + + | + + + ++ + success + + + | + + + ++ + transfer + + + | + + + +
+ + ea86c56ffa...8914074fe3 + + + + + + last month + + | + + + +
+
+ PRICE:
+
+
+ 1
+ + + + LIMIT: + + + 500,000,000 + |
+
+
+
+ + + 0.000290219 Dusk + + + | + + + ++ + success + + + | + + + ++ + transfer + + + | + + + +
+ + ea86c56ffa...8914074fe3 + + + + + + last month + + | + + + +
+
+ PRICE:
+
+
+ 1
+ + + + LIMIT: + + + 500,000,000 + |
+
+
+
+ + + 0.00029046 Dusk + + + | + + + ++ + success + + + | + + + ++ + transfer + + + | + + + +
+ + a85a0f5cc2...f0bb827312 + + + + + + last month + + | + + + +
+
+ PRICE:
+
+
+ 1
+ + + + LIMIT: + + + 500,000,000 + |
+
+
+
+ + + 0.000291263 Dusk + + + | + + + ++ + success + + + | + + + ++ + transfer + + + | + + + +
+ + 646bd535ae...67c1cb0906 + + + + + + last month + + | + + + +
+
+ PRICE:
+
+
+ 1
+ + + + LIMIT: + + + 500,000,000 + |
+
+
+
+ + + 0.000290735 Dusk + + + | + + + ++ + success + + + | + + + ++ + transfer + + + | + + + +
+ + fbcda951c6...4bec844f78 + + + + + + last month + + | + + + +
+
+ PRICE:
+
+
+ 1
+ + + + LIMIT: + + + 500,000,000 + |
+
+
+
+ + + 0.000289627 Dusk + + + | + + + ++ + success + + + | + + + ++ + transfer + + + | + + + +
+ + a90821aca4...11467eb9c6 + + + + + + last month + + | + + + +
+
+ PRICE:
+
+
+ 1
+ + + + LIMIT: + + + 500,000,000 + |
+
+
+
+ + + 0.00029061 Dusk + + + | + + + ++ + success + + + | + + + ++ + transfer + + + | + + + +
+ + 4db9e793b1...e2ab163e74 + + + + + + last month + + | + + + +
+
+ PRICE:
+
+
+ 1
+ + + + LIMIT: + + + 500,000,000 + |
+
+
+
+ + + 0.000291347 Dusk + + + | + + + ++ + success + + + | + + + ++ + transfer + + + | + + + +
+ + 47c9f1349f...e7ce5103db + + + + + + last month + + | + + + +
+
+ PRICE:
+
+
+ 1
+ + + + LIMIT: + + + 500,000,000 + |
+
+
+
+ + + 0.000290416 Dusk + + + | + + + ++ + success + + + | + + + ++ + transfer + + + | + + + +
+ Hash + | + + + ++ Gas + | + + + ++ Fee + | + + + ++ Status + | + + + ++ Type + | + + +
---|---|---|---|---|
+ + 3c6e4018cf...308e07bd2d + + + + + + last month + + | + + + +
+
+ PRICE:
+
+
+ 1
+ + + + LIMIT: + + + 500,000,000 + |
+
+
+
+ + + 0.000290766 Dusk + + + | + + + ++ + success + + + | + + + ++ + transfer + + + | + + + +
+ + 40d3e59a9b...5e8ade4d3b + + + + + + last month + + | + + + +
+
+ PRICE:
+
+
+ 1
+ + + + LIMIT: + + + 500,000,000 + |
+
+
+
+ + + 0.000290053 Dusk + + + | + + + ++ + success + + + | + + + ++ + transfer + + + | + + + +
+ + ea86c56ffa...8914074fe3 + + + + + + last month + + | + + + +
+
+ PRICE:
+
+
+ 1
+ + + + LIMIT: + + + 500,000,000 + |
+
+
+
+ + + 0.000290219 Dusk + + + | + + + ++ + success + + + | + + + ++ + transfer + + + | + + + +
+ + ea86c56ffa...8914074fe3 + + + + + + last month + + | + + + +
+
+ PRICE:
+
+
+ 1
+ + + + LIMIT: + + + 500,000,000 + |
+
+
+
+ + + 0.00029046 Dusk + + + | + + + ++ + success + + + | + + + ++ + transfer + + + | + + + +
+ + a85a0f5cc2...f0bb827312 + + + + + + last month + + | + + + +
+
+ PRICE:
+
+
+ 1
+ + + + LIMIT: + + + 500,000,000 + |
+
+
+
+ + + 0.000291263 Dusk + + + | + + + ++ + success + + + | + + + ++ + transfer + + + | + + + +
+ + 646bd535ae...67c1cb0906 + + + + + + last month + + | + + + +
+
+ PRICE:
+
+
+ 1
+ + + + LIMIT: + + + 500,000,000 + |
+
+
+
+ + + 0.000290735 Dusk + + + | + + + ++ + success + + + | + + + ++ + transfer + + + | + + + +
+ + fbcda951c6...4bec844f78 + + + + + + last month + + | + + + +
+
+ PRICE:
+
+
+ 1
+ + + + LIMIT: + + + 500,000,000 + |
+
+
+
+ + + 0.000289627 Dusk + + + | + + + ++ + success + + + | + + + ++ + transfer + + + | + + + +
+ + a90821aca4...11467eb9c6 + + + + + + last month + + | + + + +
+
+ PRICE:
+
+
+ 1
+ + + + LIMIT: + + + 500,000,000 + |
+
+
+
+ + + 0.00029061 Dusk + + + | + + + ++ + success + + + | + + + ++ + transfer + + + | + + + +
+ + 4db9e793b1...e2ab163e74 + + + + + + last month + + | + + + +
+
+ PRICE:
+
+
+ 1
+ + + + LIMIT: + + + 500,000,000 + |
+
+
+
+ + + 0.000291347 Dusk + + + | + + + ++ + success + + + | + + + ++ + transfer + + + | + + + +
+ + 47c9f1349f...e7ce5103db + + + + + + last month + + | + + + +
+
+ PRICE:
+
+
+ 1
+ + + + LIMIT: + + + 500,000,000 + |
+
+
+
+ + + 0.000290416 Dusk + + + | + + + ++ + success + + + | + + + ++ + transfer + + + | + + + +