Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
deuch13 committed May 15, 2024
1 parent 8b87857 commit 6740502
Show file tree
Hide file tree
Showing 4 changed files with 11,367 additions and 411 deletions.
16 changes: 9 additions & 7 deletions explorer/src/lib/components/__tests__/BlocksCard.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { cleanup, fireEvent, render } from "@testing-library/svelte";
import { apiBlocks } from "$lib/mock-data";
import { transformBlock } from "$lib/chain-info";
import { BlocksCard } from "..";
import { mapWith, slice } from "lamb";
import { mapWith } from "lamb";

global.ResizeObserver = vi.fn().mockImplementation(() => ({
disconnect: vi.fn(),
Expand All @@ -12,13 +12,13 @@ global.ResizeObserver = vi.fn().mockImplementation(() => ({
}));

const transformBlocks = mapWith(transformBlock);
const data = slice(transformBlocks(apiBlocks.data.blocks), 0, 10);
const data = transformBlocks(apiBlocks.data.blocks);

describe("Blocks Card", () => {
vi.useFakeTimers();
vi.setSystemTime(new Date(2024, 4, 20));
const baseProps = {
blocks: data,
blocks: null,
error: null,
loading: false,
};
Expand Down Expand Up @@ -53,11 +53,12 @@ describe("Blocks Card", () => {
});

it("should disable the `Show More` button if there is no more data to display", async () => {
const loading = true;
const loading = false;
const blocks = data;

const { container, getByRole } = render(BlocksCard, {
...baseOptions,
props: { ...baseProps, loading },
props: { ...baseProps, blocks, loading },
});

const button = getByRole("button");
Expand All @@ -66,9 +67,10 @@ describe("Blocks Card", () => {

const clicks = Math.ceil(data.length / showMoreIncrement) - 1;

Array.from({ length: clicks }).forEach(async () => {
//eslint-disable-next-line
for (const _ of Array.from({ length: clicks })) {
await fireEvent.click(button);
});
}

expect(button).toBeDisabled();

Expand Down
18 changes: 10 additions & 8 deletions explorer/src/lib/components/__tests__/TransactionsCard.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ 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";
import { mapWith } from "lamb";

global.ResizeObserver = vi.fn().mockImplementation(() => ({
disconnect: vi.fn(),
Expand All @@ -12,15 +12,15 @@ global.ResizeObserver = vi.fn().mockImplementation(() => ({
}));

const transformTransactions = mapWith(transformTransaction);
const data = slice(transformTransactions(apiTransactions.data), 0, 10);
const data = transformTransactions(apiTransactions.data);

describe("Transactions Card", () => {
vi.useFakeTimers();
vi.setSystemTime(new Date(2024, 4, 20));
const baseProps = {
error: null,
loading: false,
txs: data,
txs: null,
};
const baseOptions = {
props: baseProps,
Expand All @@ -39,7 +39,7 @@ describe("Transactions Card", () => {
expect(container.firstChild).toMatchSnapshot();
});

it("should disable the `Show More` button is the card is in the loading state", () => {
it("should disable the `Show More` button if the card is in the loading state", async () => {
const loading = true;

const { container, getByRole } = render(TransactionsCard, {
Expand All @@ -53,11 +53,12 @@ describe("Transactions Card", () => {
});

it("should disable the `Show More` button if there is no more data to display", async () => {
const loading = true;
const loading = false;
const txs = data;

const { container, getByRole } = render(TransactionsCard, {
...baseOptions,
props: { ...baseProps, loading },
props: { ...baseProps, loading, txs },
});

const button = getByRole("button");
Expand All @@ -66,9 +67,10 @@ describe("Transactions Card", () => {

const clicks = Math.ceil(data.length / showMoreIncrement) - 1;

Array.from({ length: clicks }).forEach(async () => {
//eslint-disable-next-line
for (const _ of Array.from({ length: clicks })) {
await fireEvent.click(button);
});
}

expect(button).toBeDisabled();

Expand Down
Loading

0 comments on commit 6740502

Please sign in to comment.