Files
BoosAPI/desktop/libs/markstream-vue/test/vue2-list-item-override.test.ts
T
boos e0a5f57793 feat(desktop): embed BoosAPI Desktop client as a subproject
Vendor the rebranded BoosAPI Desktop client (Tauri + Vue) into metapi as
a monorepo subdirectory under desktop/. Source only — node_modules,
dist, Cargo target and the upstream .git history are excluded.

desktop/ keeps its own independent Cargo workspace (desktop/src-tauri
with crates/*); it is not part of the backend boosapi crate, so a
`cargo check` at the metapi root still compiles only the backend. Build
the desktop app from desktop/src-tauri per desktop/README.md.

Note: app icons are still placeholder assets pending the final BoosAPI
logo. The updater signing keys live outside the repo and are not
included.
2026-06-22 11:32:57 +08:00

67 lines
2.2 KiB
TypeScript

/**
* @vitest-environment jsdom
*/
import { mount } from '@vue/test-utils'
import { describe, expect, it, vi } from 'vitest'
import { defineComponent, h } from 'vue'
import ListNode from '../packages/markstream-vue2/src/components/ListNode/ListNode.vue'
import { removeCustomComponents, setCustomComponents } from '../packages/markstream-vue2/src/utils/nodeComponents'
vi.mock('../packages/markstream-vue2/src/components/ListItemNode', () => {
return {
default: defineComponent({
name: 'MockListItemNode',
props: ['node', 'value'],
setup(props) {
return () => h('li', { 'class': 'mock-list-item', 'data-value': props.value }, (props as any).node?.children?.[0]?.content ?? '')
},
}),
}
})
describe('vue 2 - customComponents can override list_item', () => {
it('renders list items with the custom component', () => {
const scopeId = 'vue2-custom-list-item'
const CustomListItem = defineComponent({
name: 'CustomListItem',
props: ['node', 'value'],
setup(props) {
return () => h('li', { 'class': 'custom-list-item', 'data-value': props.value }, (props as any).node?.children?.[0]?.content ?? '')
},
})
setCustomComponents(scopeId, { list_item: CustomListItem as any })
try {
const wrapper = mount(ListNode, {
props: {
node: {
type: 'list',
ordered: true,
start: 1,
items: [
{ type: 'list_item', raw: '', children: [{ type: 'text', raw: '', content: 'First' }] },
{ type: 'list_item', raw: '', children: [{ type: 'text', raw: '', content: 'Second' }] },
],
raw: '',
},
customId: scopeId,
indexKey: 'list',
typewriter: false,
},
})
expect(wrapper.findAll('li.custom-list-item')).toHaveLength(2)
expect(wrapper.findAll('li.custom-list-item')[0].attributes('data-value')).toBe('1')
expect(wrapper.findAll('li.custom-list-item')[1].attributes('data-value')).toBe('2')
expect(wrapper.text()).toContain('First')
expect(wrapper.text()).toContain('Second')
expect(wrapper.findAll('li.mock-list-item')).toHaveLength(0)
}
finally {
removeCustomComponents(scopeId)
}
})
})