fix(game-ui): 자동 갱신 중 커맨드 입력값 보존

같은 명령의 field 계약과 유효한 select option이 유지되는 동안 사용자가 편집한 값을 보존한다. 장수 동향과 명령표 realtime 갱신을 함께 발생시키는 desktop/mobile Chromium 회귀 테스트를 추가한다.
This commit is contained in:
2026-08-19 13:28:11 +00:00
parent 54a5b91ca9
commit f01661bc08
4 changed files with 380 additions and 12 deletions
@@ -0,0 +1,81 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import {
commandArgumentFieldContract,
shouldPreserveCommandArgumentValue,
} from '../src/components/command/commandArgumentDraft.ts';
import type { CommandInputField, CommandOption } from '../src/components/command/types.ts';
const field = (kind: CommandInputField['kind'], optionSource?: CommandInputField['optionSource']): CommandInputField => ({
key: 'value',
label: '값',
kind,
required: true,
optionSource,
});
void test('preserves every user-editable non-select command argument across data refreshes', () => {
for (const [kind, value] of [
['text', '작성 중인 국명'],
['number', 777],
['boolean', false],
['numberTuple', [111, 222]],
] as const) {
const currentField = field(kind);
assert.equal(
shouldPreserveCommandArgumentValue(
currentField,
commandArgumentFieldContract(currentField),
{ value },
[]
),
true,
kind
);
}
});
void test('preserves a select only while its field contract and selected option remain available', () => {
const currentField = field('select', 'cities');
const options: CommandOption[] = [
{ value: 1, label: '업' },
{ value: 2, label: '허창' },
];
assert.equal(
shouldPreserveCommandArgumentValue(
currentField,
commandArgumentFieldContract(currentField),
{ value: 2 },
options
),
true
);
assert.equal(
shouldPreserveCommandArgumentValue(
currentField,
commandArgumentFieldContract(currentField),
{ value: 3 },
options
),
false
);
assert.equal(
shouldPreserveCommandArgumentValue(currentField, { kind: 'select', optionSource: 'nations' }, { value: 2 }, options),
false
);
});
void test('reinitializes hidden, new, and changed-kind fields', () => {
const hidden = field('hidden');
assert.equal(
shouldPreserveCommandArgumentValue(hidden, commandArgumentFieldContract(hidden), { value: 'old' }, []),
false
);
const text = field('text');
assert.equal(shouldPreserveCommandArgumentValue(text, undefined, { value: 'old' }, []), false);
assert.equal(shouldPreserveCommandArgumentValue(text, { kind: 'number' }, { value: 'old' }, []), false);
assert.equal(
shouldPreserveCommandArgumentValue(text, commandArgumentFieldContract(text), {}, []),
false
);
});