import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { WELCOME_PAGE, pinState, welcomeUrl } from './welcome' const getUserSettings = vi.fn() beforeEach(() => { vi.stubGlobal('chrome', { action: { getUserSettings }, runtime: { getURL: (path: string) => `chrome-extension://testid/${path}` }, }) }) afterEach(() => { vi.unstubAllGlobals() vi.restoreAllMocks() }) describe('welcomeUrl', () => { it('resolves the bundled page against the extension origin', () => { expect(welcomeUrl()).toBe(`chrome-extension://testid/${WELCOME_PAGE}`) }) }) describe('pinState', () => { it('reports a pinned toolbar icon', async () => { getUserSettings.mockResolvedValue({ isOnToolbar: true }) await expect(pinState()).resolves.toBe('pinned') }) it('reports an unpinned one', async () => { getUserSettings.mockResolvedValue({ isOnToolbar: false }) await expect(pinState()).resolves.toBe('unpinned') }) // Both failure shapes answer 'unknown', which the page renders as no claim // either way — never as "you have not pinned it". it('is unknown when the read fails', async () => { vi.spyOn(console, 'debug').mockImplementation(() => {}) getUserSettings.mockRejectedValue(new Error('nope')) await expect(pinState()).resolves.toBe('unknown') }) it('is unknown when the browser has no such API', async () => { vi.stubGlobal('chrome', { action: {} }) await expect(pinState()).resolves.toBe('unknown') }) })