explore.test.tsx
This file
Path
apps/web/test/explore.test.tsx
213 lines · 6.8 KiB · TypeScript
Last changed by
Merge redesign into mainoscabrielbefore adoptioncaedd21
History of this fileTake it
Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 1–213why, one step back1import { describe, expect, it } from "@effect/vitest";2import { ProjectListing } from "@repo/protocol/domain/front-page";3import { ProjectName } from "@repo/protocol/ids";4import { DateTime, Effect, Schema } from "effect";56import { ExploreView } from "../src/features/explore/explore-page.tsx";7import { exploreGroups } from "../src/features/explore/groups.ts";8import { LandingProjects } from "../src/features/landing/projects.ts";9import { readEveryProject } from "../src/features/landing/read.ts";10import { fixturesClient } from "./dev-client.ts";11import { TEN_LISTED } from "./listings.ts";12import { textIn } from "./markup.ts";13import { unreachablePlatform } from "./platform.ts";14import { renderAt } from "./render.tsx";1516const DATEKIT_LINE =17 "Small, dependency-free date helpers: parse, format, add and diff.";1819const listedIn = (read: LandingProjects) =>20 LandingProjects.match(read, {21 Listed: ({ projects }) => projects,22 Unreachable: () => [],23 });2425const decodeListing = Schema.decodeSync(ProjectListing);2627const at = (iso: string) => DateTime.makeUnsafe(iso);2829/** An import adopted from its source, landed on and taking no answers. */30const click = decodeListing({31 description: "Python composable command line interface toolkit.",32 landedAt: "2026-10-12T09:00:00.000Z",33 openAsks: 0,34 posture: "open",35 project: "github.com/pallets/click",36});3738/** Markup before and after the group of projects taking no answers. */39const groupsIn = (markup: string) => {40 const [taking = "", rest = ""] = markup.split('data-group="rest"');4142 return { rest, taking };43};4445const explored = (projects: readonly ProjectListing[]) =>46 renderAt(47 "/explore",48 <ExploreView projects={LandingProjects.cases.Listed.make({ projects })} />49 );5051describe("Explore, read on the server", () => {52 it.live(53 "lists datekit with its README's first paragraph as its description, and its count of landings",54 () =>55 Effect.gen(function* () {56 const datekit = listedIn(yield* readEveryProject).find(57 ({ project }) => project === "oscabriel/datekit"58 );5960 expect(datekit?.description).toBe(DATEKIT_LINE);61 expect(datekit?.landings).toBeGreaterThan(0);62 }).pipe(Effect.provide(fixturesClient()), Effect.scoped),63 60_00064 );6566 it.effect("is unreachable, never a failed page, when the platform is", () =>67 Effect.gen(function* () {68 const read = yield* readEveryProject.pipe(69 Effect.provide(unreachablePlatform)70 );7172 expect(read._tag).toBe("Unreachable");73 })74 );7576 it("is one page for every reader, which the edge may keep", () => {77 // `branchPage`'s value is cache-headers.test.ts's to pin.78 const routes: Readonly<Record<string, string>> = import.meta.glob(79 "../src/routes/explore.tsx",80 { eager: true, import: "default", query: "?raw" }81 );8283 expect(84 Object.values(routes).map((source) =>85 source.replaceAll(/\s+/gu, " ").includes("headers: () => branchPage")86 )87 ).toStrictEqual([true]);88 });89});9091describe(exploreGroups, () => {92 it("puts the projects taking answers first, each group by its latest landing", () => {93 const { rest, taking } = exploreGroups([94 {95 openAsks: 2,96 posture: "open",97 project: ProjectName.make("oscabriel/alpha"),98 },99 {100 landedAt: at("2026-10-12T08:00:00Z"),101 openAsks: 1,102 posture: "open",103 project: ProjectName.make("oscabriel/datekit"),104 },105 {106 landedAt: at("2026-10-12T10:00:00Z"),107 openAsks: 0,108 posture: "open",109 project: ProjectName.make("oscabriel/zeta"),110 },111 {112 landedAt: at("2026-10-12T11:00:00Z"),113 openAsks: 4,114 posture: "open",115 project: ProjectName.make("oscabriel/burrow"),116 },117 ]);118119 expect(taking.map(({ project }) => project)).toStrictEqual([120 "oscabriel/burrow",121 "oscabriel/datekit",122 "oscabriel/alpha",123 ]);124 expect(rest.map(({ project }) => project)).toStrictEqual([125 "oscabriel/zeta",126 ]);127 });128});129130describe(ExploreView, () => {131 it.live(132 "draws datekit and burrow under taking answers now, and an import after them",133 () =>134 Effect.gen(function* () {135 const projects = listedIn(yield* readEveryProject);136137 const { rest, taking } = groupsIn(138 yield* explored([...projects, click])139 );140141 expect(textIn(taking)).toContain("Taking answers now");142 expect(taking).toContain('data-project="oscabriel/datekit"');143 expect(taking).toContain('data-project="oscabriel/burrow"');144 expect(rest).toContain('data-project="github.com/pallets/click"');145 expect(rest).not.toContain('data-project="oscabriel/datekit"');146 }).pipe(Effect.provide(fixturesClient()), Effect.scoped),147 60_000148 );149150 it.effect(151 "shows a card's full name, description, posture, open asks, landings and last landing",152 () =>153 Effect.gen(function* () {154 const datekit = decodeListing({155 description: DATEKIT_LINE,156 landedAt: "2026-10-12T09:00:00.000Z",157 landings: 12,158 openAsks: 3,159 posture: "openWithSealedEvidence",160 project: "oscabriel/datekit",161 });162163 const [, card = ""] = (yield* explored([datekit])).split(164 'data-project="oscabriel/datekit"'165 );166167 expect(textIn(card)).toContain("oscabriel/datekit");168 expect(textIn(card)).toContain(DATEKIT_LINE);169 expect(card).toContain('data-posture="openWithSealedEvidence"');170 expect(171 ["3 open asks", "12 landings", "Last landed Oct 12, 2026"].filter(172 (fact) => !textIn(card).includes(fact)173 )174 ).toStrictEqual([]);175 })176 );177178 it.effect(179 "says when no project takes answers, and when a project has not landed, with no count of landings",180 () =>181 Effect.gen(function* () {182 const markup = yield* explored([183 {184 openAsks: 0,185 posture: "open",186 project: ProjectName.make("oscabriel/zeta"),187 },188 ]);189190 expect(textIn(markup)).toContain(191 "No project has an open ask right now."192 );193 expect(textIn(markup)).toContain("No open asks");194 expect(textIn(markup)).toContain("No landing yet");195 expect(textIn(markup)).not.toMatch(/\d+ landings?/u);196 })197 );198199 it.effect("links each project to its own page under its full name", () =>200 Effect.gen(function* () {201 const markup = yield* explored(TEN_LISTED);202203 const hrefs = [204 ...markup.matchAll(/<a\b[^>]*href="(?<href>[^"]+)"[^>]*>/gu),205 ].flatMap(({ groups }) => groups?.href ?? []);206207 expect(textIn(markup)).toContain("Explore");208 expect(hrefs).toStrictEqual(209 expect.arrayContaining(TEN_LISTED.map(({ project }) => `/${project}`))210 );211 })212 );213});