Something went wrong. Try again.
Browser extension: detect and subscribe to standard.site publications on ATProto
Something went wrong. Try again.
1.5 kB · 47 lines
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748import { 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') })})