返回 slidev
drag.test.ts
根目录 / packages / slidev / node / syntax / drag.test.ts
1 import MagicString from 'magic-string-stack'
2 import MarkdownExit from 'markdown-exit'
3 import { expect, it } from 'vitest'
4 import MarkdownItVDrag from './drag'
5
6 it('v-drag component', async () => {
7 const md = MarkdownExit({ html: true })
8 const map = new Map<string, MagicString>()
9 md.use(MarkdownItVDrag, map)
10
11 const result = await md.renderAsync('<v-drag>Content</v-drag>', { id: 'test' })
12
13 expect(result).toMatchInlineSnapshot(`
14 "<p><v-drag :markdownSource="[0,1,0]">Content</v-drag></p>
15 "
16 `)
17 })
18
19 it('v-drag directive', async () => {
20 const md = MarkdownExit({ html: true })
21 const map = new Map<string, MagicString>()
22 md.use(MarkdownItVDrag, map)
23
24 const result = await md.renderAsync('<div v-drag>Content</div>', { id: 'test' })
25
26 expect(result).toMatchInlineSnapshot(`"<div v-drag :markdownSource="[0,1,5]">Content</div>"`)
27 })
28
29 it('keeps the v-drag source range when the block ends the slide', async () => {
30 const md = MarkdownExit({ html: true })
31 const map = new Map<string, MagicString>()
32 md.use(MarkdownItVDrag, map)
33
34 // No trailing newline: the exclusive end line of the last block is past the
35 // last line the transform source map covers.
36 const source = [
37 '# Test',
38 '',
39 '<div',
40 ' v-drag="[284, 248, 166, NaN]"',
41 '>',
42 ' V-drag element',
43 '</div>',
44 ].join('\n')
45 const id = '/slides.md'
46 map.set(id, new MagicString(source))
47
48 const result = await md.renderAsync(source, { id })
49
50 // [start, end, index]: end is exclusive and must include the closing tag,
51 // not collapse to the line after `<div`.
52 expect(result).toContain('v-drag="[284, 248, 166, NaN]" :markdownSource="[2,7,7]"')
53 })
54
54 lines TYPESCRIPT