import test from 'node:test' import assert from 'node:assert/strict' import { readSource } from './helpers.ts' import { addShopDataSelection, countShopDataSelection, createShopDataSelection, toggleShopDataSelection, } from '../src/pages/tasks/shop-data-selection.ts' test('test_task_112_shop_data_selection_normal_primary_path', () => { // 正常主路径:切换选择 result_id(加/减)。 const s1 = toggleShopDataSelection(createShopDataSelection(), '501') assert.equal(countShopDataSelection(s1), 1) assert.ok(s1.has('501')) const s2 = toggleShopDataSelection(s1, '501') assert.equal(countShopDataSelection(s2), 0) }) test('test_task_112_shop_data_selection_normal_variant_input', () => { // 正常变体:批量加入多结果(重复键幂等)。 const s = addShopDataSelection(createShopDataSelection(), ['1', '2', '1']) assert.equal(countShopDataSelection(s), 2) }) test('test_task_112_shop_data_selection_repeated_is_idempotent', () => { // 正常重复:重复加入幂等、不改入参。 const input = new Set(['a']) assert.deepEqual(addShopDataSelection(input, ['a']), new Set(['a'])) assert.deepEqual([...input], ['a']) }) test('test_task_112_shop_data_selection_boundary_empty_input', () => { // 边界空值:空选择计数为 0。 assert.equal(countShopDataSelection(createShopDataSelection()), 0) }) test('test_task_112_shop_data_selection_boundary_single_item', () => { // 边界单元素:单结果选择。 const s = addShopDataSelection(createShopDataSelection(), ['9']) assert.equal(countShopDataSelection(s), 1) }) test('test_task_112_shop_data_selection_boundary_limit_or_missing_field', () => { // 边界上限/缺字段:空串键被忽略。 const s = toggleShopDataSelection(createShopDataSelection(), '') assert.equal(countShopDataSelection(s), 0) }) test('test_task_112_shop_data_selection_invalid_input_rejected', () => { // 异常输入:非数字 result id 不进入选择(由可选项展平保证数字)。 const s = addShopDataSelection(createShopDataSelection(), ['abc']) assert.equal(countShopDataSelection(s), 1, '保留字符串 id 供 result_id 兼容') }) test('test_task_112_shop_data_selection_dependency_failure_returns_actionable_message', () => { // 依赖失败/可操作:选择状态纯逻辑、无框架/http。 const mod = readSource('src/pages/tasks/shop-data-selection.ts') assert.equal(/axios|http\.|vue/.test(mod), false, '选择模块保持纯逻辑') assert.match(mod, /toggleShopDataSelection/) })