learn and share notes on atproto (wip) 馃 malfestio.stormlightlabs.org/
readability solid axum atproto srs
at main 56 lines 1.9 kB view raw
1import { api } from "$lib/api"; 2import Library from "$pages/Library"; 3import { cleanup, render, screen, waitFor } from "@solidjs/testing-library"; 4import type { JSX } from "solid-js"; 5import { afterEach, describe, expect, it, type Mock, vi } from "vitest"; 6 7vi.mock("$lib/api", () => ({ api: { search: vi.fn() } })); 8 9vi.mock( 10 "@solidjs/router", 11 () => ({ A: (props: { href: string; children: JSX.Element }) => <a href={props.href}>{props.children}</a> }), 12); 13 14describe("Library page", () => { 15 afterEach(cleanup); 16 17 it("renders loading state initially", () => { 18 (api.search as Mock).mockReturnValue(new Promise(() => {})); 19 const { container } = render(() => <Library />); 20 expect(container.querySelector(".animate-spin")).toBeInTheDocument(); 21 }); 22 23 it("renders remote decks when loaded", async () => { 24 (api.search as Mock).mockResolvedValue({ 25 ok: true, 26 json: 27 async () => [{ 28 item_type: "deck", 29 item_id: "deck1", 30 creator_did: "did:plc:other", 31 data: { 32 title: "Federated Deck", 33 description: "From another server", 34 tags: ["remote"], 35 at_uri: "at://did:plc:other/org.stormlightlabs.malfestio.deck/deck1", 36 }, 37 rank: 1, 38 source: "remote", 39 }], 40 }); 41 42 render(() => <Library />); 43 44 await waitFor(() => expect(screen.getByText("Federated Deck")).toBeInTheDocument()); 45 expect(screen.getByText("by did:plc:othe...")).toBeInTheDocument(); 46 expect(screen.getByText("#remote")).toBeInTheDocument(); 47 }); 48 49 it("renders empty state when no content", async () => { 50 (api.search as Mock).mockResolvedValue({ ok: true, json: async () => [] }); 51 52 render(() => <Library />); 53 54 await waitFor(() => expect(screen.getByText("No federated content found")).toBeInTheDocument()); 55 }); 56});