import { test } from 'node:test' import assert from 'node:assert/strict' import { readFileSync } from 'node:fs' import { EVENT_ROW_DBLCLICK_TITLE, openEventCategories } from '../components/baseData/eventRowActions' import type { BaseDataTabKey } from '../components/baseData/tabs' // 双击小项条目 → 跳到该小项的组别列表。 // 浏览器在 dblclick 前必然先派发两次 click,这里模拟「先点过别的行、再双击目标行」, // 确认最终选中项是被双击的那一项,而不是上一次单击留下的那一项。 test('双击:最终选中被双击的那一项,并跳到 categories', () => { const calls: string[] = [] let selected: number | null = null const deps = { selectEvent: (id: number) => { selected = id calls.push(`select:${id}`) }, goTab: (tab: BaseDataTabKey) => { calls.push(`goTab:${tab}`) }, } deps.selectEvent(1) openEventCategories(7, deps) assert.equal(selected, 7) assert.deepEqual(calls.slice(-2), ['select:7', 'goTab:categories']) }) // 必须先选中再跳分区:反过来会在分区切换(可能重建列表)之后再改选中,跳过去的小项就不对。 test('双击:先选中、后跳转,顺序不能反', () => { const calls: string[] = [] openEventCategories(3, { selectEvent: (id) => calls.push(`select:${id}`), goTab: (tab) => calls.push(`goTab:${tab}`), }) assert.deepEqual(calls, ['select:3', 'goTab:categories']) }) // 模板契约:条目要绑 @dblclick,且 title 写明可发现性提示; // 行内的小按钮(编辑 / 删除)用 @dblclick.stop 挡住,双击按钮不会误跳转。 const SECTION_SOURCE = readFileSync( new URL('../components/baseData/SportsEventsSection.vue', import.meta.url), 'utf8', ) test('小项条目绑定双击跳转与 title 提示', () => { assert.match(SECTION_SOURCE, /@dblclick="openCategories\(event\.id\)"/) assert.match(SECTION_SOURCE, /:title="EVENT_ROW_DBLCLICK_TITLE"/) assert.equal(EVENT_ROW_DBLCLICK_TITLE, '双击查看该小项的组别') }) test('条目里的小按钮不会被双击误触发跳转', () => { assert.match(SECTION_SOURCE, /