| 1 | import type { SlideRoute } from '@slidev/types' |
| 2 | import { describe, expect, it } from 'vitest' |
| 3 | import { getPrintSlideAnchorId, getSlideRoutePath } from './slidePath' |
| 4 | |
| 5 | function route(no: number, routeAlias?: string): SlideRoute { |
| 6 | return { |
| 7 | no, |
| 8 | meta: { |
| 9 | slide: { |
| 10 | frontmatter: { |
| 11 | routeAlias, |
| 12 | }, |
| 13 | }, |
| 14 | }, |
| 15 | } as unknown as SlideRoute |
| 16 | } |
| 17 | |
| 18 | describe('getSlideRoutePath', () => { |
| 19 | it('returns router paths without Vite base', () => { |
| 20 | expect(getSlideRoutePath(route(2), false)).toBe('/2') |
| 21 | expect(getSlideRoutePath(route(2), true)).toBe('/presenter/2') |
| 22 | expect(getSlideRoutePath(route(2), false, true)).toBe('/export/2') |
| 23 | }) |
| 24 | |
| 25 | it('uses route aliases', () => { |
| 26 | expect(getSlideRoutePath(route(2, 'intro'), false)).toBe('/intro') |
| 27 | expect(getSlideRoutePath(route(2, 'intro'), true)).toBe('/presenter/intro') |
| 28 | }) |
| 29 | }) |
| 30 | |
| 31 | describe('getPrintSlideAnchorId', () => { |
| 32 | it('depends on the slide number only, so it is the same however many clicks the slide has', () => { |
| 33 | expect(getPrintSlideAnchorId(2)).toBe('slide-2') |
| 34 | expect(getPrintSlideAnchorId('2')).toBe(getPrintSlideAnchorId(2)) |
| 35 | expect(getPrintSlideAnchorId(12)).not.toBe(getPrintSlideAnchorId(2)) |
| 36 | }) |
| 37 | |
| 38 | it('never equals a print container id (`NNN-NN`), which would make a link ambiguous', () => { |
| 39 | for (const no of [1, 2, 12, 123]) |
| 40 | expect(getPrintSlideAnchorId(no)).not.toMatch(/^\d{3}-\d{2}$/) |
| 41 | }) |
| 42 | }) |
| 43 |