The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { resolveContextStripLabelsCompact } from "./BranchToolbar.logic"; |
| 4 | import { |
| 5 | resolveRestingComposerControlsLayout, |
| 6 | resolveRestingComposerControlsNaturalWidth, |
| 7 | } from "./composerFooterLayout"; |
| 8 | |
| 9 | describe("context strip labels and resting composer controls", () => { |
| 10 | const stripWidth = 724; |
| 11 | const labelWidth = 327; |
| 12 | const chromeWidth = 125; |
| 13 | const measurement = { |
| 14 | gap: 4, |
| 15 | naturalFixedWidth: 96.3828125 + 5 + 4, |
| 16 | minimumFixedWidth: 52 + 5 + 4, |
| 17 | blockWidths: [130.6953125, 119.671875], |
| 18 | overflowWidth: 28, |
| 19 | }; |
| 20 | const naturalWidth = resolveRestingComposerControlsNaturalWidth(measurement); |
| 21 | |
| 22 | function hostWidth(compact: boolean): number { |
| 23 | return stripWidth - chromeWidth - (compact ? 0 : labelWidth); |
| 24 | } |
| 25 | |
| 26 | it("keeps the labels compact when the full controls only fit beside compact labels", () => { |
| 27 | const layout = resolveRestingComposerControlsLayout({ |
| 28 | ...measurement, |
| 29 | hostWidth: hostWidth(true), |
| 30 | }); |
| 31 | expect(layout).toEqual({ hiddenCount: 0, visible: true }); |
| 32 | |
| 33 | const compact = resolveContextStripLabelsCompact({ |
| 34 | compact: true, |
| 35 | neededWidth: chromeWidth + labelWidth + naturalWidth, |
| 36 | availableWidth: stripWidth, |
| 37 | }); |
| 38 | expect(compact).toBe(true); |
| 39 | |
| 40 | expect( |
| 41 | resolveRestingComposerControlsLayout({ ...measurement, hostWidth: hostWidth(compact) }), |
| 42 | ).toEqual(layout); |
| 43 | }); |
| 44 | }); |
| 45 | |
| 46 | describe("resolveRestingComposerControlsLayout hysteresis", () => { |
| 47 | const base = { |
| 48 | gap: 4, |
| 49 | naturalFixedWidth: 149, |
| 50 | minimumFixedWidth: 105, |
| 51 | blockWidths: [60, 140], |
| 52 | overflowWidth: 24, |
| 53 | }; |
| 54 | |
| 55 | it("settles when the measured picker width jitters below a pixel", () => { |
| 56 | let layout = { hiddenCount: 0, visible: true }; |
| 57 | const settled: string[] = []; |
| 58 | for (let index = 0; index < 10; index += 1) { |
| 59 | layout = resolveRestingComposerControlsLayout({ |
| 60 | ...base, |
| 61 | naturalFixedWidth: index % 2 === 0 ? 149 : 149.5, |
| 62 | hostWidth: 357, |
| 63 | previous: layout, |
| 64 | }); |
| 65 | if (index >= 2) settled.push(`${layout.hiddenCount}:${layout.visible}`); |
| 66 | } |
| 67 | expect(new Set(settled).size).toBe(1); |
| 68 | }); |
| 69 | }); |
| 70 | |
| 71 | describe("progressive composer controls", () => { |
| 72 | const measurement = { |
| 73 | gap: 4, |
| 74 | naturalFixedWidth: 140, |
| 75 | minimumFixedWidth: 80, |
| 76 | blockWidths: [80, 140], |
| 77 | iconOnlyBlockWidths: [40, 60], |
| 78 | overflowWidth: 24, |
| 79 | }; |
| 80 | |
| 81 | it("settles through fractional label-width changes at each threshold", () => { |
| 82 | for (const hostWidth of [368, 288, 248]) { |
| 83 | let previous = resolveRestingComposerControlsLayout({ ...measurement, hostWidth }); |
| 84 | for (let index = 0; index < 10; index += 1) { |
| 85 | const next = resolveRestingComposerControlsLayout({ |
| 86 | ...measurement, |
| 87 | hostWidth, |
| 88 | previous, |
| 89 | naturalFixedWidth: 140 + (index % 2) * 0.5, |
| 90 | }); |
| 91 | if (index > 1) expect(next).toEqual(previous); |
| 92 | previous = next; |
| 93 | } |
| 94 | } |
| 95 | }); |
| 96 | }); |