|
1 | 1 | import type { DocksContext } from '@vitejs/devtools-kit/client' |
2 | 2 | import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest' |
3 | 3 | import { setDocksOverflowPanel, useDocksOverflowPanel } from '../floating-tooltip' |
4 | | -import { closeDockPopup, filterPopupDockEntry, isDockPopupEntryVisible, isDockPopupSupported, openDockPopup, setDockStandaloneLoaderForTest, useDockPopupWindow, useIsDockPopupOpen } from '../popup' |
| 4 | +import { closeDockPopup, isDockPopupSupported, openDockPopup, setDockStandaloneLoaderForTest, useDockPopupWindow, useIsDockPopupOpen } from '../popup' |
5 | 5 |
|
6 | 6 | const { |
7 | 7 | DockStandaloneElementMock, |
@@ -49,6 +49,9 @@ function createMockContext( |
49 | 49 | inactiveTimeout: 3_000, |
50 | 50 | }, |
51 | 51 | }, |
| 52 | + docks: { |
| 53 | + switchEntry: vi.fn(), |
| 54 | + }, |
52 | 55 | } as unknown as DocksContext |
53 | 56 | } |
54 | 57 |
|
@@ -145,49 +148,11 @@ describe('dock popup state', () => { |
145 | 148 |
|
146 | 149 | it('returns null when the API is unavailable', async () => { |
147 | 150 | expect(isDockPopupSupported()).toBe(false) |
148 | | - expect(isDockPopupEntryVisible('embedded')).toBe(false) |
149 | 151 | const popup = await openDockPopup(createMockContext()) |
150 | 152 | expect(popup).toBeNull() |
151 | 153 | expect(useIsDockPopupOpen().value).toBe(false) |
152 | 154 | }) |
153 | 155 |
|
154 | | - it('hides popup entry when popup is already open', async () => { |
155 | | - const popup = createMockPopupWindow() |
156 | | - const requestWindow = vi.fn().mockResolvedValue(popup) |
157 | | - ;(window as Window & { documentPictureInPicture?: unknown }).documentPictureInPicture = { requestWindow } |
158 | | - |
159 | | - expect(isDockPopupEntryVisible('embedded')).toBe(true) |
160 | | - await openDockPopup(createMockContext()) |
161 | | - expect(isDockPopupEntryVisible('embedded')).toBe(false) |
162 | | - }) |
163 | | - |
164 | | - it('hides popup entry when running inside popup window', () => { |
165 | | - ;(window as Window & { documentPictureInPicture?: unknown }).documentPictureInPicture = { requestWindow: vi.fn() } |
166 | | - |
167 | | - expect(isDockPopupEntryVisible('standalone')).toBe(false) |
168 | | - }) |
169 | | - |
170 | | - it('filters popup entry from grouped entries', () => { |
171 | | - const groups = [ |
172 | | - ['~builtin', [ |
173 | | - { type: '~builtin', id: '~popup', title: 'Popup', icon: 'test' }, |
174 | | - { type: '~builtin', id: '~settings', title: 'Settings', icon: 'test' }, |
175 | | - ]], |
176 | | - ['default', [ |
177 | | - { type: 'iframe', id: 'app', title: 'App', icon: 'test', url: 'http://example.com' }, |
178 | | - ]], |
179 | | - ] as const as Parameters<typeof filterPopupDockEntry>[0] |
180 | | - |
181 | | - expect(filterPopupDockEntry(groups)).toEqual([ |
182 | | - ['~builtin', [ |
183 | | - { type: '~builtin', id: '~settings', title: 'Settings', icon: 'test' }, |
184 | | - ]], |
185 | | - ['default', [ |
186 | | - { type: 'iframe', id: 'app', title: 'App', icon: 'test', url: 'http://example.com' }, |
187 | | - ]], |
188 | | - ]) |
189 | | - }) |
190 | | - |
191 | 156 | it('opens popup window and mounts standalone frame', async () => { |
192 | 157 | const popup = createMockPopupWindow() |
193 | 158 | const requestWindow = vi.fn().mockResolvedValue(popup) |
@@ -240,32 +205,36 @@ describe('dock popup state', () => { |
240 | 205 | expect(popup.focus).toHaveBeenCalledTimes(1) |
241 | 206 | }) |
242 | 207 |
|
243 | | - it('clears popup state when popup is closed', async () => { |
| 208 | + it('clears popup state and closes panel when popup is closed', async () => { |
244 | 209 | const popup = createMockPopupWindow() |
245 | 210 | const requestWindow = vi.fn().mockResolvedValue(popup) |
246 | 211 | ;(window as Window & { documentPictureInPicture?: unknown }).documentPictureInPicture = { requestWindow } |
247 | 212 |
|
248 | | - await openDockPopup(createMockContext()) |
| 213 | + const context = createMockContext() |
| 214 | + await openDockPopup(context) |
249 | 215 | expect(useIsDockPopupOpen().value).toBe(true) |
250 | 216 |
|
251 | 217 | popup.dispatchEvent(new Event('pagehide')) |
252 | 218 |
|
253 | 219 | expect(dockElementRemoveMock).toHaveBeenCalledTimes(1) |
254 | 220 | expect(useIsDockPopupOpen().value).toBe(false) |
255 | 221 | expect(useDockPopupWindow().value).toBeNull() |
| 222 | + expect(context.docks.switchEntry).toHaveBeenCalledWith(null) |
256 | 223 | }) |
257 | 224 |
|
258 | | - it('closes popup window via closeDockPopup', async () => { |
| 225 | + it('closes popup window and panel via closeDockPopup', async () => { |
259 | 226 | const popup = createMockPopupWindow() |
260 | 227 | const requestWindow = vi.fn().mockResolvedValue(popup) |
261 | 228 | ;(window as Window & { documentPictureInPicture?: unknown }).documentPictureInPicture = { requestWindow } |
262 | 229 |
|
263 | | - await openDockPopup(createMockContext()) |
| 230 | + const context = createMockContext() |
| 231 | + await openDockPopup(context) |
264 | 232 | closeDockPopup() |
265 | 233 |
|
266 | 234 | expect(dockElementRemoveMock).toHaveBeenCalledTimes(1) |
267 | 235 | expect(popup.close).toHaveBeenCalledTimes(1) |
268 | 236 | expect(useIsDockPopupOpen().value).toBe(false) |
269 | 237 | expect(useDockPopupWindow().value).toBeNull() |
| 238 | + expect(context.docks.switchEntry).toHaveBeenCalledWith(null) |
270 | 239 | }) |
271 | 240 | }) |
0 commit comments