Skip to content

Commit 7d5cb86

Browse files
committed
test(web): align plugin render lifecycle and available panel counters
1 parent cdaf7e7 commit 7d5cb86

1 file changed

Lines changed: 124 additions & 0 deletions

File tree

‎apps/web/src/panels/device/DeviceSidePanel.thread-switches.browser.test.tsx‎

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,127 @@ it("keeps a late power-off error in the environment that started it", async () =
207207
await screen.rerender(devicePanel(threadA, streaming));
208208
expect(errors()).toHaveLength(1);
209209
});
210+
211+
const otherEnvironment = switches[1][1];
212+
const streaming: Extract<RightPanelSurface, { kind: "device" }> = {
213+
id: "device:phone",
214+
kind: "device",
215+
target: { hostId: "local", deviceId: "phone", platform: "ios", name: "Phone" },
216+
};
217+
218+
describe("DevicePanel notices", () => {
219+
it("keeps discovery warnings dismissed until the diagnostic or environment changes", async () => {
220+
setup();
221+
await using screen = await render(null, { container, router: false });
222+
currentState = {
223+
...deviceState,
224+
hostStatusDetail: "Could not read simulator usage timestamps.",
225+
};
226+
await screen.rerender(devicePanel(threadA));
227+
expect(errors()).toHaveLength(1);
228+
expect(startButton()?.disabled).toBe(false);
229+
await click(container.querySelector('[aria-label="Dismiss device warning"]'));
230+
expect(errors()).toHaveLength(0);
231+
await screen.rerender(devicePanel(threadA));
232+
expect(errors()).toHaveLength(0);
233+
234+
currentState = { ...currentState, hostStatusDetail: "A different discovery warning." };
235+
await screen.rerender(devicePanel(threadA));
236+
expect(errors()).toHaveLength(1);
237+
await click(container.querySelector('[aria-label="Dismiss device warning"]'));
238+
await screen.rerender(devicePanel(otherEnvironment));
239+
expect(errors()).toHaveLength(1);
240+
});
241+
242+
it("keeps the loading content centered when discovery and boot notices arrive or are dismissed", async () => {
243+
setup();
244+
await using screen = await render(null, { container, router: false });
245+
const pick = deferred();
246+
mocks.open.mockReturnValue(pick.promise);
247+
await screen.rerender(devicePanel(threadA));
248+
await click(startButton());
249+
const loadingBounds = () =>
250+
container
251+
.querySelector('[aria-label="Step 1 of 2: open device"]')!
252+
.parentElement!.getBoundingClientRect();
253+
const before = loadingBounds();
254+
const panel = container.getBoundingClientRect();
255+
expect(before.height).toBeGreaterThan(0);
256+
expect(before.top + before.height / 2).toBeCloseTo(panel.top + panel.height / 2, 0);
257+
258+
currentState = {
259+
...deviceState,
260+
hostStatusDetail: "Could not read CoreSimulator plist.\n".repeat(8),
261+
bootingDevices: [{ ...phone, threadId: threadA.threadId }],
262+
};
263+
await screen.rerender(devicePanel(threadA));
264+
expect(loadingBounds().top).toBe(before.top);
265+
expect(loadingBounds().left).toBe(before.left);
266+
await click(container.querySelector('[aria-label="Dismiss device warning"]'));
267+
expect(loadingBounds().top).toBe(before.top);
268+
expect(loadingBounds().left).toBe(before.left);
269+
await act(async () => pick.settle(failed));
270+
});
271+
});
272+
273+
describe("DevicePanel thread switches", () => {
274+
it.each(switches)(
275+
"keeps a pending or failed pick in its starting scope when switching to %s",
276+
async (_, target) => {
277+
setup();
278+
await using screen = await render(null, { container, router: false });
279+
const pick = deferred();
280+
mocks.open.mockReturnValue(pick.promise);
281+
await screen.rerender(devicePanel(threadA));
282+
await click(startButton());
283+
expect(startButton()).toBeNull();
284+
285+
await screen.rerender(devicePanel(target));
286+
expect(startButton()?.disabled).toBe(false);
287+
288+
await act(async () => pick.settle(failed));
289+
expect(errors()).toHaveLength(0);
290+
expect(mocks.openDevice).not.toHaveBeenCalled();
291+
292+
await screen.rerender(devicePanel(threadA));
293+
expect(startButton()?.disabled).toBe(false);
294+
expect(errors()).toHaveLength(1);
295+
296+
await screen.rerender(devicePanel(target));
297+
expect(startButton()?.disabled).toBe(false);
298+
expect(errors()).toHaveLength(0);
299+
},
300+
);
301+
302+
it.each([
303+
[
304+
"pick",
305+
picker,
306+
() => mocks.open,
307+
() => click(startButton()),
308+
() => expect(mocks.openDevice).toHaveBeenCalledExactlyOnceWith(threadA, phoneTarget),
309+
],
310+
[
311+
"power-off",
312+
streaming,
313+
() => mocks.close,
314+
() => click(container.querySelector("button")),
315+
() => expect(mocks.closeSurface).toHaveBeenCalledExactlyOnceWith(threadA, streaming.id),
316+
],
317+
] as const)(
318+
"applies a late %s to its starting thread after switching environments with the same thread id",
319+
async (_, surface, command, start, expectApplied) => {
320+
setup();
321+
await using screen = await render(null, { container, router: false });
322+
const late = deferred();
323+
command().mockReturnValue(late.promise);
324+
await screen.rerender(devicePanel(threadA, surface));
325+
await start();
326+
327+
await screen.rerender(devicePanel(otherEnvironment, surface));
328+
await act(async () => late.settle(opened));
329+
330+
expectApplied();
331+
},
332+
);
333+
});

0 commit comments

Comments
 (0)