Files
LexAI/tests/unit/background.test.ts
Nemo b04076081c
Some checks failed
CI — Test & Build / Unit Tests (push) Failing after 54s
CI — Test & Build / Build Extension (push) Has been skipped
feat: initial LexAI Chrome extension scaffold
- WXT + React 18 + TypeScript setup
- Background service worker (LLM API proxy)
- Content script (floating toolbar + text selection)
- Options page (provider/model/API key config)
- Popup UI
- Gitea Actions workflows (CI, preview, release)
- Vitest unit tests + Playwright E2E setup
- Supports: OpenAI, Anthropic, Groq, OpenRouter
2026-03-06 09:34:15 +08:00

29 lines
916 B
TypeScript

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<any>((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<void>((resolve) =>
chrome.storage.local.set(testConfig, resolve)
);
expect(chrome.storage.local.set).toHaveBeenCalledWith(testConfig, expect.any(Function));
});
});