Skip to content

Commit d7c27dc

Browse files
authored
test(query-devtools/contexts/PiPContext): add tests for 'closePipWindow' guard and reset (TanStack#10802)
1 parent 4cfd8a7 commit d7c27dc

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

packages/query-devtools/src/__tests__/contexts/PiPContext.test.tsx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,4 +261,49 @@ describe('PiPContext', () => {
261261
)
262262
})
263263
})
264+
265+
describe('"closePipWindow"', () => {
266+
it('should be a noop when no window is open', () => {
267+
const { fakeWindow } = stubPipWindow()
268+
269+
renderAndAct((pip) => {
270+
pip().closePipWindow()
271+
})
272+
273+
expect(fakeWindow.close).not.toHaveBeenCalled()
274+
})
275+
276+
it('should call "close" on the opened window and reset the "pipWindow" signal', () => {
277+
const { fakeWindow } = stubPipWindow()
278+
const observed: Array<Window | null> = []
279+
280+
renderAndAct(
281+
(pip) => {
282+
pip().requestPipWindow(640, 480)
283+
observed.push(pip().pipWindow)
284+
pip().closePipWindow()
285+
observed.push(pip().pipWindow)
286+
},
287+
{ disabled: true },
288+
)
289+
290+
expect(fakeWindow.close).toHaveBeenCalledTimes(1)
291+
expect(observed).toEqual([fakeWindow, null])
292+
})
293+
294+
it('should call "close" only once when "closePipWindow" runs twice in a row', () => {
295+
const { fakeWindow } = stubPipWindow()
296+
297+
renderAndAct(
298+
(pip) => {
299+
pip().requestPipWindow(640, 480)
300+
pip().closePipWindow()
301+
pip().closePipWindow()
302+
},
303+
{ disabled: true },
304+
)
305+
306+
expect(fakeWindow.close).toHaveBeenCalledTimes(1)
307+
})
308+
})
264309
})

0 commit comments

Comments
 (0)