Skip to content

Commit e63a6f3

Browse files
committed
parameterize watchdog visibility cases
1 parent fb8c197 commit e63a6f3

1 file changed

Lines changed: 46 additions & 29 deletions

File tree

packages/ui/src/shell/useAppVisibilityWatchdog.test.ts

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,57 @@ afterEach(() => {
3939
});
4040

4141
describe("useAppVisibilityWatchdog", () => {
42-
it("reports when the main app is mounted but invisible", () => {
42+
it.each([
43+
{
44+
name: "invisible via opacity",
45+
opacity: "0",
46+
width: 1200,
47+
height: 800,
48+
active: true,
49+
reports: true,
50+
},
51+
{
52+
name: "collapsed to zero size",
53+
opacity: "1",
54+
width: 0,
55+
height: 0,
56+
active: true,
57+
reports: true,
58+
},
59+
{
60+
name: "visible",
61+
opacity: "1",
62+
width: 1200,
63+
height: 800,
64+
active: true,
65+
reports: false,
66+
},
67+
{
68+
name: "inactive",
69+
opacity: "0",
70+
width: 1200,
71+
height: 800,
72+
active: false,
73+
reports: false,
74+
},
75+
])(
76+
"reports=$reports when $name",
77+
({ opacity, width, height, active, reports }) => {
78+
const ref = { current: mountElement(opacity, width, height) };
79+
renderHook(() => useAppVisibilityWatchdog(ref, active));
80+
81+
vi.advanceTimersByTime(3000);
82+
83+
expect(captureException).toHaveBeenCalledTimes(reports ? 1 : 0);
84+
},
85+
);
86+
87+
it("reports the element's opacity and source", () => {
4388
const ref = { current: mountElement("0", 1200, 800) };
4489
renderHook(() => useAppVisibilityWatchdog(ref, true));
4590

4691
vi.advanceTimersByTime(3000);
4792

48-
expect(captureException).toHaveBeenCalledOnce();
4993
expect(captureException).toHaveBeenCalledWith(
5094
expect.any(Error),
5195
expect.objectContaining({
@@ -55,33 +99,6 @@ describe("useAppVisibilityWatchdog", () => {
5599
);
56100
});
57101

58-
it("reports when the main app has collapsed to zero size", () => {
59-
const ref = { current: mountElement("1", 0, 0) };
60-
renderHook(() => useAppVisibilityWatchdog(ref, true));
61-
62-
vi.advanceTimersByTime(3000);
63-
64-
expect(captureException).toHaveBeenCalledOnce();
65-
});
66-
67-
it("stays silent when the main app is visible", () => {
68-
const ref = { current: mountElement("1", 1200, 800) };
69-
renderHook(() => useAppVisibilityWatchdog(ref, true));
70-
71-
vi.advanceTimersByTime(3000);
72-
73-
expect(captureException).not.toHaveBeenCalled();
74-
});
75-
76-
it("does nothing while inactive", () => {
77-
const ref = { current: mountElement("0", 1200, 800) };
78-
renderHook(() => useAppVisibilityWatchdog(ref, false));
79-
80-
vi.advanceTimersByTime(3000);
81-
82-
expect(captureException).not.toHaveBeenCalled();
83-
});
84-
85102
it("does not report after unmounting before the deadline", () => {
86103
const ref = { current: mountElement("0", 1200, 800) };
87104
const { unmount } = renderHook(() => useAppVisibilityWatchdog(ref, true));

0 commit comments

Comments
 (0)