|
1 | 1 | /** @jsxImportSource @opentui/solid */ |
2 | 2 | import { testRender } from "@opentui/solid" |
3 | | -import { afterEach, expect, test } from "bun:test" |
| 3 | +import { expect, test } from "bun:test" |
4 | 4 | import { resetSetupComplete } from "../../src/component/altimate-onboarding" |
5 | 5 | import { WelcomePanel } from "../../src/component/welcome-panel" |
6 | 6 | import { TuiConfigProvider } from "../../src/config" |
@@ -67,31 +67,37 @@ async function renderPanel(availableWidth: number, availableHeight: number) { |
67 | 67 | return { app, frame } |
68 | 68 | } |
69 | 69 |
|
70 | | -let current: Awaited<ReturnType<typeof testRender>> | undefined |
71 | | -afterEach(() => { |
72 | | - current?.renderer.destroy() |
73 | | - current = undefined |
74 | | -}) |
| 70 | +// Own the renderer per test and destroy it in the same test's finally (plus reset |
| 71 | +// onboarding state), so nothing leaks between tests or races under parallel bun test. |
| 72 | +async function withPanel(width: number, height: number, check: (frame: string) => void) { |
| 73 | + const { app, frame } = await renderPanel(width, height) |
| 74 | + try { |
| 75 | + check(frame) |
| 76 | + } finally { |
| 77 | + app.renderer.destroy() |
| 78 | + resetSetupComplete() |
| 79 | + } |
| 80 | +} |
75 | 81 |
|
76 | 82 | test("full variant renders the wordmark + what-is section at a large available size", async () => { |
77 | | - const { app, frame } = await renderPanel(FULL_MIN_WIDTH, FULL_MIN_HEIGHT) |
78 | | - current = app |
79 | | - // "What is Altimate Code" is unique to the full two-column box. |
80 | | - expect(frame).toContain("What is Altimate Code") |
| 83 | + await withPanel(FULL_MIN_WIDTH, FULL_MIN_HEIGHT, (frame) => { |
| 84 | + // "What is Altimate Code" is unique to the full two-column box. |
| 85 | + expect(frame).toContain("What is Altimate Code") |
| 86 | + }) |
81 | 87 | }) |
82 | 88 |
|
83 | 89 | test("medium variant renders the condensed line (no what-is section) below the full width floor", async () => { |
84 | | - const { app, frame } = await renderPanel(FULL_MIN_WIDTH - 1, FULL_MIN_HEIGHT) |
85 | | - current = app |
86 | | - expect(frame).toContain("Gives your AI real context") |
87 | | - expect(frame).not.toContain("What is Altimate Code") |
| 90 | + await withPanel(FULL_MIN_WIDTH - 1, FULL_MIN_HEIGHT, (frame) => { |
| 91 | + expect(frame).toContain("Gives your AI real context") |
| 92 | + expect(frame).not.toContain("What is Altimate Code") |
| 93 | + }) |
88 | 94 | }) |
89 | 95 |
|
90 | 96 | test("compact variant renders a single line below the medium width floor", async () => { |
91 | | - const { app, frame } = await renderPanel(MEDIUM_MIN_WIDTH - 1, FULL_MIN_HEIGHT) |
92 | | - current = app |
93 | | - // Unconnected → the connect CTA; neither the medium nor full body is present. |
94 | | - expect(frame).toContain("Connect your AI model to start") |
95 | | - expect(frame).not.toContain("Gives your AI real context") |
96 | | - expect(frame).not.toContain("What is Altimate Code") |
| 97 | + await withPanel(MEDIUM_MIN_WIDTH - 1, FULL_MIN_HEIGHT, (frame) => { |
| 98 | + // Unconnected → the connect CTA; neither the medium nor full body is present. |
| 99 | + expect(frame).toContain("Connect your AI model to start") |
| 100 | + expect(frame).not.toContain("Gives your AI real context") |
| 101 | + expect(frame).not.toContain("What is Altimate Code") |
| 102 | + }) |
97 | 103 | }) |
0 commit comments