jiggle-genius
Version:
Jiggle Genius is a simple and efficient mouse jiggler CLI tool designed to keep your computer awake during those times when you need it to stay active. Whether you're preventing your screen from locking during a presentation or keeping your online status
86 lines (85 loc) • 3.85 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = require("../index");
jest.mock('robotjs', () => ({
setMouseDelay: jest.fn(),
getScreenSize: jest.fn(() => ({ width: 1920, height: 1080 })),
moveMouse: jest.fn(),
}));
describe('JiggleGenius', () => {
beforeEach(() => {
jest.spyOn(console, 'log').mockImplementation(() => { });
jest.spyOn(console, 'error').mockImplementation(() => { });
});
afterEach(() => {
jest.clearAllMocks();
});
describe('validateConfig', () => {
it('should accept valid configuration', () => {
const validConfig = {
duration: 30,
radius: 10,
speed: 5,
};
expect(() => (0, index_1.validateConfig)(validConfig)).not.toThrow();
});
it('should throw error for invalid duration', () => {
const invalidConfig = {
...index_1.DEFAULT_CONFIG,
duration: -1,
};
expect(() => (0, index_1.validateConfig)(invalidConfig)).toThrow(index_1.JiggleError);
expect(() => (0, index_1.validateConfig)(invalidConfig)).toThrow('Duration must be a positive number');
});
it('should throw error for invalid radius', () => {
const invalidConfig = {
...index_1.DEFAULT_CONFIG,
radius: 0,
};
expect(() => (0, index_1.validateConfig)(invalidConfig)).toThrow(index_1.JiggleError);
expect(() => (0, index_1.validateConfig)(invalidConfig)).toThrow('Radius must be a positive number');
});
it('should throw error for invalid speed', () => {
const invalidConfig = {
...index_1.DEFAULT_CONFIG,
speed: 11,
};
expect(() => (0, index_1.validateConfig)(invalidConfig)).toThrow(index_1.JiggleError);
expect(() => (0, index_1.validateConfig)(invalidConfig)).toThrow('Speed must be a number between 1 and 10');
});
it('should throw error for non-numeric values', () => {
const invalidConfig = {
...index_1.DEFAULT_CONFIG,
duration: '30',
};
expect(() => (0, index_1.validateConfig)(invalidConfig)).toThrow(index_1.JiggleError);
});
});
describe('calculateMousePosition', () => {
it('should calculate correct position for angle 0', () => {
const position = (0, index_1.calculateMousePosition)(100, 100, 0, 10);
expect(position.x).toBe(110); // cos(0) = 1
expect(position.y).toBe(100); // sin(0) = 0
});
it('should calculate correct position for angle 90 degrees', () => {
const position = (0, index_1.calculateMousePosition)(100, 100, Math.PI / 2, 10);
expect(position.x).toBe(100); // cos(90) = 0
expect(position.y).toBe(110); // sin(90) = 1
});
it('should calculate correct position for angle 180 degrees', () => {
const position = (0, index_1.calculateMousePosition)(100, 100, Math.PI, 10);
expect(position.x).toBe(90); // cos(180) = -1
expect(position.y).toBe(100); // sin(180) = 0
});
it('should round calculated positions', () => {
const position = (0, index_1.calculateMousePosition)(100, 100, Math.PI / 4, 10); // 45 degrees
expect(Number.isInteger(position.x)).toBe(true);
expect(Number.isInteger(position.y)).toBe(true);
});
it('should handle negative radius', () => {
const position = (0, index_1.calculateMousePosition)(100, 100, 0, -10);
expect(position.x).toBe(90);
expect(position.y).toBe(100);
});
});
});