Files
CONSOLGAMES/tests/sim/clock.test.ts
T

34 lines
1.2 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { isOpen, tick } from '../../src/sim/clock';
import { CLOSE_MINUTES, createNewGame, OPEN_MINUTES } from '../../src/sim/state';
import { testCatalog } from './helpers';
const catalog = testCatalog();
describe('clock', () => {
it('opens the shop at 9:00 with no customers before', () => {
const s = createNewGame(1);
const events = tick(s, catalog, 60);
expect(s.minutes).toBe(OPEN_MINUTES);
expect(events).toEqual([{ type: 'shop_opened' }]);
expect(isOpen(s)).toBe(true);
});
it('brings customers during opening hours and closes at 19:00', () => {
const s = createNewGame(1);
s.reputation = 100;
const events = tick(s, catalog, 24 * 60);
expect(s.minutes).toBe(CLOSE_MINUTES);
expect(events.filter((e) => e.type === 'customer_arrived').length).toBeGreaterThan(10);
expect(events[events.length - 1]).toEqual({ type: 'shop_closed' });
expect(isOpen(s)).toBe(false);
});
it('does nothing once closed', () => {
const s = createNewGame(1);
tick(s, catalog, 24 * 60);
expect(tick(s, catalog, 60)).toEqual([]);
expect(s.minutes).toBe(CLOSE_MINUTES);
});
});