25ebd667f1
新增 shop-filter-bar-state.ts:筛选草稿→已应用快照与重置语义,筛选变更标记 回到第 1 页重新加载;纯逻辑可测。 TDD: task-98.test.ts 8 用例先 RED 后 GREEN。
73 lines
3.3 KiB
TypeScript
73 lines
3.3 KiB
TypeScript
import test from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { readSource } from './helpers.ts'
|
|
import {
|
|
clearShopFilterState,
|
|
commitShopFilterDraft,
|
|
createShopFilterBarState,
|
|
isShopFilterDraftApplied,
|
|
shopFilterDraftFromInput,
|
|
} from '../src/pages/shop/shop-filter-bar-state.ts'
|
|
|
|
test('test_task_098_shop_filter_bar_normal_primary_path', () => {
|
|
// 正常主路径:草稿输入提交后成为已应用筛选并触发回到首页加载。
|
|
const state = commitShopFilterDraft(
|
|
createShopFilterBarState(),
|
|
shopFilterDraftFromInput({ groupId: '3', shopName: ' 主店 ' }),
|
|
)
|
|
assert.equal(state.applied!.groupId, 3)
|
|
assert.equal(state.applied!.shopName, '主店')
|
|
assert.equal(state.returnFirstPage, true, '筛选变更应回到第 1 页')
|
|
})
|
|
|
|
test('test_task_098_shop_filter_bar_normal_variant_input', () => {
|
|
// 正常变体:重置筛选后无已应用条件且触发首页加载。
|
|
const base = createShopFilterBarState()
|
|
const cleared = clearShopFilterState(base)
|
|
assert.equal(cleared.applied, null)
|
|
assert.equal(cleared.returnFirstPage, true)
|
|
})
|
|
|
|
test('test_task_098_shop_filter_bar_repeated_is_idempotent', () => {
|
|
// 正常重复:提交同一草稿结果稳定、不改草稿入参。
|
|
const draft = shopFilterDraftFromInput({ groupId: '2', shopName: '店' })
|
|
const a = commitShopFilterDraft(createShopFilterBarState(), draft)
|
|
const b = commitShopFilterDraft(createShopFilterBarState(), draft)
|
|
assert.deepEqual(a.applied, b.applied)
|
|
assert.equal((draft as { shopName: string }).shopName, '店')
|
|
})
|
|
|
|
test('test_task_098_shop_filter_bar_boundary_empty_input', () => {
|
|
// 边界空值:无筛选条件提交后应用为空且不再标记变更。
|
|
const applied = commitShopFilterDraft(createShopFilterBarState(), { groupId: null, shopName: '' }).applied
|
|
assert.deepEqual(applied, { groupId: null, shopName: '' })
|
|
assert.equal(isShopFilterDraftApplied({ groupId: null, shopName: '' }, applied), true)
|
|
})
|
|
|
|
test('test_task_098_shop_filter_bar_boundary_single_item', () => {
|
|
// 边界单元素:仅分组筛选提交应用。
|
|
const state = commitShopFilterDraft(createShopFilterBarState(), shopFilterDraftFromInput({ groupId: '9', shopName: '' }))
|
|
assert.equal(state.applied!.groupId, 9)
|
|
assert.equal(isShopFilterDraftApplied({ groupId: 9, shopName: '' }, state.applied), true)
|
|
})
|
|
|
|
test('test_task_098_shop_filter_bar_boundary_limit_or_missing_field', () => {
|
|
// 边界上限/缺字段:非法/空分组输入归一为无分组筛选。
|
|
const draft = shopFilterDraftFromInput({ groupId: 'abc', shopName: ' ' })
|
|
assert.equal(draft.groupId, null)
|
|
assert.equal(draft.shopName, '')
|
|
})
|
|
|
|
test('test_task_098_shop_filter_bar_invalid_input_rejected', () => {
|
|
// 异常输入:已应用筛选与草稿不一致时视为有变更(需重新加载)。
|
|
const state = commitShopFilterDraft(createShopFilterBarState(), { groupId: 1, shopName: 'A店' })
|
|
assert.equal(isShopFilterDraftApplied({ groupId: 1, shopName: 'B店' }, state.applied), false)
|
|
})
|
|
|
|
test('test_task_098_shop_filter_bar_dependency_failure_returns_actionable_message', () => {
|
|
// 依赖失败/可操作:筛选栏状态纯逻辑、无框架/http。
|
|
const mod = readSource('src/pages/shop/shop-filter-bar-state.ts')
|
|
assert.equal(/axios|http\.|vue/.test(mod), false, '筛选栏状态保持纯逻辑')
|
|
assert.match(mod, /returnFirstPage/)
|
|
})
|