Files
scrabble-game/ui/src/lib/variants.test.ts
T
Ilia Denisov 54bc31c619 fix(ui): default the profileless client to Erudit only, not every variant
availableVariants fell back to all three variants when the player had no
stored preferences. A fresh offline native launch boots with no profile, so
New Game exposed the English game before the player opted in — contrary to the
backend's Erudit-only new-account default (docs/FUNCTIONAL.md). Fall back to
DEFAULT_VARIANTS (Erudit only) instead; all dictionaries stay bundled.
2026-07-14 21:57:21 +02:00

74 lines
2.5 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import {
ALL_VARIANTS,
DEFAULT_VARIANTS,
availableVariants,
supportsMultipleWordsToggle,
multipleWordsForRequest,
usesStarBlank,
BLANK_STAR,
} from './variants';
describe('ALL_VARIANTS', () => {
it('lists variants Erudit-first', () => {
expect(ALL_VARIANTS.map((v) => v.id)).toEqual(['erudit_ru', 'scrabble_ru', 'scrabble_en']);
});
});
describe('availableVariants', () => {
it('falls back to the Erudit-only default for an empty or absent preference set', () => {
const fallback = ALL_VARIANTS.filter((v) => DEFAULT_VARIANTS.includes(v.id));
expect(fallback.map((v) => v.id)).toEqual(['erudit_ru']);
expect(availableVariants([])).toEqual(fallback);
expect(availableVariants(undefined)).toEqual(fallback);
});
it('offers only the preferred variants', () => {
expect(availableVariants(['scrabble_en']).map((v) => v.id)).toEqual(['scrabble_en']);
expect(availableVariants(['erudit_ru', 'scrabble_en']).map((v) => v.id)).toEqual(['erudit_ru', 'scrabble_en']);
});
it('keeps the Erudit-first catalogue order regardless of preference order', () => {
expect(availableVariants(['scrabble_en', 'erudit_ru', 'scrabble_ru']).map((v) => v.id)).toEqual([
'erudit_ru',
'scrabble_ru',
'scrabble_en',
]);
});
});
describe('supportsMultipleWordsToggle', () => {
it('is true for Russian variants only', () => {
expect(supportsMultipleWordsToggle('scrabble_ru')).toBe(true);
expect(supportsMultipleWordsToggle('erudit_ru')).toBe(true);
expect(supportsMultipleWordsToggle('scrabble_en')).toBe(false);
});
});
describe('multipleWordsForRequest', () => {
it('carries the toggle for Russian games', () => {
expect(multipleWordsForRequest('scrabble_ru', false)).toBe(false);
expect(multipleWordsForRequest('scrabble_ru', true)).toBe(true);
expect(multipleWordsForRequest('erudit_ru', false)).toBe(false);
});
it('forces standard (true) for English whatever the toggle', () => {
expect(multipleWordsForRequest('scrabble_en', false)).toBe(true);
expect(multipleWordsForRequest('scrabble_en', true)).toBe(true);
});
});
describe('usesStarBlank', () => {
it('marks the blank with a star for Erudit only', () => {
expect(usesStarBlank('erudit_ru')).toBe(true);
expect(usesStarBlank('scrabble_ru')).toBe(false);
expect(usesStarBlank('scrabble_en')).toBe(false);
});
it('BLANK_STAR is the heavy teardrop-spoked asterisk (U+273B)', () => {
expect(BLANK_STAR).toBe('✻');
expect(BLANK_STAR.codePointAt(0)).toBe(0x273b);
});
});