-
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
31 changed files
with
2,455 additions
and
3,962 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { afterEach, describe, expect, it, vi } from "vitest"; | ||
import { cleanup, fireEvent, render } from "@testing-library/svelte"; | ||
|
||
import { Alert } from ".."; | ||
|
||
describe("Alert", () => { | ||
const baseProps = { | ||
error: null, | ||
hasEmptyData: false, | ||
}; | ||
const baseOptions = { | ||
props: baseProps, | ||
target: document.body, | ||
}; | ||
|
||
afterEach(cleanup); | ||
|
||
it("should render the `Alert` in the no data state", () => { | ||
const hasEmptyData = true; | ||
const { container } = render(Alert, { | ||
...baseOptions, | ||
props: { ...baseProps, hasEmptyData }, | ||
}); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
it("should render the `Alert` in the error state", () => { | ||
const error = new Error("error"); | ||
const { container } = render(Alert, { | ||
...baseOptions, | ||
props: { ...baseProps, error }, | ||
}); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
it("should dispatch the `retry` event on button click", async () => { | ||
const eventHandler = vi.fn(); | ||
const error = new Error("error"); | ||
const { component, getByRole } = render(Alert, { | ||
...baseOptions, | ||
props: { ...baseProps, error }, | ||
}); | ||
|
||
component.$on("retry", eventHandler); | ||
await fireEvent.click(getByRole("button")); | ||
expect(eventHandler).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
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
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,33 @@ | ||
import { afterAll, afterEach, describe, expect, it, vi } from "vitest"; | ||
import { cleanup, render } from "@testing-library/svelte"; | ||
import { apiBlocks } from "$lib/mock-data"; | ||
import { transformBlock } from "$lib/chain-info"; | ||
import { BlocksTable } from ".."; | ||
import { mapWith, slice } from "lamb"; | ||
|
||
const transformBlocks = mapWith(transformBlock); | ||
const data = slice(transformBlocks(apiBlocks.data.blocks), 0, 10); | ||
|
||
describe("Blocks Table", () => { | ||
vi.useFakeTimers(); | ||
vi.setSystemTime(new Date(2024, 4, 20)); | ||
const baseProps = { | ||
data: data, | ||
}; | ||
const baseOptions = { | ||
props: baseProps, | ||
target: document.body, | ||
}; | ||
|
||
afterEach(cleanup); | ||
|
||
afterAll(() => { | ||
vi.useRealTimers(); | ||
}); | ||
|
||
it("should render the `BlocksTable` component", () => { | ||
const { container } = render(BlocksTable, baseOptions); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
}); |
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,86 @@ | ||
import { afterEach, describe, expect, it, vi } from "vitest"; | ||
import { cleanup, fireEvent, render } from "@testing-library/svelte"; | ||
|
||
import { renderWithSimpleContent } from "$lib/dusk/test-helpers"; | ||
|
||
import { DataCard } from ".."; | ||
|
||
describe("DataCard", () => { | ||
const baseProps = { | ||
button: { action: () => {}, label: "Button" }, | ||
data: null, | ||
error: null, | ||
loading: false, | ||
title: "Title", | ||
}; | ||
const baseOptions = { | ||
props: baseProps, | ||
target: document.body, | ||
}; | ||
|
||
afterEach(cleanup); | ||
|
||
it("should render the `DataCard` in the loading state", () => { | ||
const loading = true; | ||
const { container } = render(DataCard, { | ||
...baseOptions, | ||
props: { ...baseProps, loading }, | ||
}); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
it("should render the `DataCard` in the error state", () => { | ||
const error = new Error("error"); | ||
const { container } = render(DataCard, { | ||
...baseOptions, | ||
props: { ...baseProps, error }, | ||
}); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
it("should render the `DataCard` in the no data state", () => { | ||
const data = new Array(0); | ||
const { container } = render(DataCard, { | ||
...baseOptions, | ||
props: { ...baseProps, data }, | ||
}); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
it("should render the `DataCard` in the data state", () => { | ||
const data = new Array(2); | ||
const renderWithSlots = renderWithSimpleContent(DataCard, { | ||
...baseOptions, | ||
props: { ...baseProps, data }, | ||
}); | ||
|
||
expect(renderWithSlots.container.firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
it("should render the `DataCard` in the data state when loading is true", () => { | ||
const data = new Array(2); | ||
const loading = true; | ||
const renderWithSlots = renderWithSimpleContent(DataCard, { | ||
...baseOptions, | ||
props: { ...baseProps, data, loading }, | ||
}); | ||
|
||
expect(renderWithSlots.container.firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
it("should pass the correct function to the button on click event", async () => { | ||
const onClickMock = vi.fn(); | ||
const button = { action: onClickMock, label: "Back" }; | ||
const { getByRole } = render(DataCard, { | ||
...baseOptions, | ||
props: { ...baseProps, button }, | ||
}); | ||
|
||
await fireEvent.click(getByRole("button")); | ||
|
||
expect(onClickMock).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
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,34 @@ | ||
import { afterEach, describe, expect, it } from "vitest"; | ||
import { cleanup, render } from "@testing-library/svelte"; | ||
|
||
import { renderWithSimpleContent } from "$lib/dusk/test-helpers"; | ||
|
||
import { DataGuard } from ".."; | ||
|
||
describe("DataGuard", () => { | ||
const baseProps = { | ||
data: null, | ||
}; | ||
const baseOptions = { | ||
props: baseProps, | ||
target: document.body, | ||
}; | ||
|
||
afterEach(cleanup); | ||
|
||
it("should render the `DataGuard` with the placeholder if no data is passed", () => { | ||
const { container } = render(DataGuard, baseOptions); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
it("should render the `DataGuard` if data is present", () => { | ||
const data = 1; | ||
const renderWithSlots = renderWithSimpleContent(DataGuard, { | ||
...baseOptions, | ||
props: { ...baseProps, data }, | ||
}); | ||
|
||
expect(renderWithSlots.container.firstChild).toMatchSnapshot(); | ||
}); | ||
}); |
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
33 changes: 33 additions & 0 deletions
33
explorer/src/lib/components/__tests__/TransactionsTable.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,33 @@ | ||
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 { TransactionsTable } from ".."; | ||
import { mapWith, slice } from "lamb"; | ||
|
||
const transformTransactions = mapWith(transformTransaction); | ||
const data = slice(transformTransactions(apiTransactions.data), 0, 10); | ||
|
||
describe("Transactions Table", () => { | ||
vi.useFakeTimers(); | ||
vi.setSystemTime(new Date(2024, 4, 20)); | ||
const baseProps = { | ||
data: data, | ||
}; | ||
const baseOptions = { | ||
props: baseProps, | ||
target: document.body, | ||
}; | ||
|
||
afterEach(cleanup); | ||
|
||
afterAll(() => { | ||
vi.useRealTimers(); | ||
}); | ||
|
||
it("should render the `TransactionsTable` component", () => { | ||
const { container } = render(TransactionsTable, baseOptions); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.