import { describe, it, expect, vi, beforeEach } from 'vitest'; describe('Background Service Worker', () => { beforeEach(() => { vi.clearAllMocks(); }); it('should return error when no API key is configured', async () => { (chrome.storage.local.get as any).mockImplementation((keys: any, cb: any) => cb({})); // Simulate the handleAnalyzeText function behavior const config = await new Promise((resolve) => chrome.storage.local.get(['provider', 'apiKey', 'model'], resolve) ); expect(config.apiKey).toBeUndefined(); }); it('should store API key correctly', async () => { const testConfig = { provider: 'openai', apiKey: 'sk-test123', model: 'gpt-4o-mini' }; await new Promise((resolve) => chrome.storage.local.set(testConfig, resolve) ); expect(chrome.storage.local.set).toHaveBeenCalledWith(testConfig, expect.any(Function)); }); });