121 lines
3.5 KiB
TypeScript
Executable file
121 lines
3.5 KiB
TypeScript
Executable file
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
|
|
});
|
|
});
|