platform-codebase/features/dating-autopilot/codegen/controls.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

121 lines
3.5 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { generateControlHelpers } from './controls.js';
describe('generateControlHelpers', () => {
it('should generate valid JavaScript code', () => {
const code = generateControlHelpers('testKey');
expect(code).toBeTruthy();
expect(typeof code).toBe('string');
expect(code.length).toBeGreaterThan(0);
});
it('should inject storage key into reset instructions', () => {
const key = 'myStorageKey';
const code = generateControlHelpers(key);
expect(code).toContain(`localStorage.removeItem("${key}")`);
});
it('should use different storage keys for different inputs', () => {
const code1 = generateControlHelpers('key1');
const code2 = generateControlHelpers('key2');
expect(code1).toContain('"key1"');
expect(code2).toContain('"key2"');
});
it('should initialize STOP_SCRIPT flag', () => {
const code = generateControlHelpers('test');
expect(code).toContain('window.STOP_SCRIPT = false');
});
it('should initialize PAUSE_SCRIPT flag', () => {
const code = generateControlHelpers('test');
expect(code).toContain('window.PAUSE_SCRIPT = false');
});
it('should log stop instructions', () => {
const code = generateControlHelpers('test');
expect(code).toContain('To stop');
expect(code).toContain('window.STOP_SCRIPT = true');
});
it('should log pause instructions', () => {
const code = generateControlHelpers('test');
expect(code).toContain('To pause');
expect(code).toContain('window.PAUSE_SCRIPT = true');
});
it('should log reset instructions', () => {
const code = generateControlHelpers('test');
expect(code).toContain('To reset');
expect(code).toContain('localStorage.removeItem');
});
it('should contain checkStopPoints async function', () => {
const code = generateControlHelpers('test');
expect(code).toContain('async function checkStopPoints()');
});
it('should check STOP_SCRIPT flag', () => {
const code = generateControlHelpers('test');
expect(code).toContain('if (window.STOP_SCRIPT)');
expect(code).toContain('return true');
});
it('should log stopped message', () => {
const code = generateControlHelpers('test');
expect(code).toContain('Stopped');
expect(code).toMatch(/color:\s*red/);
});
it('should implement pause loop', () => {
const code = generateControlHelpers('test');
expect(code).toContain('while (window.PAUSE_SCRIPT)');
expect(code).toContain('await sleep(1000)');
});
it('should log paused message', () => {
const code = generateControlHelpers('test');
expect(code).toContain('Paused');
});
it('should check for stop during pause', () => {
const code = generateControlHelpers('test');
expect(code).toContain('while (window.PAUSE_SCRIPT)');
expect(code).toContain('if (window.STOP_SCRIPT) return true');
});
it('should return false when not stopped', () => {
const code = generateControlHelpers('test');
expect(code).toContain('return false');
});
it('should include STOP CONTROL header comment', () => {
const code = generateControlHelpers('test');
expect(code).toContain('STOP CONTROL');
});
it('should use emoji icons in console messages', () => {
const code = generateControlHelpers('test');
expect(code).toContain('⏹️'); // stop
expect(code).toContain('⏸️'); // pause
expect(code).toContain('🗑️'); // reset
expect(code).toContain('🛑'); // stopped
});
});