84 lines
2.3 KiB
TypeScript
84 lines
2.3 KiB
TypeScript
import { flushPromises, mount } from '@vue/test-utils'
|
|||
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||
|
|
import AppSession from '../AppSession.vue'
|
||
|
|
|
||
|
|
const { mockReplace, mockPush, mockWindowOpen, mockSuppress, mockResume } = vi.hoisted(() => ({
|
||
|
|
mockReplace: vi.fn(),
|
||
|
|
mockPush: vi.fn(),
|
||
|
|
mockWindowOpen: vi.fn(),
|
||
|
|
mockSuppress: vi.fn(),
|
||
|
|
mockResume: vi.fn(),
|
||
|
|
}))
|
||
|
|
|
||
|
|
vi.mock('vue-router', () => ({
|
||
|
|
useRoute: () => ({
|
||
|
|
params: { appId: 'gitea' },
|
||
|
|
query: { returnTo: '/dashboard/apps' },
|
||
|
|
fullPath: '/dashboard/apps/session/gitea',
|
||
|
|
}),
|
||
|
|
useRouter: () => ({ replace: mockReplace, push: mockPush }),
|
||
|
|
}))
|
||
|
|
|
||
|
|
vi.mock('@/stores/appLauncher', () => ({
|
||
|
|
useAppLauncherStore: () => ({ panelAppId: null }),
|
||
|
|
}))
|
||
|
|
|
||
|
|
vi.mock('@/stores/app', () => ({
|
||
|
|
useAppStore: () => ({ data: { 'package-data': {} } }),
|
||
|
|
}))
|
||
|
|
|
||
|
|
vi.mock('@/stores/screensaver', () => ({
|
||
|
|
useScreensaverStore: () => ({ suppress: mockSuppress, resume: mockResume }),
|
||
|
|
}))
|
||
|
|
|
||
|
|
vi.mock('../appSession/useAppIdentity', () => ({
|
||
|
|
useAppIdentity: () => ({
|
||
|
|
onIdentitySelected: vi.fn(),
|
||
|
|
onIframeLoadIdentity: vi.fn(),
|
||
|
|
handleIdentityRequest: vi.fn(),
|
||
|
|
getStoredIdentity: vi.fn(),
|
||
|
|
}),
|
||
|
|
}))
|
||
|
|
|
||
|
|
vi.mock('../appSession/useNostrBridge', () => ({
|
||
|
|
useNostrBridge: () => ({ handleNostrRequest: vi.fn() }),
|
||
|
|
}))
|
||
|
|
|
||
|
|
vi.stubGlobal('open', mockWindowOpen)
|
||
|
|
|
||
|
|
describe('AppSession mobile new-tab apps', () => {
|
||
|
|
beforeEach(() => {
|
||
|
|
vi.clearAllMocks()
|
||
|
|
localStorage.clear()
|
||
|
|
Object.defineProperty(window, 'innerWidth', {
|
||
|
|
value: 390,
|
||
|
|
writable: true,
|
||
|
|
configurable: true,
|
||
|
|
})
|
||
|
|
Object.defineProperty(window, 'location', {
|
||
|
|
value: { hostname: '192.168.1.228' },
|
||
|
|
writable: true,
|
||
|
|
configurable: true,
|
||
|
|
})
|
||
|
|
})
|
||
|
|
|
||
|
|
it('keeps iframe-blocked apps inside the mobile session instead of auto-opening a tab', async () => {
|
||
|
|
const wrapper = mount(AppSession, {
|
||
|
|
global: {
|
||
|
|
stubs: {
|
||
|
|
Teleport: true,
|
||
|
|
AppSessionHeader: true,
|
||
|
|
NostrIdentityPicker: true,
|
||
|
|
MobileGamepad: true,
|
||
|
|
},
|
||
|
|
},
|
||
|
|
})
|
||
|
|
await flushPromises()
|
||
|
|
|
||
|
|
expect(mockWindowOpen).not.toHaveBeenCalled()
|
||
|
|
expect(mockReplace).not.toHaveBeenCalled()
|
||
|
|
expect(wrapper.text()).toContain('This app opens in a new tab')
|
||
|
|
expect(wrapper.text()).toContain('Open in new tab')
|
||
|
|
})
|
||
|
|
})
|