Skip to content
Myr

propose.test.tsx

This file

Path

apps/web/test/propose.test.tsx

256 lines · 7.6 KiB · TypeScript

Last changed by

Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571

History of this file

Take it

Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9

lines 1–4why, one step back
1import { describe, expect, it } from "@effect/vitest";
2import { Brand } from "@repo/brand";3import { ProposeAsk } from "@repo/protocol/contracts";4import { CommitSha, ProjectName, RepoPath } from "@repo/protocol/ids";

Merge build/1008oscabrielbefore adoption7de721c

line 5why, one step back
5import { Unauthenticated } from "@repo/protocol/principal";

Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9

line 6why, one step back
6import { CapReached } from "@repo/protocol/refusal";

Merge build/1008oscabrielbefore adoption7de721c

line 7why, one step back
7import { Cause, Option, Schema } from "effect";

Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9

lines 8–10why, one step back
8import { AsyncResult } from "effect/reactivity";
910import { proposalMade, topFolders } from "../src/client/propose.ts";

Merge build/1008oscabrielbefore adoption7de721c

line 11why, one step back
11import { ProposalFailure } from "../src/features/proposal/failure.tsx";

Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9

lines 12–14why, one step back
12import {
13 ProposeView,14 proposalPayload,

Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2

line 15why, one step back
15 territoryChoices,

Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9

lines 16–19why, one step back
16} from "../src/features/propose/propose-view.tsx";
17import type { About } from "../src/features/propose/propose-view.tsx";18import { markupOf, plainText } from "./ask-fixtures.ts";19

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

line 20why, one step back
20const datekit = ProjectName.make("oscabriel/datekit");

Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9

