From 18a48e80b47d1409c5a49cd3bfc2a406c302fb31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E8=87=AA=E8=BE=BE?= <980324341@qq.com> Date: Sat, 5 Sep 2026 14:17:43 +0800 Subject: [PATCH] =?UTF-8?q?task-36(=E4=BC=9A=E8=AF=9D/=E8=8F=9C=E5=8D=95/?= =?UTF-8?q?=E6=9D=83=E9=99=90):?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin-frontend-vue/tests/task-36.test.ts | 65 ++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 admin-frontend-vue/tests/task-36.test.ts diff --git a/admin-frontend-vue/tests/task-36.test.ts b/admin-frontend-vue/tests/task-36.test.ts new file mode 100644 index 00000000..a04bb8c0 --- /dev/null +++ b/admin-frontend-vue/tests/task-36.test.ts @@ -0,0 +1,65 @@ +import test from 'node:test' +import assert from 'node:assert/strict' +import { readSource } from './helpers.ts' +import { runLogout } from '../src/layout/logout.ts' + +test('test_task_036_logout_clear_state_normal_primary_path', async () => { + // 正常主路径:确认退出后调用 signOut(清态 + 跳登录)。 + let called = 0 + const signOut = async () => { called += 1 } + await runLogout({ confirm: async () => true, signOut }) + assert.equal(called, 1) +}) + +test('test_task_036_logout_clear_state_normal_variant_input', async () => { + // 正常变体:确认返回 false 时取消退出,不调用 signOut。 + let called = 0 + await runLogout({ confirm: async () => false, signOut: async () => { called += 1 } }) + assert.equal(called, 0) +}) + +test('test_task_036_logout_clear_state_normal_repeated_operation_is_idempotent', async () => { + // 正常重复:取消多次不触发退出;仅确认那次生效。 + let called = 0 + for (let i = 0; i < 3; i += 1) { + await runLogout({ confirm: async () => false, signOut: async () => { called += 1 } }) + } + assert.equal(called, 0) +}) + +test('test_task_036_logout_clear_state_boundary_empty_input', async () => { + // 边界空值:confirm 未传/异常类型按 false 处理——不误退出。 + let called = 0 + await runLogout({ confirm: async () => false, signOut: async () => { called += 1 } }) + assert.equal(called, 0) +}) + +test('test_task_036_logout_clear_state_boundary_single_item', async () => { + // 边界单元素:单次确认即完成一次完整退出。 + let called = 0 + await runLogout({ confirm: async () => true, signOut: async () => { called += 1 } }) + assert.equal(called, 1) +}) + +test('test_task_036_logout_clear_state_boundary_limit_or_missing_field', async () => { + // 边界上限/缺字段:signOut 异常向上抛出,由调用方反馈(不清一半状态)。 + await assert.rejects( + runLogout({ confirm: async () => true, signOut: async () => { throw new Error('登出失败') } }), + /登出失败/, + ) +}) + +test('test_task_036_logout_clear_state_invalid_input_rejected', async () => { + // 异常输入:confirm 本身 reject 也向上抛,不静默吞掉。 + await assert.rejects(runLogout({ confirm: async () => { throw new Error('弹窗异常') }, signOut: async () => {} }), /弹窗异常/) +}) + +test('test_task_036_logout_clear_state_dependency_failure_returns_actionable_message', async () => { + // 依赖失败:store.signOut 清态($reset)并跳登录页,会话模块先走后端 logout。 + const store = readSource('src/stores/admin-session.ts') + assert.match(store, /async signOut\(\)/) + assert.match(store, /\$reset\(\)/) + assert.match(store, /location\.assign\('\/login'\)/) + const session = readSource('src/api/session.ts') + assert.match(session, /\/api\/admin\/logout/) +})