40 lines
2.1 KiB
TypeScript
40 lines
2.1 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';
|
|
|
|
const props = {
|
|
target: 'target', leaderName: (id: string) => id,
|
|
locationName: (id: string) => id, playerName: (id: string) => id,
|
|
};
|
|
const preview = (text: string, scope: 'fact' | 'currentTurn' = 'fact') =>
|
|
renderToStaticMarkup(createElement(FreeformFactPreview, { ...props, scope, text }));
|
|
|
|
void test('the editor previews a compound prediction and physical-force question', () => {
|
|
const html = preview('Did you predict Guild and do you have at least 3 forces in your reserves?');
|
|
assert.match(html, /Recognized freeform question/);
|
|
assert.match(html, /your recorded Bene Gesserit prediction names Spacing Guild/);
|
|
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/);
|
|
});
|
|
|
|
void test('the editor previews a three-clause aggregate without exposing answers', () => {
|
|
const text = 'Did you predict Guild and is your predicted turn at least 5 and do you have at least 3 forces in your reserves?';
|
|
const html = preview(text);
|
|
assert.match(html, /Recognized freeform question/);
|
|
assert.match(html, /your recorded Bene Gesserit prediction names Spacing Guild/);
|
|
assert.match(html, /the turn in your recorded Bene Gesserit prediction is at least 5/);
|
|
assert.match(html, /currently have at least 3 physical forces in your reserves/);
|
|
assert.equal((html.match(/AND/g) ?? []).length, 2);
|
|
assert.doesNotMatch(html, /Your current game information establishes/);
|
|
assert.match(preview(text, 'currentTurn'), /not automatically interpreted/);
|
|
});
|
|
|
|
void test('ambiguous mixed operators remain player-managed', () => {
|
|
const html = preview('Did you predict Guild and is your predicted turn at least 5 or do you have at least 3 forces in your reserves?');
|
|
assert.match(html, /not automatically interpreted/);
|
|
assert.doesNotMatch(html, /Recognized freeform question/);
|
|
});
|