diff --git a/packages/bits-ui/src/tests/pagination/Pagination.spec.ts b/packages/bits-ui/src/tests/pagination/Pagination.spec.ts index 551da7901..b1242dbe1 100644 --- a/packages/bits-ui/src/tests/pagination/Pagination.spec.ts +++ b/packages/bits-ui/src/tests/pagination/Pagination.spec.ts @@ -1,13 +1,11 @@ -// NOTE: these tests were shamelessly copied from melt-ui 🥲 import { render } from "@testing-library/svelte"; -import { userEvent } from "@testing-library/user-event"; import { axe } from "jest-axe"; -import PaginationTest from "./PaginationTest.svelte"; -import type { Pagination } from "$lib/index.js"; +import PaginationTest, { type PaginationTestProps } from "./PaginationTest.svelte"; import { isHTMLElement } from "$lib/internal/is.js"; +import { setupUserEvents } from "../utils.js"; -function setup(props: Pagination.Props = { count: 100 }) { - const user = userEvent.setup(); +function setup(props: PaginationTestProps = { count: 100 }) { + const user = setupUserEvents(); const returned = render(PaginationTest, { ...props }); const root = returned.getByTestId("root"); @@ -44,31 +42,31 @@ describe("pagination", () => { }); it("previous and Next button should work accordingly", async () => { - const { root, prev, next } = setup(); + const { root, prev, next, user } = setup(); - await expect(getValue(root)).toBe("1"); - await prev.click(); - await expect(getValue(root)).toBe("1"); - await next.click(); - await expect(getValue(root)).toBe("2"); - await next.click(); - await expect(getValue(root)).toBe("3"); - await prev.click(); - await expect(getValue(root)).toBe("2"); + expect(getValue(root)).toBe("1"); + await user.click(prev); + expect(getValue(root)).toBe("1"); + await user.click(next); + expect(getValue(root)).toBe("2"); + await user.click(next); + expect(getValue(root)).toBe("3"); + await user.click(prev); + expect(getValue(root)).toBe("2"); }); it("should change on clicked button", async () => { - const { getByTestId } = await render(PaginationTest); + const { getByTestId, user } = setup(); const root = getByTestId("root"); const page2 = getPageButton(root, 2); - await expect(getValue(root)).toBe("1"); - await page2.click(); - await expect(getValue(root)).toBe("2"); + expect(getValue(root)).toBe("1"); + await user.click(page2); + expect(getValue(root)).toBe("2"); const page10 = getPageButton(root, 10); - await page10.click(); - await expect(getValue(root)).toBe("10"); + await user.click(page10); + expect(getValue(root)).toBe("10"); }); }); diff --git a/packages/bits-ui/src/tests/pagination/PaginationTest.svelte b/packages/bits-ui/src/tests/pagination/PaginationTest.svelte index 58206f978..552ba0b01 100644 --- a/packages/bits-ui/src/tests/pagination/PaginationTest.svelte +++ b/packages/bits-ui/src/tests/pagination/PaginationTest.svelte @@ -1,31 +1,33 @@ - - export let count: $$Props["count"] = 100; - export let perPage: $$Props["perPage"] = 10; +
- -

Showing items {range.start} - {range.end}

-
- - - - {#each pages as page (page.key)} - {#if page.type === "ellipsis"} - ... - {:else if page.type === "page"} - - {page.value} - - {/if} - {/each} - - →; - -
+ + {#snippet children({ pages, range })} +

Showing items {range.start} - {range.end}

+
+ + + + {#each pages as page (page.key)} + {#if page.type === "ellipsis"} + ... + {:else if page.type === "page"} + + {page.value} + + {/if} + {/each} + + →; + +
+ {/snippet}