import { describe, expect, it, vi, beforeEach } from 'vitest' import { mount } from '@vue/test-utils' import { createPinia, setActivePinia } from 'pinia' import { PackageState, type PackageDataEntry } from '@/types/api' import { useAppLauncherStore } from '@/stores/appLauncher' import AppIconGrid from '../AppIconGrid.vue' const mockWindowOpen = vi.fn() vi.stubGlobal('open', mockWindowOpen) function makePkg(id: string): PackageDataEntry { return { state: PackageState.Running, manifest: { id, title: id, version: '1.0.0', description: { short: '', long: '' }, 'release-notes': '', license: '', 'wrapper-repo': '', 'upstream-repo': '', 'support-site': '', 'marketing-site': '', 'donation-url': null, interfaces: { main: { ui: true } }, } as unknown as PackageDataEntry['manifest'], 'static-files': { license: '', instructions: '', icon: '' }, } } describe('AppIconGrid', () => { beforeEach(() => { setActivePinia(createPinia()) vi.clearAllMocks() localStorage.clear() Object.defineProperty(window, 'innerWidth', { value: 1024, writable: true, configurable: true, }) Object.defineProperty(window, 'location', { value: { hostname: '192.168.1.198' }, writable: true, configurable: true, }) }) it('opens LND companion UI in the app panel', async () => { const wrapper = mount(AppIconGrid, { props: { apps: [['lnd', makePkg('lnd')]] }, global: { plugins: [createPinia()], }, }) await wrapper.get('.app-icon-item').trigger('click') expect(mockWindowOpen).not.toHaveBeenCalled() expect(useAppLauncherStore().panelAppId).toBe('lnd') }) it('routes desktop new-tab apps through app session on mobile', async () => { Object.defineProperty(window, 'innerWidth', { value: 390, writable: true, configurable: true, }) const wrapper = mount(AppIconGrid, { props: { apps: [['gitea', makePkg('gitea')]] }, global: { plugins: [createPinia()], }, }) await wrapper.get('.app-icon-item').trigger('click') expect(mockWindowOpen).not.toHaveBeenCalled() expect(useAppLauncherStore().panelAppId).toBeNull() }) })