| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | |
| 4 | import { BEAT, CHECKS, LOOP_MS, PILLS, SESSION, SETTLED, STILLS, SUMMARIZED, SUMMARY_WORDS, frameAt, pillAt, pillProgress, sameFrame } from "./tour.ts"; |
| 5 | |
| 6 | test("the first frame is Home before anything settles, the same on the server and the client", () => { |
| 7 | const frame = frameAt(0); |
| 8 | assert.equal(frame.scene, "home"); |
| 9 | assert.equal(frame.settled, 0); |
| 10 | assert.equal(frame.summarizing, false); |
| 11 | assert.equal(frame.checks, 0); |
| 12 | assert.equal(frame.cursorShown, false); |
| 13 | assert.ok(sameFrame(frame, frameAt(0))); |
| 14 | }); |
| 15 | |
| 16 | test("the scenes come in the story's order: Home first", () => { |
| 17 | const order: string[] = []; |
| 18 | for (let t = 0; t < LOOP_MS; t += 100) { |
| 19 | const scene = frameAt(t).scene; |
| 20 | if (order[order.length - 1] !== scene) order.push(scene); |
| 21 | } |
| 22 | assert.deepEqual(order, ["home", "code", "session", "chat"]); |
| 23 | }); |
| 24 | |
| 25 | test("checks pass before review, and the queue merges only after approval", () => { |
| 26 | assert.equal(frameAt(BEAT.approved).checks, CHECKS.length); |
| 27 | assert.equal(frameAt(BEAT.merged - 1).merged, false); |
| 28 | assert.equal(frameAt(BEAT.merged).approved, true); |
| 29 | }); |
| 30 | |
| 31 | test("Home's #431 opens the pull request, and the cursor stays out of its way until it has merged", () => { |
| 32 | assert.equal(frameAt(BEAT.prClick).cursor, "home-pr"); |
| 33 | assert.equal(frameAt(BEAT.prClick).click, true); |
| 34 | assert.equal(frameAt(BEAT.prClick).scene, "home"); |
| 35 | assert.equal(frameAt(BEAT.code).scene, "code"); |
| 36 | assert.equal(frameAt(BEAT.code).checks, 0); |
| 37 | assert.equal(frameAt(BEAT.merged - 1).cursorShown, false); |
| 38 | assert.equal(frameAt(BEAT.sessionClick).cursor, "pr-session"); |
| 39 | assert.equal(frameAt(BEAT.sessionClick).click, true); |
| 40 | assert.equal(frameAt(BEAT.railChatClick).cursor, "rail-chat"); |
| 41 | assert.equal(frameAt(BEAT.railChatClick).click, true); |
| 42 | }); |
| 43 | |
| 44 | test("the session plays back in full before the tour moves on to Chat", () => { |
| 45 | assert.equal(frameAt(BEAT.session - 1).entries, 0); |
| 46 | assert.equal(frameAt(BEAT.railChatClick - 1).entries, SESSION.length); |
| 47 | assert.equal(SESSION[0].kind, "prompt"); |
| 48 | }); |
| 49 | |
| 50 | test("the loop wraps", () => { |
| 51 | assert.ok(sameFrame(frameAt(LOOP_MS + 1234), frameAt(1234))); |
| 52 | assert.ok(sameFrame(frameAt(-1), frameAt(LOOP_MS - 1))); |
| 53 | }); |
| 54 | |
| 55 | test("pills start where their scene does, and progress runs 0 to 1", () => { |
| 56 | assert.equal(PILLS[0].scene, "home"); |
| 57 | PILLS.forEach((pill, index) => { |
| 58 | assert.equal(frameAt(pill.start + 1).scene, pill.scene); |
| 59 | assert.equal(pillAt(pill.start + 1), index); |
| 60 | }); |
| 61 | assert.ok(pillProgress(PILLS[1].start) < 0.01); |
| 62 | assert.ok(pillProgress(PILLS[2].start - 1) > 0.99); |
| 63 | }); |
| 64 | |
| 65 | test("each still shows its step's point", () => { |
| 66 | assert.equal(frameAt(STILLS.code).approved, true); |
| 67 | assert.equal(frameAt(STILLS.session).entries, SESSION.length); |
| 68 | assert.equal(frameAt(STILLS.chat).told, true); |
| 69 | assert.equal(frameAt(STILLS.home).words, SUMMARY_WORDS.length); |
| 70 | assert.equal(frameAt(STILLS.home).cleared, SETTLED.length); |
| 71 | }); |
| 72 | |
| 73 | test("Dana tells support only after Priya says it shipped", () => { |
| 74 | assert.equal(frameAt(BEAT.told - 1).told, false); |
| 75 | assert.equal(frameAt(BEAT.told).shipped, true); |
| 76 | }); |
| 77 | |
| 78 | test("on Home, notifications settle and leave before Summarize, and the summary finishes before #431 is opened", () => { |
| 79 | assert.equal(frameAt(BEAT.settle0 - 1).settled, 0); |
| 80 | const before = frameAt(BEAT.summarizeClick); |
| 81 | assert.equal(before.settled, SETTLED.length); |
| 82 | assert.equal(before.cleared, SETTLED.length); |
| 83 | assert.equal(before.cursor, "home-summarize"); |
| 84 | assert.equal(before.click, true); |
| 85 | assert.equal(frameAt(BEAT.word0 - 1).words, 0); |
| 86 | assert.ok(SUMMARIZED < BEAT.prClick - 700); |
| 87 | assert.equal(frameAt(BEAT.prClick - 1).words, SUMMARY_WORDS.length); |
| 88 | assert.ok(SUMMARY_WORDS.some((word) => word.includes("#431"))); |
| 89 | }); |