-
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.
- Loading branch information
Showing
10 changed files
with
3,167 additions
and
29 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
77 changes: 77 additions & 0 deletions
77
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,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 = { | ||
error: null, | ||
loading: false, | ||
txs: data, | ||
}; | ||
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(); | ||
}); | ||
}); |
Oops, something went wrong.