-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.test.tsx
More file actions
1575 lines (1413 loc) · 52.8 KB
/
Copy pathApp.test.tsx
File metadata and controls
1575 lines (1413 loc) · 52.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// @vitest-environment jsdom
import {
cleanup,
fireEvent,
render,
screen,
} from "@testing-library/react";
import { OsEventTypeList } from "@evenrealities/even_hub_sdk";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { App } from "./App";
import {
createInitialLiveDashboardState,
type LiveDashboardState,
} from "./live-state";
import { diagnosticLogger } from "./diagnostic-log";
type RefreshTarget = "left" | "right" | "right-top" | "all";
type FastInput =
| "tap"
| "double-tap"
| "scroll-next"
| "scroll-previous";
type FastInputResult = "unhandled" | "consume" | "redraw";
type FastTestOptions = {
readonly beforeExternalRefresh?: () => void | Promise<void>;
readonly displayHideStrategy?: "black-tiles" | "blank-rebuild";
readonly imageSendConcurrency?: 1 | 2 | 3 | 4;
readonly tileImageFormat?: "png" | "bmp-1";
readonly tilePaletteMode?: "original" | "hud-4";
readonly onBattery?: (battery: {
readonly label: "G1" | "G2" | "R1";
readonly level?: number;
readonly charging?: boolean;
} | undefined) => void;
readonly onDisplayCommitted?: (minute: number) => void;
readonly onInput?: (
input: FastInput,
) => FastInputResult | Promise<FastInputResult>;
readonly onRawEvent?: (event: {
readonly count: number;
readonly hidden: boolean;
readonly sysEventType?: OsEventTypeList;
readonly textEventType?: OsEventTypeList;
readonly eventSource?: number;
}) => void;
readonly onRefreshReady?: (
request: (target: RefreshTarget) => void,
) => void;
};
type SessionTestOptions = {
readonly canRefreshNews?: () => boolean;
readonly onUpdate: (update: {
readonly state: LiveDashboardState;
readonly target: RefreshTarget;
}) => void;
};
function deferred<T>() {
let resolve!: (value: T) => void;
const promise = new Promise<T>((next) => {
resolve = next;
});
return { promise, resolve };
}
function fastOptions(): FastTestOptions {
const calls = mocks.transmitFast.mock.calls as unknown as Array<
[unknown, unknown, unknown, FastTestOptions]
>;
return calls[0][3];
}
function sessionOptions(): SessionTestOptions {
const calls = mocks.createSession.mock.calls as unknown as Array<
[SessionTestOptions]
>;
return calls[0][0];
}
const mocks = vi.hoisted(() => ({
createSession: vi.fn(),
drawDetail: vi.fn(),
drawFast: vi.fn(),
drawFullscreen: vi.fn(),
drawLocale: vi.fn(),
getRoutingStatus: vi.fn(),
minuteStart: vi.fn(),
searchDestinations: vi.fn(),
transmitFast: vi.fn(),
waitForBridge: vi.fn(),
}));
vi.mock("./fast-detail-hud", async (importOriginal) => ({
...await importOriginal<typeof import("./fast-detail-hud")>(),
drawFastDetailHud: (...args: unknown[]) => {
mocks.drawLocale(args[2]);
mocks.drawDetail(...args.slice(0, 2));
},
}));
vi.mock("./fast-canvas-hud", async (importOriginal) => ({
...await importOriginal<typeof import("./fast-canvas-hud")>(),
drawFastCanvasHud: (...args: unknown[]) => {
mocks.drawLocale(args[4]);
mocks.drawFast(...args.slice(0, 4));
},
}));
vi.mock("./fast-map", async (importOriginal) => ({
...await importOriginal<typeof import("./fast-map")>(),
drawFastFullscreenMap: (...args: unknown[]) => {
mocks.drawLocale(args[3]);
mocks.drawFullscreen(...args.slice(0, 3));
},
}));
vi.mock("./glasses", async (importOriginal) => ({
...await importOriginal<typeof import("./glasses")>(),
transmitFastCanvas: mocks.transmitFast,
}));
vi.mock("@evenrealities/even_hub_sdk", async (importOriginal) => ({
...await importOriginal<typeof import("@evenrealities/even_hub_sdk")>(),
waitForEvenAppBridge: mocks.waitForBridge,
}));
vi.mock("./live-dashboard", async (importOriginal) => ({
...await importOriginal<typeof import("./live-dashboard")>(),
createLiveDashboardSession: mocks.createSession,
}));
vi.mock("./minute-refresh", () => ({
startMinuteRefresh: mocks.minuteStart,
}));
vi.mock("./routing", async (importOriginal) => ({
...await importOriginal<typeof import("./routing")>(),
getRoutingStatus: mocks.getRoutingStatus,
searchDestinations: mocks.searchDestinations,
}));
beforeEach(() => {
vi.spyOn(HTMLCanvasElement.prototype, "getContext").mockReturnValue({
font: "",
measureText: (value: string) => ({
width: [...value].length * 10,
}),
} as unknown as CanvasRenderingContext2D);
mocks.createSession.mockReset();
mocks.drawDetail.mockReset();
mocks.drawFast.mockReset();
mocks.drawFullscreen.mockReset();
mocks.drawLocale.mockReset();
mocks.getRoutingStatus.mockReset();
mocks.getRoutingStatus.mockResolvedValue({ enabled: false });
mocks.minuteStart.mockReset();
mocks.searchDestinations.mockReset();
mocks.searchDestinations.mockResolvedValue([]);
mocks.transmitFast.mockReset();
mocks.waitForBridge.mockReset();
mocks.waitForBridge.mockResolvedValue({});
});
afterEach(() => {
cleanup();
vi.restoreAllMocks();
window.history.replaceState({}, "", "/");
});
describe("SANDEVISTAN peripheral HUD", () => {
it("uses one 576 by 288 canvas as the only visible HUD surface", () => {
render(<App autoStart={false} />);
const hud = screen.getByTestId("hud-frame");
const canvas = screen.getByRole("img", {
name: "Sandevistan glasses HUD frame",
});
expect(hud.getAttribute("data-logical-size")).toBe("576x288");
expect(hud.dataset.textContainers).toBe("1");
expect(hud.dataset.imageContainers).toBe("4");
expect(canvas.tagName).toBe("CANVAS");
expect(canvas.getAttribute("width")).toBe("576");
expect(canvas.getAttribute("height")).toBe("288");
expect(hud.getAttribute("dir")).toBe("ltr");
expect(canvas.getAttribute("dir")).toBe("ltr");
});
it("keeps mock information inside the raster instead of native text", () => {
render(<App autoStart={false} />);
expect(screen.queryByText("14:37")).toBeNull();
expect(screen.queryByText("다음 교차로에서 우회전")).toBeNull();
});
it("selects the official raw-byte diagnostic from its dedicated path", () => {
window.history.replaceState({}, "", "/diagnostic-v6");
render(<App autoStart={false} />);
const hud = screen.getByTestId("hud-frame");
expect(screen.getByText(/OFFICIAL SAMPLE\.PNG · RAW BYTES/)).toBeTruthy();
expect(hud.dataset.textContainers).toBe("2");
expect(hud.dataset.imageContainers).toBe("1");
});
it("selects the click-triggered BMP diagnostic from the v10 path", () => {
window.history.replaceState({}, "", "/diagnostic-v10");
render(<App autoStart={false} />);
expect(screen.getByText(/1-BIT BMP · CLICK TO SEND/)).toBeTruthy();
});
it("selects the four-tile maximum-boundary calibration route", () => {
window.history.replaceState({}, "", "/calibration-max");
render(<App autoStart={false} />);
const hud = screen.getByTestId("hud-frame");
expect(screen.getByText(/576×288 MAX BOUNDARY/)).toBeTruthy();
expect(hud.dataset.textContainers).toBe("1");
expect(hud.dataset.imageContainers).toBe("4");
});
it("selects the dense Canvas HUD with the proven four-tile layout", () => {
window.history.replaceState({}, "", "/hud-canvas");
render(<App autoStart={false} />);
const hud = screen.getByTestId("hud-frame");
expect(screen.getByText(/576×288 · CANVAS HUD/)).toBeTruthy();
expect(hud.dataset.renderer).toBe("canvas");
expect(hud.dataset.textContainers).toBe("1");
expect(hud.dataset.imageContainers).toBe("4");
expect(hud.dataset.pages).toBe("4");
expect(hud.dataset.layout).toBeUndefined();
expect(screen.getByText(/SCROLL · 4 PAGES/)).toBeTruthy();
});
it("isolates the two-tile fast Canvas experiment", () => {
window.history.replaceState({}, "", "/hud-canvas-fast");
render(<App autoStart={false} />);
const hud = screen.getByTestId("hud-frame");
expect(hud.dataset.renderer).toBe("canvas-fast");
expect(hud.dataset.layout).toBe("static-left-dynamic-right");
expect(hud.dataset.updateTiles).toBe("2");
expect(screen.queryByRole("banner", {
name: "Sandevistan / Dashboard",
})).toBeNull();
expect(screen.getByRole("heading", {
level: 2,
name: "Dashboard",
})).toBeTruthy();
expect(screen.getByText("Dashboard")).toBeTruthy();
expect(screen.getByRole("button", { name: /Devices/ })).toBeTruthy();
expect(screen.queryByText(/CANVAS HUD · FAST 2-TILE/)).toBeNull();
});
it("passes the opt-in image pipeline limit to the fast transport", async () => {
window.history.replaceState(
{},
"",
"/hud-canvas-fast?pipeline=2",
);
mocks.transmitFast.mockResolvedValue(vi.fn());
render(<App />);
await vi.waitFor(() => expect(mocks.transmitFast).toHaveBeenCalledOnce());
expect(fastOptions().imageSendConcurrency).toBe(2);
});
it("uses the hardware-proven four-call transport by default", async () => {
window.history.replaceState({}, "", "/hud-canvas-fast");
mocks.transmitFast.mockResolvedValue(vi.fn());
render(<App />);
await vi.waitFor(() => expect(mocks.transmitFast).toHaveBeenCalledOnce());
expect(fastOptions().imageSendConcurrency).toBe(4);
});
it("passes the four-call image pipeline to the fast transport", async () => {
window.history.replaceState(
{},
"",
"/hud-canvas-fast?pipeline=4",
);
mocks.transmitFast.mockResolvedValue(vi.fn());
render(<App />);
await vi.waitFor(() => expect(mocks.transmitFast).toHaveBeenCalledOnce());
expect(fastOptions().imageSendConcurrency).toBe(4);
});
it("falls back to four-call image transport for an invalid pipeline", async () => {
window.history.replaceState(
{},
"",
"/hud-canvas-fast?pipeline=9",
);
mocks.transmitFast.mockResolvedValue(vi.fn());
render(<App />);
await vi.waitFor(() => expect(mocks.transmitFast).toHaveBeenCalledOnce());
expect(fastOptions().imageSendConcurrency).toBe(4);
});
it("passes the opt-in four-level tile palette to the fast transport", async () => {
window.history.replaceState(
{},
"",
"/hud-canvas-fast?pipeline=4&levels=4",
);
mocks.transmitFast.mockResolvedValue(vi.fn());
render(<App />);
await vi.waitFor(() => expect(mocks.transmitFast).toHaveBeenCalledOnce());
expect(fastOptions().imageSendConcurrency).toBe(4);
expect(fastOptions().tilePaletteMode).toBe("hud-4");
});
it("uses the four-level tile palette by default", async () => {
window.history.replaceState({}, "", "/hud-canvas-fast?pipeline=4");
mocks.transmitFast.mockResolvedValue(vi.fn());
render(<App />);
await vi.waitFor(() => expect(mocks.transmitFast).toHaveBeenCalledOnce());
expect(fastOptions().tilePaletteMode).toBe("hud-4");
});
it("keeps the explicit blank route as a blank-rebuild alias", async () => {
window.history.replaceState({}, "", "/hud-canvas-fast?hide=blank");
mocks.transmitFast.mockResolvedValue(vi.fn());
render(<App />);
await vi.waitFor(() => expect(mocks.transmitFast).toHaveBeenCalledOnce());
expect(fastOptions().displayHideStrategy).toBe("blank-rebuild");
});
it("uses blank rebuild as the query-free display toggle", async () => {
window.history.replaceState({}, "", "/hud-canvas-fast");
mocks.transmitFast.mockResolvedValue(vi.fn());
render(<App />);
await vi.waitFor(() => expect(mocks.transmitFast).toHaveBeenCalledOnce());
expect(fastOptions().displayHideStrategy).toBe("blank-rebuild");
});
it("keeps black tiles behind the explicit control route", async () => {
window.history.replaceState({}, "", "/hud-canvas-fast?hide=black");
mocks.transmitFast.mockResolvedValue(vi.fn());
render(<App />);
await vi.waitFor(() => expect(mocks.transmitFast).toHaveBeenCalledOnce());
expect(fastOptions().displayHideStrategy).toBe("black-tiles");
});
it("passes the opt-in one-bit BMP format to the fast transport", async () => {
window.history.replaceState(
{},
"",
"/hud-canvas-fast?format=bmp1",
);
mocks.transmitFast.mockResolvedValue(vi.fn());
render(<App />);
await vi.waitFor(() => expect(mocks.transmitFast).toHaveBeenCalledOnce());
expect(fastOptions().tileImageFormat).toBe("bmp-1");
});
it("uses PNG content tiles by default", async () => {
window.history.replaceState({}, "", "/hud-canvas-fast");
mocks.transmitFast.mockResolvedValue(vi.fn());
render(<App />);
await vi.waitFor(() => expect(mocks.transmitFast).toHaveBeenCalledOnce());
expect(fastOptions().tileImageFormat).toBe("png");
});
it("ignores the unsupported Base64 query and keeps the stable transport", async () => {
window.history.replaceState(
{},
"",
"/hud-canvas-fast?bridge=base64",
);
mocks.transmitFast.mockResolvedValue(vi.fn());
render(<App />);
await vi.waitFor(() => expect(mocks.transmitFast).toHaveBeenCalledOnce());
expect(fastOptions()).not.toHaveProperty("imageBridgeMode");
});
it("supports the explicit serial original-palette rollback route", async () => {
window.history.replaceState(
{},
"",
"/hud-canvas-fast?pipeline=1&levels=original",
);
mocks.transmitFast.mockResolvedValue(vi.fn());
render(<App />);
await vi.waitFor(() => expect(mocks.transmitFast).toHaveBeenCalledOnce());
expect(fastOptions().imageSendConcurrency).toBe(1);
expect(fastOptions().tilePaletteMode).toBe("original");
});
it("localizes fast HUD preview semantics in the effective phone language", () => {
window.history.replaceState({}, "", "/hud-canvas-fast");
render(<App autoStart={false} />);
expect(screen.getByTestId("hud-frame").getAttribute("aria-label"))
.toBe("Sandevistan image-transfer preview");
expect(screen.getByRole("img", {
name: "Sandevistan glasses HUD frame",
})).toBeTruthy();
fireEvent.click(screen.getByRole("button", { name: /^TODO/ }));
expect(screen.getByText("Go to the subway station")).toBeTruthy();
expect(screen.queryByText("지하철역으로 이동")).toBeNull();
});
it("uses the saved locale on the first HUD frame and stops idle sensors", async () => {
vi.spyOn(window.navigator, "language", "get").mockReturnValue("en-US");
window.history.replaceState({}, "", "/hud-canvas-fast");
const audioControl = vi.fn(async () => true);
const imuControl = vi.fn(async () => true);
const stopAppLocationUpdates = vi.fn(async () => true);
mocks.waitForBridge.mockResolvedValue({
audioControl,
imuControl,
stopAppLocationUpdates,
getLocalStorage: vi.fn(async (key: string) => key.includes("phone-preferences")
? JSON.stringify({
locale: "ko",
order: ["overview", "news", "todo", "weather", "ai"],
enabled: ["overview", "news", "todo", "weather", "ai"],
aiTextIntervalMs: 200,
})
: ""),
setLocalStorage: vi.fn(async () => true),
});
mocks.transmitFast.mockResolvedValue(vi.fn());
mocks.createSession.mockReturnValue({
start: vi.fn(async () => undefined),
getState: vi.fn(),
dispose: vi.fn(),
});
const view = render(<App />);
await vi.waitFor(() => expect(mocks.transmitFast).toHaveBeenCalledOnce());
expect(mocks.drawLocale.mock.calls[0]?.[0]).toBe("ko");
expect(mocks.drawLocale).not.toHaveBeenCalledWith("en");
expect(audioControl).toHaveBeenCalledWith(false);
expect(imuControl).toHaveBeenCalledWith(false);
expect(stopAppLocationUpdates).toHaveBeenCalledOnce();
view.unmount();
});
it("relocalizes built-in TODOs independently of a G2 refresh", async () => {
vi.spyOn(window.navigator, "language", "get").mockReturnValue("ko-KR");
window.history.replaceState({}, "", "/hud-canvas-fast");
mocks.transmitFast.mockResolvedValue(vi.fn());
const setLocalStorage = vi.fn(async () => true);
mocks.waitForBridge.mockResolvedValue({
getLocalStorage: vi.fn(async () => ""),
setLocalStorage,
});
const session = {
start: vi.fn(async () => undefined),
getState: vi.fn(),
dispose: vi.fn(),
};
mocks.createSession.mockReturnValue(session);
render(<App />);
await vi.waitFor(() => expect(session.start).toHaveBeenCalledOnce());
fireEvent.click(screen.getByRole("button", { name: /^할 일/ }));
expect(screen.getByText("지하철역으로 이동")).toBeTruthy();
fireEvent.click(screen.getByRole("button", {
name: "대시보드로 돌아가기",
}));
fireEvent.click(screen.getByRole("button", { name: /^언어/ }));
fireEvent.click(screen.getByRole("radio", { name: "English" }));
await vi.waitFor(() => expect(setLocalStorage).toHaveBeenCalledWith(
"sandevistan:phone-preferences:v1",
expect.stringContaining('"locale":"en"'),
));
await vi.waitFor(() => expect(screen.getByRole("heading", {
level: 1,
name: "Language",
})).toBeTruthy());
fireEvent.click(screen.getByRole("button", {
name: "Back to Dashboard",
}));
fireEvent.click(screen.getByRole("button", { name: /^TODO/ }));
expect(screen.getByText("Go to the subway station")).toBeTruthy();
expect(screen.queryByText("지하철역으로 이동")).toBeNull();
});
it("shows diagnostics only after opening Developer on the fast HUD", () => {
window.history.replaceState({}, "", "/hud-canvas-fast");
const fast = render(<App autoStart={false} />);
expect(screen.queryByText("WEBVIEW TRACE")).toBeNull();
fireEvent.click(screen.getByRole("button", { name: /Developer/ }));
expect(screen.getByText("WEBVIEW TRACE")).toBeTruthy();
fast.unmount();
window.history.replaceState({}, "", "/hud-canvas");
render(<App autoStart={false} />);
expect(screen.queryByText("WEBVIEW TRACE")).toBeNull();
});
it("does not show live-data credits outside the fast route", () => {
window.history.replaceState({}, "", "/hud-canvas");
render(<App autoStart={false} />);
expect(screen.queryByText(
"날씨: Open-Meteo · 지도 데이터: OpenStreetMap contributors · 뉴스: SBS RSS · 개인·비상업",
)).toBeNull();
});
it("renders the newest live snapshot before requesting its target refresh", async () => {
window.history.replaceState({}, "", "/hud-canvas-fast");
const requestRefresh = vi.fn();
const transportCleanup = vi.fn();
mocks.transmitFast.mockImplementation(async (...args: unknown[]) => {
const options = args[3] as FastTestOptions;
options.onRefreshReady?.(requestRefresh);
return transportCleanup;
});
const storage = new Map<string, string>();
mocks.waitForBridge.mockResolvedValue({
getLocalStorage: vi.fn(async (key: string) => storage.get(key) ?? ""),
setLocalStorage: vi.fn(async (key: string, value: string) => {
storage.set(key, value);
return true;
}),
});
const session = {
start: vi.fn(async () => undefined),
getState: vi.fn(),
dispose: vi.fn(),
};
mocks.createSession.mockReturnValue(session);
const view = render(<App />);
await vi.waitFor(() => expect(session.start).toHaveBeenCalledTimes(1));
const newest: LiveDashboardState = {
...createInitialLiveDashboardState(),
weather: {
status: "fresh",
fetchedAt: 1_800_000_000_000,
value: {
temperature: 30,
apparentTemperature: 31,
humidity: 67,
windSpeed: 8,
precipitationProbability: 20,
weatherCode: 2,
condition: "대체로 맑음",
},
},
};
sessionOptions().onUpdate({ state: newest, target: "right" });
expect(requestRefresh).toHaveBeenCalledWith("right");
await fastOptions().beforeExternalRefresh?.();
expect(mocks.drawFast).toHaveBeenLastCalledWith(
expect.any(HTMLCanvasElement),
expect.any(Date),
"overview",
{ battery: undefined, live: newest, mapRadiusMeters: 650 },
);
expect(mocks.drawLocale).toHaveBeenLastCalledWith("en");
view.unmount();
});
it("redraws the visible HUD once after a saved language change", async () => {
window.history.replaceState({}, "", "/hud-canvas-fast");
const requestRefresh = vi.fn();
mocks.transmitFast.mockImplementation(async (...args: unknown[]) => {
const options = args[3] as FastTestOptions;
options.onRefreshReady?.(requestRefresh);
return vi.fn();
});
const storage = new Map<string, string>();
mocks.waitForBridge.mockResolvedValue({
getLocalStorage: vi.fn(async (key: string) => storage.get(key) ?? ""),
setLocalStorage: vi.fn(async (key: string, value: string) => {
storage.set(key, value);
return true;
}),
});
const session = {
start: vi.fn(async () => undefined),
getState: vi.fn(),
dispose: vi.fn(),
};
mocks.createSession.mockReturnValue(session);
const view = render(<App />);
await vi.waitFor(() => expect(session.start).toHaveBeenCalledOnce());
requestRefresh.mockClear();
mocks.drawLocale.mockClear();
fireEvent.click(screen.getByRole("button", { name: /Language/ }));
fireEvent.click(screen.getByRole("radio", { name: "한국어" }));
await vi.waitFor(() => {
expect(requestRefresh).toHaveBeenCalledWith("all");
});
expect(mocks.drawLocale).toHaveBeenLastCalledWith("ko");
view.unmount();
});
it("requests only the right-top tile on minute boundaries and stops on cleanup", async () => {
window.history.replaceState({}, "", "/hud-canvas-fast");
const requestRefresh = vi.fn();
const stopMinuteRefresh = vi.fn();
let onMinute: ((minute: number) => void) | undefined;
mocks.minuteStart.mockImplementation((callback: (minute: number) => void) => {
onMinute = callback;
return stopMinuteRefresh;
});
const transportCleanup = vi.fn();
mocks.transmitFast.mockImplementation(async (...args: unknown[]) => {
const options = args[3] as FastTestOptions;
options.onRefreshReady?.(requestRefresh);
return transportCleanup;
});
mocks.waitForBridge.mockResolvedValue({});
const session = {
start: vi.fn(async () => undefined),
getState: vi.fn(),
dispose: vi.fn(),
};
mocks.createSession.mockReturnValue(session);
const view = render(<App />);
await vi.waitFor(() => expect(session.start).toHaveBeenCalledOnce());
expect(mocks.minuteStart).toHaveBeenCalledOnce();
onMinute?.(1_234);
expect(requestRefresh).toHaveBeenCalledWith("right-top");
view.unmount();
expect(stopMinuteRefresh).toHaveBeenCalledOnce();
});
it("checks due news each minute except while reading and checks on exit", async () => {
window.history.replaceState({}, "", "/hud-canvas-fast");
let onMinute: ((minute: number) => void) | undefined;
let navigate:
| ((direction: "next" | "previous") => Promise<void>)
| undefined;
mocks.minuteStart.mockImplementation((callback: (minute: number) => void) => {
onMinute = callback;
return vi.fn();
});
mocks.transmitFast.mockImplementation(async (...args: unknown[]) => {
navigate = args[2] as typeof navigate;
const options = args[3] as FastTestOptions;
options.onRefreshReady?.(vi.fn());
return vi.fn();
});
mocks.waitForBridge.mockResolvedValue({});
const refreshNewsIfDue = vi.fn();
const session = {
start: vi.fn(async () => undefined),
refreshNewsIfDue,
getState: vi.fn(),
dispose: vi.fn(),
};
mocks.createSession.mockReturnValue(session);
const view = render(<App />);
await vi.waitFor(() => expect(session.start).toHaveBeenCalledOnce());
expect(sessionOptions().canRefreshNews?.()).toBe(true);
onMinute?.(1_234);
expect(refreshNewsIfDue).toHaveBeenCalledOnce();
await navigate?.("next");
expect(await fastOptions().onInput?.("tap")).toBe("redraw");
expect(sessionOptions().canRefreshNews?.()).toBe(false);
onMinute?.(1_235);
expect(refreshNewsIfDue).toHaveBeenCalledOnce();
expect(await fastOptions().onInput?.("double-tap")).toBe("redraw");
expect(sessionOptions().canRefreshNews?.()).toBe(true);
expect(refreshNewsIfDue).toHaveBeenCalledTimes(2);
view.unmount();
});
it("skips clock refresh when another transfer committed this minute", async () => {
window.history.replaceState({}, "", "/hud-canvas-fast");
const requestRefresh = vi.fn();
let onMinute: ((minute: number) => void) | undefined;
mocks.minuteStart.mockImplementation((callback: (minute: number) => void) => {
onMinute = callback;
return vi.fn();
});
mocks.transmitFast.mockImplementation(async (...args: unknown[]) => {
const options = args[3] as FastTestOptions;
options.onRefreshReady?.(requestRefresh);
return vi.fn();
});
mocks.waitForBridge.mockResolvedValue({});
const session = {
start: vi.fn(async () => undefined),
getState: vi.fn(),
dispose: vi.fn(),
};
mocks.createSession.mockReturnValue(session);
const view = render(<App />);
await vi.waitFor(() => expect(session.start).toHaveBeenCalledOnce());
fastOptions().onDisplayCommitted?.(1_234);
onMinute?.(1_234);
expect(requestRefresh).not.toHaveBeenCalled();
onMinute?.(1_235);
expect(requestRefresh).toHaveBeenCalledOnce();
expect(requestRefresh).toHaveBeenCalledWith("right-top");
view.unmount();
});
it("does not retry one minute refresh in the same minute", async () => {
window.history.replaceState({}, "", "/hud-canvas-fast");
const requestRefresh = vi.fn();
let onMinute: ((minute: number) => void) | undefined;
mocks.minuteStart.mockImplementation((callback: (minute: number) => void) => {
onMinute = callback;
return vi.fn();
});
mocks.transmitFast.mockImplementation(async (...args: unknown[]) => {
const options = args[3] as FastTestOptions;
options.onRefreshReady?.(requestRefresh);
return vi.fn();
});
mocks.waitForBridge.mockResolvedValue({});
mocks.createSession.mockReturnValue({
start: vi.fn(async () => undefined),
getState: vi.fn(),
dispose: vi.fn(),
});
const view = render(<App />);
await vi.waitFor(() => expect(mocks.createSession).toHaveBeenCalledOnce());
onMinute?.(1_235);
onMinute?.(1_235);
onMinute?.(1_235);
expect(requestRefresh).toHaveBeenCalledOnce();
expect(requestRefresh).toHaveBeenCalledWith("right-top");
view.unmount();
});
it("traces fast HUD lifecycle without changing refresh behavior", async () => {
window.history.replaceState({}, "", "/hud-canvas-fast");
diagnosticLogger.clear();
const requestRefresh = vi.fn();
let onMinute: ((minute: number) => void) | undefined;
mocks.minuteStart.mockImplementation((callback: (minute: number) => void) => {
onMinute = callback;
return vi.fn();
});
mocks.transmitFast.mockImplementation(async (...args: unknown[]) => {
const options = args[3] as FastTestOptions;
options.onRefreshReady?.(requestRefresh);
return vi.fn();
});
mocks.waitForBridge.mockResolvedValue({});
const session = {
start: vi.fn(async () => undefined),
getState: vi.fn(),
dispose: vi.fn(),
};
mocks.createSession.mockReturnValue(session);
const view = render(<App />);
await vi.waitFor(() => expect(session.start).toHaveBeenCalledOnce());
fastOptions().onBattery?.({
label: "G2",
level: 78,
charging: false,
});
await fastOptions().onInput?.("tap");
sessionOptions().onUpdate({
state: createInitialLiveDashboardState(),
target: "right",
});
onMinute?.(1_234);
const errorEvent = new ErrorEvent("error", {
cancelable: true,
error: new TypeError("private route destination"),
message: "private route destination",
});
errorEvent.preventDefault();
window.dispatchEvent(errorEvent);
const rejection = new Event("unhandledrejection");
Object.defineProperty(rejection, "reason", {
value: new RangeError("private coordinate"),
});
window.dispatchEvent(rejection);
view.unmount();
const trace = diagnosticLogger.text();
expect(trace).toContain("[APP] fast HUD effect start");
expect(trace).toContain("[APP] transport start");
expect(trace).toContain("[APP] transport ready");
expect(trace).toContain("[APP] live bridge ready");
expect(trace).toContain("[TIMER] heartbeat started");
expect(trace).toContain("[TIMER] minute refresh");
expect(trace).toContain("[INPUT] app tap");
expect(trace).toContain("[LIVE] app update · right");
expect(trace).toContain("[ERROR] window error · TypeError");
expect(trace).toContain("[ERROR] unhandled rejection · RangeError");
expect(trace).toContain("[APP] fast HUD effect cleanup");
expect(trace).toContain("[TIMER] heartbeat stopped");
expect(trace).not.toContain("private route destination");
expect(trace).not.toContain("private coordinate");
expect(requestRefresh).toHaveBeenCalledWith("right-top");
});
it("keeps raw hidden input out of localized phone status", async () => {
window.history.replaceState({}, "", "/hud-canvas-fast");
mocks.transmitFast.mockImplementation(async () => vi.fn());
mocks.waitForBridge.mockResolvedValue({});
mocks.createSession.mockReturnValue({
start: vi.fn(async () => undefined),
getState: vi.fn(),
dispose: vi.fn(),
});
render(<App />);
await vi.waitFor(() => expect(mocks.transmitFast).toHaveBeenCalledOnce());
fastOptions().onRawEvent?.({
count: 7,
hidden: true,
sysEventType: undefined,
textEventType: OsEventTypeList.DOUBLE_CLICK_EVENT,
eventSource: 2,
});
await vi.waitFor(() => expect(screen.queryByText(
"숨김 입력 #7 · SYS - · TEXT 3 · SRC 2",
)).toBeNull());
});
it("refreshes a visible overview battery change and retains it on other pages", async () => {
window.history.replaceState({}, "", "/hud-canvas-fast");
const requestRefresh = vi.fn();
const transportCleanup = vi.fn();
let navigate:
| ((direction: "next" | "previous") => Promise<void>)
| undefined;
mocks.transmitFast.mockImplementation(async (...args: unknown[]) => {
navigate = args[2] as typeof navigate;
const options = args[3] as FastTestOptions;
options.onBattery?.({
label: "G2",
level: 82,
charging: false,
});
options.onRefreshReady?.(requestRefresh);
return transportCleanup;
});
mocks.waitForBridge.mockResolvedValue({});
const session = {
start: vi.fn(async () => undefined),
getState: vi.fn(),
dispose: vi.fn(),
};
mocks.createSession.mockReturnValue(session);
const view = render(<App />);
await vi.waitFor(() => expect(session.start).toHaveBeenCalledOnce());
fastOptions().onBattery?.({
label: "G2",
level: 81,
charging: false,
});
expect(requestRefresh).toHaveBeenLastCalledWith("right-top");
requestRefresh.mockClear();
await navigate?.("next");
fastOptions().onBattery?.({
label: "G2",
level: 80,
charging: true,
});
expect(requestRefresh).not.toHaveBeenCalled();
await navigate?.("previous");
expect(mocks.drawFast).toHaveBeenLastCalledWith(
expect.any(HTMLCanvasElement),
expect.any(Date),
"overview",
{
battery: { label: "G2", level: 80, charging: true },
live: expect.any(Object),
mapRadiusMeters: 650,
},
);
view.unmount();
});
it("opens, zooms, and closes the fullscreen map from overview input", async () => {
window.history.replaceState({}, "", "/hud-canvas-fast");
const requestRefresh = vi.fn();
const transportCleanup = vi.fn();
let navigate:
| ((direction: "next" | "previous") => Promise<void>)
| undefined;
mocks.transmitFast.mockImplementation(async (...args: unknown[]) => {
navigate = args[2] as typeof navigate;
const options = args[3] as FastTestOptions;
options.onRefreshReady?.(requestRefresh);
return transportCleanup;
});
mocks.waitForBridge.mockResolvedValue({});
const session = {
start: vi.fn(async () => undefined),
getState: vi.fn(),
dispose: vi.fn(),
};
mocks.createSession.mockReturnValue(session);
const view = render(<App />);
await vi.waitFor(() => expect(session.start).toHaveBeenCalledOnce());
expect(await fastOptions().onInput?.("tap")).toBe("redraw");
expect(mocks.drawFullscreen).toHaveBeenLastCalledWith(
expect.any(HTMLCanvasElement),
expect.any(Object),
650,
);
expect(await fastOptions().onInput?.("scroll-next")).toBe("redraw");
expect(mocks.drawFullscreen).toHaveBeenLastCalledWith(
expect.any(HTMLCanvasElement),
expect.any(Object),
850,
);
expect(await fastOptions().onInput?.("double-tap")).toBe("redraw");
expect(mocks.drawFast).toHaveBeenLastCalledWith(
expect.any(HTMLCanvasElement),
expect.any(Date),
"overview",
expect.objectContaining({ mapRadiusMeters: 850 }),
);
expect(await fastOptions().onInput?.("double-tap")).toBe("unhandled");
await navigate?.("next");
mocks.drawFullscreen.mockClear();
expect(await fastOptions().onInput?.("tap")).toBe("redraw");
expect(mocks.drawFullscreen).not.toHaveBeenCalled();
expect(mocks.drawDetail).toHaveBeenLastCalledWith(
expect.any(HTMLCanvasElement),
expect.objectContaining({ mode: "news", newsIndex: 0, newsPage: 0 }),
);
view.unmount();
});
it("cycles Weather, Ask AI, and Conversate while Navigation stays opt-in", async () => {
window.history.replaceState({}, "", "/hud-canvas-fast");
const requestRefresh = vi.fn();
let navigate:
| ((direction: "next" | "previous") => Promise<void>)
| undefined;
mocks.transmitFast.mockImplementation(async (...args: unknown[]) => {
navigate = args[2] as typeof navigate;
const options = args[3] as FastTestOptions;
options.onRefreshReady?.(requestRefresh);
return vi.fn();
});
mocks.waitForBridge.mockResolvedValue({});
const session = {
start: vi.fn(async () => undefined),
getState: vi.fn(),
dispose: vi.fn(),
};
mocks.createSession.mockReturnValue(session);
const view = render(<App />);
await vi.waitFor(() => expect(session.start).toHaveBeenCalledOnce());
await navigate?.("next");