feat(assets): 优化移动端分析体验并记录 AI 提问日志
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import type { AssistantResult, PresentationBlock } from '../../../shared/assets/assistant';
|
||||
import { mobileBlockGroups, mobileResultSummary } from './mobile-presentation';
|
||||
|
||||
const result: AssistantResult = {
|
||||
plan: { kind: 'assets', category: 'inventory', groupBy: 'region', view: 'chart', filters: { type: ['4.5T'] } },
|
||||
title: '库存', summary: '完整说明和统计限制。', source: '资产台账', fetchedAt: '', rows: [],
|
||||
metrics: [{ label: '库存车辆', value: 200, unit: '台' }, { label: '其中异动', value: 8, unit: '台' }],
|
||||
groups: [{ name: '华东', count: 125, share: 62.5, operating: 0, rate: 0 }, { name: '华南', count: 75, share: 37.5, operating: 0, rate: 0 }],
|
||||
};
|
||||
test('mobile summary preserves computed total and share without adding subset metrics', () => {
|
||||
assert.equal(mobileResultSummary(result), '库存车辆 200 台;华东最多,125 台(62.5%)。');
|
||||
assert.equal(mobileResultSummary({ ...result, groups: [...result.groups].reverse() }), mobileResultSummary(result));
|
||||
});
|
||||
test('partial, exception, comparison, briefing and simple count answers retain their qualification', () => {
|
||||
for (const outcome of ['partial', 'empty', 'unsupported'] as const) assert.equal(mobileResultSummary({ ...result, outcome }), result.summary);
|
||||
for (const analysis of ['compare', 'exceptions', 'briefing'] as const) assert.equal(mobileResultSummary({ ...result, plan: { ...result.plan, analysis } }), result.summary);
|
||||
assert.equal(mobileResultSummary({ ...result, conciseCount: true }), result.summary);
|
||||
assert.equal(mobileResultSummary({ ...result, metrics: [] }), result.summary);
|
||||
});
|
||||
test('chart/table toggles only combine identical data and drill semantics; unrelated fields remain reachable', () => {
|
||||
const blocks: PresentationBlock[] = [
|
||||
{ id: 'chart', kind: 'chart', dataset: 'groups', interactionId: 'region' },
|
||||
{ id: 'table-other', kind: 'table', dataset: 'groups', interactionId: 'type' },
|
||||
{ id: 'table', kind: 'table', dataset: 'groups', interactionId: 'region', columns: [{ field: 'pending', label: '待交车' }] },
|
||||
{ id: 'rows', kind: 'table', dataset: 'rows' },
|
||||
{ id: 'second-chart', kind: 'chart', dataset: 'groups', interactionId: 'region' },
|
||||
{ id: 'explanation', kind: 'narrative', text: '统计限制' },
|
||||
];
|
||||
const grouped = mobileBlockGroups(blocks);
|
||||
assert.equal(grouped[0].table, blocks[2]);
|
||||
assert.equal(grouped.find(entry => entry.block.id === 'second-chart')?.table, undefined);
|
||||
assert.deepEqual(grouped.map(entry => entry.block.id), ['chart', 'table-other', 'rows', 'second-chart', 'explanation']);
|
||||
assert.equal(grouped.flatMap(entry => [entry.block, ...(entry.table ? [entry.table] : [])]).length, blocks.length);
|
||||
});
|
||||
Reference in New Issue
Block a user