Public: anyone can read this; the crew can change it.
/explore says how many apps match, in one plain line above the list #14881
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/14854-explore-says-how-many-apps-match-in-one → main 1 commit fork
1 file
changed +65
−0
test/explorer-count.test.ts added +65
| @@ -0,0 +1,65 @@ | ||
| 1 | /** | |
| 2 | * The /explore count line and the rows under it come from one list: with two filters stacked they | |
| 3 | * agree. | |
| 4 | */ | |
| 5 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 6 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 7 | import { tmpdir } from "node:os"; | |
| 8 | import { join } from "node:path"; | |
| 9 | import { createApp, type App } from "../src/app.ts"; | |
| 10 | import { createRepo } from "../src/actions/repos.ts"; | |
| 11 | import { createApp as insertApp } from "../src/core/apps.ts"; | |
| 12 | import { createUser } from "../src/core/users.ts"; | |
| 13 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 14 | import { quietLogs } from "./helpers/globals.ts"; | |
| 15 | import { proveAll } from "./helpers/verified.ts"; | |
| 16 | import { promote } from "./helpers/members.ts"; | |
| 17 | ||
| 18 | quietLogs(); | |
| 19 | let dir: string; | |
| 20 | let app: App; | |
| 21 | let servers: Servers; | |
| 22 | ||
| 23 | beforeAll(async () => { | |
| 24 | dir = await mkdtemp(join(tmpdir(), "forge-explorer-count-")); | |
| 25 | app = createApp({ dataDir: dir, port: 0 }); | |
| 26 | const made = await createUser(app.db, { origin: "seed", username: "olive", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: false }); | |
| 27 | if (!made.ok) throw new Error(made.error); | |
| 28 | proveAll(app); | |
| 29 | promote(app.db, made.value); | |
| 30 | for (const n of ["garden-one", "garden-two", "garden-three", "ledger"]) { | |
| 31 | const repo = await createRepo(app, made.value, { name: n, visibility: "public" }); | |
| 32 | if (!repo.ok) throw new Error(String(repo.error)); | |
| 33 | const rec = insertApp(app.db, { repoId: repo.value.id, slug: `olive-${n}`, access: "public" }); | |
| 34 | if (!rec.ok) throw new Error(rec.error); | |
| 35 | } | |
| 36 | servers = await serve(app); | |
| 37 | }, 60_000); | |
| 38 | afterAll(async () => { | |
| 39 | await servers.stop(); | |
| 40 | app.db.close(); | |
| 41 | await rm(dir, { recursive: true, force: true }); | |
| 42 | }); | |
| 43 | ||
| 44 | const get = async (path: string) => (await fetch(`${servers.url}${path}`)).text(); | |
| 45 | const line = (html: string) => html.match(/data-hits[^>]*>([^<]*)/)?.[1]?.trim() ?? ""; | |
| 46 | const cards = (html: string) => (html.match(/<ul class="list">([\s\S]*?)<\/ul>/)?.[1] ?? "").split("<li").length - 1; | |
| 47 | ||
| 48 | test("two filters stacked: the line's number is the number of cards", async () => { | |
| 49 | const html = await get("/explore?q=" + encodeURIComponent("kind:app owner:olive garden")); | |
| 50 | expect(cards(html)).toBe(3); | |
| 51 | expect(line(html)).toMatch(/^3 apps/); | |
| 52 | }); | |
| 53 | ||
| 54 | test("two filters leaving one say '1 app', and one card", async () => { | |
| 55 | const html = await get("/explore?q=" + encodeURIComponent("kind:app owner:olive ledger")); | |
| 56 | expect(cards(html)).toBe(1); | |
| 57 | expect(line(html)).toMatch(/^1 app\b(?!s)/); | |
| 58 | }); | |
| 59 | ||
| 60 | test("two filters leaving none: no cards, never null, a link that clears them", async () => { | |
| 61 | const html = await get("/explore?q=" + encodeURIComponent("kind:app owner:olive zzzzqqq")); | |
| 62 | expect(cards(html)).toBe(0); | |
| 63 | expect(line(html)).not.toContain("null"); | |
| 64 | expect(html).toMatch(/<a href="\/explore" data-clear-filters>Clear filters<\/a>/); | |
| 65 | }); |
new above
offline