diff --git a/tests/unit/gameState.test.js b/tests/unit/gameState.test.js index 862ba8f..6ef3818 100644 --- a/tests/unit/gameState.test.js +++ b/tests/unit/gameState.test.js @@ -79,6 +79,10 @@ describe('Game Logic (gameState.js)', () => { expect(state.visuForm).toBe(false) expect(state.visuStriscia).toBe(true) }) + + it('dovrebbe avere timeout false', () => { + expect(state.timeout).toBe(false) + }) }) // ============================================= @@ -479,6 +483,14 @@ describe('Game Logic (gameState.js)', () => { const s = applyAction(state, { type: 'toggleOrder' }) expect(s.order).toBe(false) }) + + it('toggleTimeout: false → true → false', () => { + expect(state.timeout).toBe(false) + const s1 = applyAction(state, { type: 'toggleTimeout' }) + expect(s1.timeout).toBe(true) + const s2 = applyAction(s1, { type: 'toggleTimeout' }) + expect(s2.timeout).toBe(false) + }) }) // ============================================= diff --git a/tests/unit/spotUtils.test.js b/tests/unit/spotUtils.test.js new file mode 100644 index 0000000..126b8f6 --- /dev/null +++ b/tests/unit/spotUtils.test.js @@ -0,0 +1,38 @@ +import { describe, it, expect, beforeEach, afterEach } from 'vitest' +import { mkdtempSync, writeFileSync, rmSync } from 'fs' +import { tmpdir } from 'os' +import { join } from 'path' +import { listSpotVideos } from '../../src/spot-utils.js' + +describe('listSpotVideos (spot-utils.js)', () => { + let dir + + beforeEach(() => { + dir = mkdtempSync(join(tmpdir(), 'spot-test-')) + }) + + afterEach(() => { + rmSync(dir, { recursive: true, force: true }) + }) + + it('ritorna [] se la cartella non esiste', () => { + expect(listSpotVideos(join(dir, 'inesistente'))).toEqual([]) + }) + + it('ritorna [] se la cartella è vuota', () => { + expect(listSpotVideos(dir)).toEqual([]) + }) + + it('elenca solo i file .mp4, ordinati alfabeticamente', () => { + writeFileSync(join(dir, 'b.mp4'), '') + writeFileSync(join(dir, 'a.mp4'), '') + writeFileSync(join(dir, 'note.txt'), '') + writeFileSync(join(dir, 'foto.png'), '') + expect(listSpotVideos(dir)).toEqual(['a.mp4', 'b.mp4']) + }) + + it('riconosce l\'estensione .mp4 senza distinzione di maiuscole', () => { + writeFileSync(join(dir, 'SPOT.MP4'), '') + expect(listSpotVideos(dir)).toEqual(['SPOT.MP4']) + }) +})