9d8a40beab
build / build (push) Successful in 1m10s
只在流水及明细范围保留表头条件,统计请求只携带已执行时间和关键词。 拒绝将被字段筛选的返回误作全范围看板,原查询对象保持不变。 验证:请求隔离/错误范围拒绝先红后绿,流水筛选与实时范围回归通过;完整门禁及原生备份恢复通过。
98 lines
4.2 KiB
TypeScript
98 lines
4.2 KiB
TypeScript
import { afterEach, describe, it, expect, vi } from 'vitest'
|
|
import { fetchQADashboard, parseQADashboard } from './qaDashboardData'
|
|
import { dashboardFixture } from './qaDashboard.fixture'
|
|
const reported = {
|
|
week: '2026WK40',
|
|
week_start: '2026-09-28T00:00:00+08:00',
|
|
week_end: '2026-10-05T00:00:00+08:00',
|
|
coverage_percent: 57.23,
|
|
correctness_percent: 92.34,
|
|
source: 'user_provided_history',
|
|
}
|
|
afterEach(() => vi.unstubAllGlobals())
|
|
describe('dashboard scope is independent of ledger header filters', () => {
|
|
const query = { start: dashboardFixture.start, end: dashboardFixture.end, keyword: 'MG400', cursor: '' }
|
|
const filters = {
|
|
coverage: '否',
|
|
is_correct: '待确认',
|
|
product_category: 'MG400',
|
|
problem_type: '故障',
|
|
root_cause: '__empty__',
|
|
}
|
|
it('sends only the executed time and keyword, leaving all five header filters on the ledger', async () => {
|
|
const fetcher = vi.fn(async (_url: string, options: RequestInit) => {
|
|
const sent = JSON.parse(String(options.body))
|
|
return new Response(
|
|
JSON.stringify({ data: { ...dashboardFixture, keyword: query.keyword, filters: sent.filters ?? {} } }),
|
|
{ status: 200 }
|
|
)
|
|
})
|
|
vi.stubGlobal('fetch', fetcher)
|
|
const input = { ...query, filters: { ...filters } }
|
|
const data = await fetchQADashboard(input)
|
|
expect(JSON.parse(String(fetcher.mock.calls[0][1].body))).toEqual({
|
|
start: query.start,
|
|
end: query.end,
|
|
keyword: query.keyword,
|
|
})
|
|
expect(data.filters).toEqual({})
|
|
expect(input.filters).toEqual(filters)
|
|
})
|
|
it('rejects a field-filtered response instead of presenting it as the full dashboard', async () => {
|
|
vi.stubGlobal(
|
|
'fetch',
|
|
vi.fn().mockResolvedValue(
|
|
new Response(JSON.stringify({ data: { ...dashboardFixture, keyword: query.keyword, filters } }), {
|
|
status: 200,
|
|
})
|
|
)
|
|
)
|
|
await expect(fetchQADashboard({ ...query, filters })).rejects.toThrow('看板返回范围与当前查询不一致')
|
|
})
|
|
})
|
|
|
|
describe('reported historical rates', () => {
|
|
it('keeps supplied percentages without inventing denominator or freeze time', () => {
|
|
const result = parseQADashboard({ ...dashboardFixture, reported_weeks: [reported] })
|
|
expect(result.reported_weeks).toEqual([reported])
|
|
expect(result.frozen_weeks).toEqual(parseQADashboard(dashboardFixture).frozen_weeks)
|
|
expect(result.quality).toEqual(parseQADashboard(dashboardFixture).quality)
|
|
})
|
|
it('rejects invalid, duplicate, future, wrongly labelled and keyword-scoped supplied history', () => {
|
|
for (const input of [
|
|
{ ...dashboardFixture, reported_weeks: [reported, reported] },
|
|
{ ...dashboardFixture, reported_weeks: [{ ...reported, denominator: 100 }] },
|
|
{ ...dashboardFixture, reported_weeks: [{ ...reported, coverage_percent: 100.01 }] },
|
|
{ ...dashboardFixture, reported_weeks: [{ ...reported, correctness_percent: null }] },
|
|
{ ...dashboardFixture, reported_weeks: [{ ...reported, source: 'frozen' }] },
|
|
{ ...dashboardFixture, reported_weeks: [{ ...reported, week: '2026WK41' }] },
|
|
{ ...dashboardFixture, reported_weeks: [{ ...reported, week_end: '2027-01-01T00:00:00+08:00' }] },
|
|
{ ...dashboardFixture, keyword: 'needle', reported_weeks: [reported] },
|
|
])
|
|
expect(() => parseQADashboard(input)).toThrow()
|
|
})
|
|
})
|
|
|
|
describe('complete dashboard data contract', () => {
|
|
it('keeps distinct cumulative, week, month and genuinely frozen periods', () => {
|
|
const data = parseQADashboard(dashboardFixture)
|
|
expect([data.total_issues, data.new_this_week, data.regions[0].questions]).toEqual([4, 2, 3])
|
|
expect(data.frozen_weeks[0].coverage.percent).toBeNull()
|
|
expect(data.frozen_weeks[1].coverage.percent).toBe(50)
|
|
})
|
|
it('rejects fabricated percentages, category omissions and historical backfill', () => {
|
|
for (const bad of [
|
|
{ ...dashboardFixture, new_this_week: 5 },
|
|
{ ...dashboardFixture, products: [] },
|
|
{ ...dashboardFixture, regions: [{ ...dashboardFixture.regions[0], frequency: 3 }] },
|
|
{
|
|
...dashboardFixture,
|
|
frozen_weeks: [
|
|
{ ...dashboardFixture.frozen_weeks[0], coverage: { numerator: 1, denominator: 2, percent: 50 } },
|
|
],
|
|
},
|
|
])
|
|
expect(() => parseQADashboard(bad)).toThrow()
|
|
})
|
|
})
|