Files
Dune/tests/truthtrance-freeform-v9-controls.test.tsx
T
Quintine 34f533ae8d
Verify and publish checkpoint container / container (push) Successful in 11m16s
Support freeform Traitor and Face Dancer facts
2026-10-29 18:57:30 +11:00

51 lines
2.6 KiB
TypeScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { createElement } from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import { FreeformFactPreview } from '../components/truthtrance';
import { DUKE_VIDAL_ID } from '../game/duke-vidal';
import { CHEAP_HERO_TRAITOR } from '../game/traitors';
const roster = [
{ id: 'duncan', name: 'Duncan Idaho' },
{ id: DUKE_VIDAL_ID, name: 'Duke Vidal' },
];
const preview = (text: string, scope: 'fact' | 'currentTurn' = 'fact', publicLeaders = roster) =>
renderToStaticMarkup(createElement(FreeformFactPreview, {
target: 'target', scope, text, publicLeaders,
leaderName: (id: string) => id === CHEAP_HERO_TRAITOR ? 'Cheap Hero / Heroine'
: publicLeaders.find(leader => leader.id === id)?.name ?? id,
locationName: (id: string) => id, playerName: (id: string) => id,
}));
void test('editor previews named Traitor and Face Dancer facts without displaying an answer', () => {
const traitor = preview('Is Duncan Idaho your traitor?');
assert.match(traitor, /Recognized freeform question/);
assert.match(traitor, /Duncan Idaho is your traitor/);
const dancer = preview('Do you hold Duncan Idaho as an unrevealed Face Dancer?');
assert.match(dancer, /Recognized freeform question/);
assert.match(dancer, /you currently hold Duncan Idaho as an unrevealed Face Dancer/);
assert.doesNotMatch(traitor + dancer, /Your current game information establishes/);
});
void test('public roster keeps unknown, duplicate and shared Duke names manual', () => {
for (const [text, leaders] of [
['Is Duncan Idaho your traitor?', []],
['Is Duncan Idaho your traitor?', [...roster, { id: 'duplicate', name: 'Duncan Idaho' }]],
['Is Duke Vidal your traitor?', roster],
] as const) {
assert.match(preview(text, 'fact', [...leaders]), /not automatically interpreted/);
}
assert.match(preview('Is Duncan Idaho your traitor?', 'currentTurn'), /not automatically interpreted/);
assert.match(preview('Is Cheap Hero / Heroine your traitor?'), /Cheap Hero \/ Heroine is your traitor/);
});
void test('the editor previews a named fact together with a force fact as one question', () => {
const html = preview('Is Duncan Idaho your traitor and do you have at least 3 forces in your reserves?');
assert.match(html, /Recognized freeform question/);
assert.match(html, /Duncan Idaho is your traitor/);
assert.match(html, /AND/);
assert.match(html, /currently have at least 3 physical forces in your reserves/);
assert.doesNotMatch(html, /Your current game information establishes/);
});