6ccd5ce1af
新增 shop-manage-list-state.ts:分组/店铺名筛选归一与激活判断、列表参数/ 查询序列化及分页信息派生;与 DTO 分页钳制对齐。 TDD: task-89.test.ts 8 用例先 RED 后 GREEN。
84 lines
3.7 KiB
TypeScript
84 lines
3.7 KiB
TypeScript
import test from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { readSource } from './helpers.ts'
|
|
import {
|
|
createShopManageFilter,
|
|
shopManageFilterActive,
|
|
shopManageFilterFromInput,
|
|
shopManagePageInfo,
|
|
toShopManageListParams,
|
|
} from '../src/pages/shop/shop-manage-list-state.ts'
|
|
|
|
test('test_task_089_shop_manage_filter_page_normal_primary_path', () => {
|
|
// 正常主路径:分组/店铺名筛选归一后转为 Java camelCase 列表查询。
|
|
const filter = shopManageFilterFromInput({ groupId: '3', shopName: ' 主店 ' })
|
|
assert.equal(filter.groupId, 3)
|
|
assert.equal(filter.shopName, '主店')
|
|
const params = toShopManageListParams(2, 20, filter)
|
|
assert.equal(params.page, 2)
|
|
assert.equal(params.pageSize, 20)
|
|
assert.equal(params.groupId, 3)
|
|
assert.equal(params.shopName, '主店')
|
|
})
|
|
|
|
test('test_task_089_shop_manage_filter_page_normal_variant_input', () => {
|
|
// 正常变体:只按店铺名筛选;分组为空字符串按无筛选。
|
|
const filter = shopManageFilterFromInput({ groupId: '', shopName: 'BlueWave' })
|
|
assert.equal(filter.groupId, null)
|
|
const params = toShopManageListParams(1, 15, filter)
|
|
assert.equal(params.shopName, 'BlueWave')
|
|
assert.equal(params.groupId, null)
|
|
})
|
|
|
|
test('test_task_089_shop_manage_filter_page_repeated_is_idempotent', () => {
|
|
// 正常重复:归一不改输入、结果稳定。
|
|
const input = { groupId: '5', shopName: ' 店 A ' }
|
|
assert.deepEqual(shopManageFilterFromInput(input), shopManageFilterFromInput(input))
|
|
assert.deepEqual(input, { groupId: '5', shopName: ' 店 A ' })
|
|
})
|
|
|
|
test('test_task_089_shop_manage_filter_page_boundary_empty_input', () => {
|
|
// 边界空值:空筛选回无筛选状态且不视为激活。
|
|
const filter = shopManageFilterFromInput({})
|
|
assert.equal(shopManageFilterActive(filter), false)
|
|
const params = toShopManageListParams(1, 15, createShopManageFilter())
|
|
assert.equal(params.page, 1)
|
|
assert.equal(params.groupId, null)
|
|
assert.equal(params.shopName, undefined)
|
|
})
|
|
|
|
test('test_task_089_shop_manage_filter_page_boundary_single_item', () => {
|
|
// 边界单元素:仅分组筛选激活并保留。
|
|
const filter = shopManageFilterFromInput({ groupId: '9', shopName: '' })
|
|
assert.equal(shopManageFilterActive(filter), true)
|
|
assert.equal(toShopManageListParams(1, 15, filter).groupId, 9)
|
|
})
|
|
|
|
test('test_task_089_shop_manage_filter_page_boundary_limit_or_missing_field', () => {
|
|
// 边界上限/缺字段:非法分组文本回 null;页码/页大小钳制。
|
|
assert.equal(shopManageFilterFromInput({ groupId: 'abc' }).groupId, null)
|
|
const params = toShopManageListParams(0, 999, createShopManageFilter())
|
|
assert.equal(params.page, 1)
|
|
assert.equal(params.pageSize, 100)
|
|
const info = shopManagePageInfo(2, 15, 30)
|
|
assert.equal(info.totalPages, 2)
|
|
assert.equal(info.from, 16)
|
|
assert.equal(info.hasNext, false)
|
|
})
|
|
|
|
test('test_task_089_shop_manage_filter_page_invalid_input_rejected', () => {
|
|
// 异常输入:负数/0 分组忽略;全空白店铺名视为无筛选。
|
|
assert.equal(shopManageFilterFromInput({ groupId: '0' }).groupId, null)
|
|
assert.equal(shopManageFilterFromInput({ groupId: '-2' }).groupId, null)
|
|
const filter = shopManageFilterFromInput({ groupId: null, shopName: ' ' })
|
|
assert.equal(shopManageFilterActive(filter), false)
|
|
})
|
|
|
|
test('test_task_089_shop_manage_filter_page_dependency_failure_returns_actionable_message', () => {
|
|
// 依赖失败/可操作:筛选状态纯逻辑,无框架/http;复用 DTO 归一与查询序列化。
|
|
const mod = readSource('src/pages/shop/shop-manage-list-state.ts')
|
|
assert.equal(/axios|http\.|vue/.test(mod), false, '筛选状态保持纯逻辑')
|
|
assert.match(mod, /normalizeShopListParams/)
|
|
assert.match(mod, /toShopManagePageQuery/)
|
|
})
|