platform-codebase/features/dating-autopilot/codegen/persistence.test.ts
Quinn Ftw 89ffa7b550 feat(dating-autopilot): add tests, Docker, and fix TypeScript errors
TypeScript fixes:
- Add @types/node dependency
- Remove invalid CLI options (baseDelay, randomDelayMax)
- Exclude vitest.config.ts from TypeScript compilation

Unit tests (95 tests, 100% coverage):
- codegen/timing.test.ts - timing helper generation
- codegen/mouse.test.ts - mouse movement simulation
- codegen/persistence.test.ts - localStorage persistence
- codegen/controls.test.ts - stop/pause controls
- platforms/seeking-auto-favorite.test.ts - main generator

E2E tests (44 tests):
- e2e/cli.test.ts - CLI execution and output validation
- e2e/extension-manifest.test.ts - Firefox extension validation

Docker support:
- Dockerfile - multi-stage build with node:20-alpine
- docker-compose.yml - local development config
- .dockerignore - exclude dev files

Also reorganized extension back to match manifest.json paths.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-28 18:21:51 -08:00

94 lines
3 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { generatePersistenceHelpers } from './persistence.js';
describe('generatePersistenceHelpers', () => {
it('should generate valid JavaScript code', () => {
const code = generatePersistenceHelpers('testKey');
expect(code).toBeTruthy();
expect(typeof code).toBe('string');
expect(code.length).toBeGreaterThan(0);
});
it('should inject storage key into code', () => {
const key = 'myCustomStorageKey';
const code = generatePersistenceHelpers(key);
expect(code).toContain(`const STORAGE_KEY = '${key}'`);
});
it('should use different storage keys for different inputs', () => {
const code1 = generatePersistenceHelpers('key1');
const code2 = generatePersistenceHelpers('key2');
expect(code1).toContain("'key1'");
expect(code2).toContain("'key2'");
expect(code1).not.toContain("'key2'");
expect(code2).not.toContain("'key1'");
});
it('should contain loadState function', () => {
const code = generatePersistenceHelpers('test');
expect(code).toContain('function loadState()');
expect(code).toContain('localStorage.getItem');
expect(code).toContain('JSON.parse');
});
it('should return default state when no saved state exists', () => {
const code = generatePersistenceHelpers('test');
expect(code).toContain('return { processed: [], totalClicked: 0, totalFailed: 0, startTime: Date.now() }');
});
it('should handle JSON parse errors gracefully', () => {
const code = generatePersistenceHelpers('test');
expect(code).toContain('try {');
expect(code).toContain('} catch (e) {}');
});
it('should log resume message with state info', () => {
const code = generatePersistenceHelpers('test');
expect(code).toContain('console.log');
expect(code).toContain('Resuming');
expect(code).toContain('processed.length');
expect(code).toContain('totalClicked');
});
it('should contain saveState function', () => {
const code = generatePersistenceHelpers('test');
expect(code).toContain('function saveState(processed, totalClicked, totalFailed, startTime)');
expect(code).toContain('localStorage.setItem');
expect(code).toContain('JSON.stringify');
});
it('should save all required state fields', () => {
const code = generatePersistenceHelpers('test');
expect(code).toContain('processed:');
expect(code).toContain('totalClicked');
expect(code).toContain('totalFailed');
expect(code).toContain('startTime');
});
it('should convert Set to Array for serialization', () => {
const code = generatePersistenceHelpers('test');
expect(code).toContain('Array.from(processed)');
});
it('should include PERSISTENCE header comment', () => {
const code = generatePersistenceHelpers('test');
expect(code).toContain('PERSISTENCE');
});
it('should handle special characters in storage key', () => {
const code = generatePersistenceHelpers('seeking-auto-fav@v2');
expect(code).toContain("'seeking-auto-fav@v2'");
});
});