| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | |
| 4 | import { BEAT, CHECKS, LOOP_MS, PILLS, STEPS, STILLS, frameAt, pillAt, pillProgress, sameFrame } from "./tour.ts"; |
| 5 | |
| 6 | test("the first frame is the pull request before its checks, the same on the server and the client", () => { |
| 7 | const frame = frameAt(0); |
| 8 | assert.equal(frame.scene, "code"); |
| 9 | assert.equal(frame.checks, 0); |
| 10 | assert.equal(frame.merged, false); |
| 11 | assert.equal(frame.cursorShown, false); |
| 12 | assert.ok(sameFrame(frame, frameAt(0))); |
| 13 | }); |
| 14 | |
| 15 | test("the scenes come in the story's order: Code first", () => { |
| 16 | const order: string[] = []; |
| 17 | for (let t = 0; t < LOOP_MS; t += 100) { |
| 18 | const scene = frameAt(t).scene; |
| 19 | if (order[order.length - 1] !== scene) order.push(scene); |
| 20 | } |
| 21 | assert.deepEqual(order, ["code", "chat", "agents", "docs"]); |
| 22 | }); |
| 23 | |
| 24 | test("checks pass before review, and the queue merges only after approval", () => { |
| 25 | assert.equal(frameAt(BEAT.approved).checks, CHECKS.length); |
| 26 | assert.equal(frameAt(BEAT.merged - 1).merged, false); |
| 27 | assert.equal(frameAt(BEAT.merged).approved, true); |
| 28 | }); |
| 29 | |
| 30 | test("the cursor leaves the code only once it has merged", () => { |
| 31 | assert.equal(frameAt(BEAT.merged - 1).cursorShown, false); |
| 32 | assert.equal(frameAt(BEAT.railChatClick).cursor, "rail-chat"); |
| 33 | assert.equal(frameAt(BEAT.railChatClick).click, true); |
| 34 | }); |
| 35 | |
| 36 | test("Otto's work is done before the story opens", () => { |
| 37 | for (const t of [0, BEAT.chat, BEAT.agents]) assert.equal(frameAt(t).steps, STEPS.length); |
| 38 | }); |
| 39 | |
| 40 | test("the loop wraps", () => { |
| 41 | assert.ok(sameFrame(frameAt(LOOP_MS + 1234), frameAt(1234))); |
| 42 | assert.ok(sameFrame(frameAt(-1), frameAt(LOOP_MS - 1))); |
| 43 | }); |
| 44 | |
| 45 | test("pills start where their scene does, and progress runs 0 to 1", () => { |
| 46 | assert.equal(PILLS[0].scene, "code"); |
| 47 | PILLS.forEach((pill, index) => { |
| 48 | assert.equal(frameAt(pill.start + 1).scene, pill.scene); |
| 49 | assert.equal(pillAt(pill.start + 1), index); |
| 50 | }); |
| 51 | assert.ok(pillProgress(PILLS[1].start) < 0.01); |
| 52 | assert.ok(pillProgress(PILLS[2].start - 1) > 0.99); |
| 53 | }); |
| 54 | |
| 55 | test("each still shows its step's point", () => { |
| 56 | assert.equal(frameAt(STILLS.code).approved, true); |
| 57 | assert.equal(frameAt(STILLS.chat).sam, true); |
| 58 | assert.equal(frameAt(STILLS.agents).scene, "agents"); |
| 59 | assert.equal(frameAt(STILLS.docs).docUpdated, true); |
| 60 | }); |
| 61 | |
| 62 | test("Sam tells #support after g1t says it shipped", () => { |
| 63 | assert.equal(frameAt(BEAT.sam - 1).sam, false); |
| 64 | assert.equal(frameAt(BEAT.sam).shipped, true); |
| 65 | }); |