86 lines
3.2 KiB
JavaScript
86 lines
3.2 KiB
JavaScript
|
|
const IntroScreen = require('../../src/js/screens/intro');
|
||
|
|
|
||
|
|
describe('IntroScreen', () => {
|
||
|
|
let introScreen;
|
||
|
|
|
||
|
|
beforeEach(() => {
|
||
|
|
introScreen = new IntroScreen();
|
||
|
|
});
|
||
|
|
|
||
|
|
describe('constructor', () => {
|
||
|
|
it('should initialize with correct default values', () => {
|
||
|
|
expect(introScreen.title).toBe('WINGS88');
|
||
|
|
expect(introScreen.credits).toBe('A RetroWeb Games Production');
|
||
|
|
expect(introScreen.instructions).toBe('Use arrow keys to fly\nPress SPACE to start');
|
||
|
|
expect(introScreen.options).toEqual(['Start Game', 'Instructions', 'Quit']);
|
||
|
|
expect(introScreen.selectedOption).toBe(0);
|
||
|
|
expect(introScreen.audioContext).toBeNull();
|
||
|
|
expect(introScreen.musicTrack).toBeNull();
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
describe('moveSelection', () => {
|
||
|
|
it('should move selection up', () => {
|
||
|
|
introScreen.selectedOption = 1;
|
||
|
|
// Mock render to prevent DOM access
|
||
|
|
introScreen.render = jest.fn();
|
||
|
|
introScreen.moveSelection(-1);
|
||
|
|
expect(introScreen.selectedOption).toBe(0);
|
||
|
|
expect(introScreen.render).toHaveBeenCalled();
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should move selection down', () => {
|
||
|
|
introScreen.selectedOption = 0;
|
||
|
|
// Mock render to prevent DOM access
|
||
|
|
introScreen.render = jest.fn();
|
||
|
|
introScreen.moveSelection(1);
|
||
|
|
expect(introScreen.selectedOption).toBe(1);
|
||
|
|
expect(introScreen.render).toHaveBeenCalled();
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should wrap around from last to first', () => {
|
||
|
|
introScreen.selectedOption = 2;
|
||
|
|
// Mock render to prevent DOM access
|
||
|
|
introScreen.render = jest.fn();
|
||
|
|
introScreen.moveSelection(1);
|
||
|
|
expect(introScreen.selectedOption).toBe(0);
|
||
|
|
expect(introScreen.render).toHaveBeenCalled();
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should wrap around from first to last', () => {
|
||
|
|
introScreen.selectedOption = 0;
|
||
|
|
// Mock render to prevent DOM access
|
||
|
|
introScreen.render = jest.fn();
|
||
|
|
introScreen.moveSelection(-1);
|
||
|
|
expect(introScreen.selectedOption).toBe(2);
|
||
|
|
expect(introScreen.render).toHaveBeenCalled();
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
describe('selectOption', () => {
|
||
|
|
it('should handle Start Game selection', () => {
|
||
|
|
introScreen.selectedOption = 0;
|
||
|
|
const logSpy = jest.spyOn(console, 'log');
|
||
|
|
introScreen.selectOption();
|
||
|
|
expect(logSpy).toHaveBeenCalledWith('Starting game...');
|
||
|
|
logSpy.mockRestore();
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should handle Instructions selection', () => {
|
||
|
|
introScreen.selectedOption = 1;
|
||
|
|
const logSpy = jest.spyOn(console, 'log');
|
||
|
|
introScreen.selectOption();
|
||
|
|
expect(logSpy).toHaveBeenCalledWith('Showing instructions...');
|
||
|
|
logSpy.mockRestore();
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should handle Quit selection', () => {
|
||
|
|
introScreen.selectedOption = 2;
|
||
|
|
const logSpy = jest.spyOn(console, 'log');
|
||
|
|
introScreen.selectOption();
|
||
|
|
expect(logSpy).toHaveBeenCalledWith('Quitting game...');
|
||
|
|
logSpy.mockRestore();
|
||
|
|
});
|
||
|
|
});
|
||
|
|
});
|