Files
2026Technology-Competition/tests/test_chat_state.js
T

76 lines
2.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 前端核心状态逻辑单测(Node 原生 test runnerUMD 模块可在 Node 下 require
// 对应方案 docs/frontend_audit_plan.md §7.1 / §4.4
const test = require('node:test');
const assert = require('node:assert/strict');
const S = require('../src/genesis/server/static/chat_state.js');
test('autoBindProject: 启动无项目且有项目时自动绑首项', () => {
assert.equal(S.autoBindProject(null, [{ name: 'A' }, { name: 'B' }]), 'A');
});
test('autoBindProject: 指向已删除项目时回退首项', () => {
assert.equal(S.autoBindProject('X', [{ name: 'A' }]), 'A');
});
test('autoBindProject: 已选有效项目保持不变', () => {
assert.equal(S.autoBindProject('A', [{ name: 'A' }]), 'A');
});
test('shouldHideUploadSelect: 始终 false(选项目时也允许补传其它类型)', () => {
assert.equal(S.shouldHideUploadSelect(null, null), false);
assert.equal(S.shouldHideUploadSelect(null, 'A'), false);
assert.equal(S.shouldHideUploadSelect('A', null), false);
assert.equal(S.shouldHideUploadSelect('A', 'A'), false);
});
test('resolveUploadType: 始终尊重用户下拉选择(不再被项目绑定强制为 requirements', () => {
assert.equal(S.resolveUploadType(null, 'A', 'template'), 'template');
assert.equal(S.resolveUploadType(null, null, 'template'), 'template');
assert.equal(S.resolveUploadType('A', null, 'existing_system'), 'existing_system');
});
test('computeDrawerSnapshot: 去空白并以单元分隔符连接', () => {
assert.equal(S.computeDrawerSnapshot([' a ', 'b']), 'a\u0001b');
});
test('isDrawerDirty: 快照不同为脏,相同为干净', () => {
assert.equal(S.isDrawerDirty('x', 'y'), true);
assert.equal(S.isDrawerDirty('x', 'x'), false);
});
test('buildWelcome: 无项目提示新建/选择项目', () => {
assert.match(S.buildWelcome(null), /请新建项目|选择项目/);
});
test('buildWelcome: 有项目时提示由项目提供模板/规则/代码库', () => {
const txt = S.buildWelcome('A');
assert.match(txt, /项目「A」/);
assert.match(txt, /要件定义/);
});
test('emptyHeadline: 返回空态主标题', () => {
assert.match(S.emptyHeadline(), /有什么可以帮到你的/);
});
test('quickPrompts: 返回 4 条快捷提示且含影响调查', () => {
const p = S.quickPrompts();
assert.equal(p.length, 4);
assert.ok(p.includes('影响调查'));
});
test('autoBindProject: explicitNone=true 时不覆写(保留 null', () => {
assert.equal(S.autoBindProject(null, [{ name: 'A' }], true), null);
});
test('groupSessionsByProject: 按项目分组,空项目入 other', () => {
const r = S.groupSessionsByProject([
{ session_id: '1', project: 'A' },
{ session_id: '2', project: 'B' },
{ session_id: '3', project: '' },
{ session_id: '4' },
]);
assert.equal(r.byProject.A.length, 1);
assert.equal(r.byProject.B.length, 1);
assert.equal(r.other.length, 2);
});