Stage 7: regression tests for the polished UI (logic + behaviour)
Lock the polish branch's behaviour so a future UI edit surfaces as a failing
assertion to re-agree or fix.
Unit (vitest, node env):
- placement: recallIndex, cellOccupied/isBlankSlot, non-linear direction, the
single-tile submit default, and placementFromHint blank-fallback / rack-exhausted.
- banner: the marquee scroll-cycle repeat-then-advance, stop(), root-relative and
multiple links.
- client.GatewayError. Extract the check-word constraints out of Game.svelte into a
pure lib/checkword.ts (sanitize + canCheck) and cover them.
E2E (playwright mock, Chromium + WebKit):
- commit via the 🏁 control, history slide-down + close, the exchange dialog,
check-word input sanitising + verdict, resign-to-finished, and the Settings
board-label mode changing the on-board labels.
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { canCheckWord, MAX_WORD_LEN, sanitizeCheckWord } from './checkword';
|
||||
|
||||
const EN = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
|
||||
|
||||
describe('sanitizeCheckWord', () => {
|
||||
it('upper-cases and keeps only letters of the alphabet', () => {
|
||||
expect(sanitizeCheckWord('ca7t!', EN)).toBe('CAT');
|
||||
expect(sanitizeCheckWord(' Hi 9 ', EN)).toBe('HI');
|
||||
});
|
||||
|
||||
it('drops characters outside the active alphabet', () => {
|
||||
expect(sanitizeCheckWord('cat', ['C', 'A'])).toBe('CA'); // T not in this alphabet
|
||||
const RU = 'КОТ'.split('');
|
||||
expect(sanitizeCheckWord('коt', RU)).toBe('КО'); // cyrillic kept, latin "t" dropped
|
||||
});
|
||||
|
||||
it('caps the length at MAX_WORD_LEN', () => {
|
||||
expect(sanitizeCheckWord('A'.repeat(30), EN)).toHaveLength(MAX_WORD_LEN);
|
||||
});
|
||||
});
|
||||
|
||||
describe('canCheckWord', () => {
|
||||
it('allows a fresh, in-range word', () => {
|
||||
expect(canCheckWord('CAT', false, false)).toBe(true);
|
||||
});
|
||||
|
||||
it('rejects an out-of-range length', () => {
|
||||
expect(canCheckWord('A', false, false)).toBe(false); // too short
|
||||
expect(canCheckWord('A'.repeat(MAX_WORD_LEN + 1), false, false)).toBe(false); // too long
|
||||
});
|
||||
|
||||
it('rejects an already-checked word or a cooling-down state', () => {
|
||||
expect(canCheckWord('CAT', true, false)).toBe(false);
|
||||
expect(canCheckWord('CAT', false, true)).toBe(false);
|
||||
});
|
||||
|
||||
it('trims surrounding whitespace before measuring length', () => {
|
||||
expect(canCheckWord(' ok ', false, false)).toBe(true);
|
||||
expect(canCheckWord(' a ', false, false)).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user