| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { beginForegroundHandoff, isForegroundHandoffActive } from "./foreground-handoff"; |
| 4 | |
| 5 | describe("foreground handoff", () => { |
| 6 | it("is active only while a handoff is open", () => { |
| 7 | expect(isForegroundHandoffActive()).toBe(false); |
| 8 | const end = beginForegroundHandoff(); |
| 9 | expect(isForegroundHandoffActive()).toBe(true); |
| 10 | end(); |
| 11 | expect(isForegroundHandoffActive()).toBe(false); |
| 12 | }); |
| 13 | |
| 14 | it("stays active until every overlapping handoff ends", () => { |
| 15 | const endFirst = beginForegroundHandoff(); |
| 16 | const endSecond = beginForegroundHandoff(); |
| 17 | endFirst(); |
| 18 | expect(isForegroundHandoffActive()).toBe(true); |
| 19 | endSecond(); |
| 20 | expect(isForegroundHandoffActive()).toBe(false); |
| 21 | }); |
| 22 | |
| 23 | it("tolerates an end function called twice", () => { |
| 24 | const endFirst = beginForegroundHandoff(); |
| 25 | const endSecond = beginForegroundHandoff(); |
| 26 | endFirst(); |
| 27 | endFirst(); |
| 28 | expect(isForegroundHandoffActive()).toBe(true); |
| 29 | endSecond(); |
| 30 | expect(isForegroundHandoffActive()).toBe(false); |
| 31 | }); |
| 32 | }); |