lines 21–44why, one step back
21
22const at = CommitSha.make("4c2e6a8b0d2f4a6c8e0b2d4f6a8c0e2b4d6f8a0c");2324const modules = [RepoPath.make("docs"), RepoPath.make("src")];2526const signedIn = (about: Option.Option<About> = Option.none()) =>27 markupOf(28 <ProposeView about={about} modules={modules} project={datekit} signedIn />29 );3031const textareaOf = (markup: string) =>32 /<textarea[^>]*>(?<text>[^<]*)<\/textarea>/u.exec(markup);3334describe(ProposeView, () => {35 it("signed in, offers a want and the draft box, checked", () => {36 const markup = signedIn();3738 expect(textareaOf(markup)?.[0]).toContain('name="want"');39 expect(markup).toMatch(40 /role="checkbox"[^>]*aria-checked="true"|aria-checked="true"[^>]*role="checkbox"/u41 );42 expect(plainText(markup)).toContain(43 "Let the platform's agent draft the ask"44 );

Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2

line 45why, one step back
45 expect(markup).toMatch(/<button[^>]*type="submit"/u);

Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9

lines 46–47why, one step back
46 });
47

Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2

lines 48–66why, one step back
48 it("says on Propose why it waits, until there is a want", () => {
49 const empty = signedIn();5051 const written = signedIn(52 Option.some({ at, line: 12, path: RepoPath.make("src/format.ts") })53 );5455 expect(empty).toMatch(56 /<button(?=[^>]*disabled="")(?=[^>]*type="submit")[^>]*>Write the want first<\/button>/u57 );58 expect(written).toMatch(59 /<button[^>]*type="submit"[^>]*>Propose<\/button>/u60 );61 expect(written).not.toMatch(62 /<button(?=[^>]*disabled="")(?=[^>]*type="submit")/u63 );64 });6566 it("offers each of the project's top folders as the territory, through the kit's select, never a native one", () => {

Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9

lines 67–69why, one step back
67 const markup = signedIn();
6869 expect(markup).toContain('name="territory"');

Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2

lines 70–76why, one step back
70 expect(markup).not.toContain("<select");
71 expect(markup).toContain('data-slot="select-trigger"');72 expect(territoryChoices(modules)).toStrictEqual([73 { label: "Let the agent choose", value: "" },74 { label: "docs", value: "docs" },75 { label: "src", value: "src" },76 ]);

Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9

lines 77–78why, one step back
77 });
78

Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2

lines 79–85why, one step back
79 it("gives the same proposal as a command, and what makes a good want", () => {
80 const text = plainText(signedIn());8182 expect(text).toContain(`${Brand.cli} propose --draft "<want>"`);83 expect(text).toContain("not how to change the code");84 });85

Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9

lines 86–108why, one step back
86 it("starts the want at the line a why page names", () => {
87 const markup = signedIn(88 Option.some({ at, line: 12, path: RepoPath.make("src/format.ts") })89 );9091 expect(textareaOf(markup)?.groups?.text).toBe(92 "In `src/format.ts` line 12 at 4c2e6a8: "93 );94 });9596 it("signed out, shows no form and links to sign in", () => {97 const markup = markupOf(98 <ProposeView99 about={Option.none()}100 modules={modules}101 project={datekit}102 signedIn={false}103 />104 );105106 expect(markup).not.toContain("<form");107 expect(markup).not.toContain("<textarea");108 expect(markup).toMatch(/<a[^>]*href="\/auth\/signin[^"]*"[^>]*>Sign in/u);

Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2

lines 109–111why, one step back
109 expect(plainText(markup)).toContain(
110 `${Brand.cli} propose --draft "<want>"`111 );

Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9

lines 112–126why, one step back
112 });
113});114115describe(proposalPayload, () => {116 const isPayload = Schema.is(ProposeAsk.payloadSchema);117118 it("asks for a draft when the box is checked", () => {119 const payload = proposalPayload({120 draft: true,121 project: datekit,122 want: " formatISO keeps the offset. ",123 });124125 expect(payload).toStrictEqual({126 draft: true,

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

line 127why, one step back
127 project: "oscabriel/datekit",

Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9

lines 128–141why, one step back
128 want: "formatISO keeps the offset.",
129 });130 expect(isPayload(payload)).toBeTruthy();131 });132133 it("carries no draft key when the box is clear, and the territory when named", () => {134 const payload = proposalPayload({135 draft: false,136 project: datekit,137 territory: RepoPath.make("src"),138 want: "formatISO keeps the offset.",139 });140141 expect(payload).toStrictEqual({

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

line 142why, one step back
142 project: "oscabriel/datekit",

Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9

lines 143–229why, one step back
143 territory: "src",
144 want: "formatISO keeps the offset.",145 });146 expect(Object.hasOwn(payload, "draft")).toBeFalsy();147 });148});149150describe(topFolders, () => {151 it("offers each top folder once, sorted, and no dot folder or root file", () => {152 expect(153 topFolders(154 [155 "src/format.ts",156 "README.md",157 `${Brand.configDir}/asks/x.ask.ts`,158 "test/format.test.ts",159 "src/parse/iso.ts",160 ".github/workflows/ci.yml",161 "docs/guide.md",162 ].map((path) => RepoPath.make(path))163 )164 ).toStrictEqual(["docs", "src", "test"]);165 });166});167168const made = (id: string) =>169 Schema.decodeUnknownSync(ProposeAsk.successSchema)({170 proposal: {171 expiresAt: "2026-10-21T09:00:00.000Z",172 files: [],173 id,174 openedAt: "2026-10-07T09:00:00.000Z",175 project: "datekit",176 proposer: "lin-h",177 state: "open",178 want: "formatISO keeps the offset.",179 },180 });181182describe(proposalMade, () => {183 const earlier = AsyncResult.success(made("prop-000004"));184185 it("names the proposal a send made, once it answered", () => {186 expect(187 proposalMade(AsyncResult.success(made("prop-000005")))188 ).toStrictEqual(Option.some("prop-000005"));189 });190191 it("names none while a later send is on its way, or after it was refused", () => {192 expect(proposalMade(AsyncResult.waiting(earlier))).toStrictEqual(193 Option.none()194 );195 expect(196 proposalMade(197 AsyncResult.fail(new CapReached({ cap: 3 }), {198 previousSuccess: Option.some(earlier),199 })200 )201 ).toStrictEqual(Option.none());202 });203});204205describe("the sign-in link", () => {206 it("comes back to the form, at the line a why page named", () => {207 const markup = markupOf(208 <ProposeView209 about={Option.some({210 at,211 line: 12,212 path: RepoPath.make("src/format.ts"),213 })}214 modules={modules}215 project={datekit}216 signedIn={false}217 />218 );219220 const href = /href="(?<href>\/auth\/signin[^"]*)"/u221 .exec(markup)222 ?.groups?.href?.replaceAll("&amp;", "&");223224 const back = new URL(href ?? "/", "https://web.test").searchParams.get(225 "return"226 );227228 const there = new URL(back ?? "/", "https://web.test");229

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

line 230why, one step back
230 expect(there.pathname).toBe("/oscabriel/datekit/proposals/new");

Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9

lines 231–235why, one step back
231 expect(Object.fromEntries(there.searchParams)).toStrictEqual({
232 about: "src/format.ts",233 at,234 line: "12",235 });

Merge build/1008oscabrielbefore adoption7de721c

lines 236–240why, one step back
236 });
237});238239describe("a refused send on the propose form", () => {240 it("with no session, asks to sign in and come back to the form as it was", () => {

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

line 241why, one step back
241 const here = `/oscabriel/datekit/proposals/new?about=src%2Fformat.ts&at=${at}&line=12`;

Merge build/1008oscabrielbefore adoption7de721c

lines 242–251why, one step back
242
243 const markup = markupOf(244 <ProposalFailure245 cause={Cause.fail(new Unauthenticated({}))}246 doing="propose it"247 here={here}248 />249 );250251 expect(markup).toContain(

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

line 252why, one step back
252 `href="/auth/signin?return=%2Foscabriel%2Fdatekit%2Fproposals%2Fnew%3Fabout%3Dsrc%252Fformat.ts%26at%3D${at}%26line%3D12"`

Merge build/1008oscabrielbefore adoption7de721c

line 253why, one step back
253 );

Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571

line 254why, one step back
254 expect(plainText(markup)).not.toContain("Today is a maintainer's page");

Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9

lines 255–256why, one step back
255 });
256});