Files
binect-chrome/tests/setup.ts
tegwick b09290cb83 Release 0.1: Complete BinectChrome implementation
Implements all requirements from ProductRequirementsDocument.md:
- PDF detection via Chrome Downloads API
- Secure credential storage with AES-GCM encryption
- Binect API integration for PDF uploads
- Popup UI with Binect branding
- Local transfer tracking (500 entry cap)
- Help page with tracking view and CSV export
- 60-day credential retention with auto-expiry
- Accessibility compliance (WCAG 2.1 AA)

Technical implementation:
- Chrome Extension Manifest V3
- TypeScript with strict mode
- Webpack build system
- Jest test suite (22/22 passing)
- ESLint configured (0 errors)

Build output: 13 KB total (production minified)
Test coverage: crypto, pdf-detector, tracker, binect-api

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-13 00:30:39 +01:00

94 lines
1.7 KiB
TypeScript

/**
* Jest test setup
* Mocks browser APIs
*/
import { webcrypto } from 'crypto';
// Mock Web Crypto API
Object.defineProperty(globalThis, 'crypto', {
value: webcrypto
});
// Mock Chrome API
const mockChrome = {
storage: {
local: {
get: jest.fn(),
set: jest.fn(),
remove: jest.fn(),
clear: jest.fn()
}
},
runtime: {
sendMessage: jest.fn(),
onMessage: {
addListener: jest.fn()
},
onInstalled: {
addListener: jest.fn()
},
onStartup: {
addListener: jest.fn()
},
getURL: jest.fn((path) => `chrome-extension://test/${path}`)
},
downloads: {
search: jest.fn(),
onChanged: {
addListener: jest.fn()
}
},
action: {
setBadgeText: jest.fn(),
setBadgeBackgroundColor: jest.fn()
},
alarms: {
create: jest.fn(),
onAlarm: {
addListener: jest.fn()
}
},
tabs: {
create: jest.fn(),
onUpdated: {
addListener: jest.fn()
},
query: jest.fn()
}
};
Object.defineProperty(globalThis, 'chrome', {
value: mockChrome,
writable: true
});
// Mock fetch
Object.defineProperty(globalThis, 'fetch', {
value: jest.fn(),
writable: true
});
// Mock btoa/atob
Object.defineProperty(globalThis, 'btoa', {
value: (str: string) => Buffer.from(str, 'binary').toString('base64'),
writable: true
});
Object.defineProperty(globalThis, 'atob', {
value: (str: string) => Buffer.from(str, 'base64').toString('binary'),
writable: true
});
// Mock TextEncoder/TextDecoder (from util)
import { TextEncoder, TextDecoder } from 'util';
Object.defineProperty(globalThis, 'TextEncoder', {
value: TextEncoder,
writable: true
});
Object.defineProperty(globalThis, 'TextDecoder', {
value: TextDecoder,
writable: true
});