-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1730 from dusk-network/feature-1721
explorer: compose Transactions page
- Loading branch information
Showing
11 changed files
with
1,287 additions
and
1,615 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
explorer/src/lib/components/__tests__/TransactionsCard.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { afterAll, afterEach, describe, expect, it, vi } from "vitest"; | ||
import { cleanup, render } from "@testing-library/svelte"; | ||
import { apiTransactions } from "$lib/mock-data"; | ||
import { transformTransaction } from "$lib/chain-info"; | ||
import { TransactionsCard } from ".."; | ||
import { compose, mapWith, take } from "lamb"; | ||
|
||
global.ResizeObserver = vi.fn().mockImplementation(() => ({ | ||
disconnect: vi.fn(), | ||
observe: vi.fn(), | ||
unobserve: vi.fn(), | ||
})); | ||
|
||
const getTenTransactions = compose(mapWith(transformTransaction), take(10)); | ||
const data = getTenTransactions(apiTransactions.data); | ||
|
||
describe("Transactions Card", () => { | ||
vi.useFakeTimers(); | ||
vi.setSystemTime(new Date(2024, 4, 20)); | ||
const baseProps = { | ||
error: null, | ||
loading: false, | ||
txs: null, | ||
}; | ||
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 if the card is in the loading state", async () => { | ||
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 = false; | ||
const txs = data; | ||
|
||
const { container, getByRole } = render(TransactionsCard, { | ||
...baseOptions, | ||
props: { ...baseProps, loading, txs }, | ||
}); | ||
|
||
expect(getByRole("button")).toBeDisabled(); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.