test/app-state.test.ts (1757 bytes)
1 import fc from 'fast-check'; 2 import { describe, expect, it } from 'vitest'; 3 import { backStep, keepScreenOn } from '../src/app-state'; 4 import type { FollowMode } from '../src/follower'; 5 6 describe('backStep', () => { 7 it('closes the page jump first, then the drawer', () => { 8 expect(backStep({ jump: true, drawer: true })).toBe('close-jump'); 9 expect(backStep({ jump: true, drawer: false })).toBe('close-jump'); 10 expect(backStep({ jump: false, drawer: true })).toBe('close-drawer'); 11 }); 12 13 it('puts the reader in the background, and never finishes it', () => { 14 // The phone finding: Back destroyed the activity, and the book was lost. 15 expect(backStep({ jump: false, drawer: false })).toBe('minimize'); 16 }); 17 }); 18 19 describe('keepScreenOn', () => { 20 const on = { active: true, book: true, playing: true, mode: 'highlight' as FollowMode }; 21 22 it('keeps the screen on during read-along, also in "Turn pages only"', () => { 23 expect(keepScreenOn(on)).toBe(true); 24 expect(keepScreenOn({ ...on, mode: 'pages' })).toBe(true); 25 }); 26 27 it('lets the screen turn off when one condition is missing', () => { 28 const cases = fc.record({ 29 active: fc.boolean(), 30 book: fc.boolean(), 31 playing: fc.boolean(), 32 mode: fc.constantFrom<FollowMode>('highlight', 'pages', 'off'), 33 }); 34 fc.assert( 35 fc.property(cases, (s) => { 36 const all = s.active && s.book && s.playing && s.mode !== 'off'; 37 expect(keepScreenOn(s)).toBe(all); 38 }), 39 ); 40 expect(keepScreenOn({ ...on, active: false })).toBe(false); 41 expect(keepScreenOn({ ...on, book: false })).toBe(false); 42 expect(keepScreenOn({ ...on, playing: false })).toBe(false); 43 expect(keepScreenOn({ ...on, mode: 'off' })).toBe(false); 44 }); 45 });