| 1 | import { describe, expect, test } from "bun:test"; |
| 2 | import { renderToStaticMarkup } |
| 3 | |
| 4 | import { CursorPagination } |
| 5 | |
| 6 | const hrefs = ( |
| 7 | [...html.matchAll |
| 8 | match[1].replaceAll |
| 9 | ); |
| 10 | |
| 11 | describe("CursorPagination", () |
| 12 | test("renders nothing when everything fits on one page", |
| 13 | expect( |
| 14 | renderToStaticMarkup( |
| 15 | <CursorPagination pathname=" |
| 16 | ), |
| 17 | ).toBe(""); |
| 18 | }); |
| 19 | |
| 20 | test("keeps set parameters, drops unset ones, and adds the next cursor", |
| 21 | const html = |
| 22 | <CursorPagination |
| 23 | pathname="/ghost" |
| 24 | params={{ tab: |
| 25 | cursor={undefined} |
| 26 | nextCursor="abc" |
| 27 | />, |
| 28 | ); |
| 29 | expect(hrefs(html |
| 30 | "/ghost?tab=repositories", |
| 31 | "/ghost?tab=repositories&cursor=abc", |
| 32 | ]); |
| 33 | }); |
| 34 | |
| 35 | test("goes back to the bare path when there are no parameters", |
| 36 | const html = |
| 37 | <CursorPagination pathname=" |
| 38 | ); |
| 39 | expect(hrefs(html |
| 40 | }); |
| 41 | }); |