import test from 'node:test' import assert from 'node:assert/strict' import { readSource } from './helpers.ts' import { allCardsSelected, clearVideoSelection, countVideoSelection, partialCardsSelected, videoSelectionAdd, videoSelectionRemove, videoSelectionToggle, } from '../src/pages/tasks/image-video-selection.ts' test('test_task_105_video_selection_normal_primary_path', () => { // 正常主路径:切换单卡选择(加/减)结果正确。 const s1 = videoSelectionToggle(new Set(), '11:0') assert.equal(countVideoSelection(s1), 1) assert.ok(s1.has('11:0')) const s2 = videoSelectionToggle(s1, '11:0') assert.equal(countVideoSelection(s2), 0, '再次切换取消选择') }) test('test_task_105_video_selection_normal_variant_input', () => { // 正常变体:批量添加多卡。 const s = videoSelectionAdd(new Set(), ['11:0', '12:1', '11:0']) assert.equal(countVideoSelection(s), 2, '重复键不重复计数') assert.ok(s.has('12:1')) }) test('test_task_105_video_selection_repeated_is_idempotent', () => { // 正常重复:同一键重复添加幂等;操作不污染入参。 const input = new Set(['a']) assert.deepEqual(videoSelectionAdd(input, ['a']), new Set(['a'])) assert.deepEqual([...input], ['a']) }) test('test_task_105_video_selection_boundary_empty_input', () => { // 边界空值:空选择计数为 0,全不选。 assert.equal(countVideoSelection(new Set()), 0) assert.equal(allCardsSelected(new Set(), ['a', 'b']), false) }) test('test_task_105_video_selection_boundary_single_item', () => { // 边界单元素:仅一卡时选中=全选。 assert.equal(allCardsSelected(new Set(['a']), ['a']), true) assert.equal(partialCardsSelected(new Set(['a']), ['a']), false) }) test('test_task_105_video_selection_boundary_limit_or_missing_field', () => { // 边界上限/缺字段:移除未选键为无操作。 const s = videoSelectionRemove(new Set(['a']), ['x']) assert.deepEqual([...s], ['a']) }) test('test_task_105_video_selection_invalid_input_rejected', () => { // 异常输入:空字符串键被忽略。 const s = videoSelectionToggle(new Set(), '') assert.equal(countVideoSelection(s), 0) assert.deepEqual([...clearVideoSelection()], []) }) test('test_task_105_video_selection_dependency_failure_returns_actionable_message', () => { // 依赖失败/可操作:选择状态纯逻辑、无框架/http。 const mod = readSource('src/pages/tasks/image-video-selection.ts') assert.equal(/axios|http\.|vue/.test(mod), false, '选择模块保持纯逻辑') assert.match(mod, /partialCardsSelected/) })