|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { Parser } from '../mdeck/parser.js'; |
| 3 | +import { Slideshow } from '../mdeck/models/slideshow.js'; |
| 4 | +import { convertMarkdown } from '../mdeck/converter.js'; |
| 5 | +import type { Dom } from '../mdeck/dom.js'; |
| 6 | +import EventEmitter from 'eventemitter3'; |
| 7 | + |
| 8 | +function makeDom(): Dom { |
| 9 | + return { |
| 10 | + getHTMLElement: () => document.documentElement, |
| 11 | + getBodyElement: () => document.body as HTMLBodyElement, |
| 12 | + getElementById: () => null, |
| 13 | + getLocationHash: () => '', |
| 14 | + setLocationHash: () => {}, |
| 15 | + XMLHttpRequest: class { |
| 16 | + open() {} |
| 17 | + send() {} |
| 18 | + onload?: () => void; |
| 19 | + readyState = 0; |
| 20 | + status = 0; |
| 21 | + responseText = ''; |
| 22 | + } as unknown as typeof XMLHttpRequest, |
| 23 | + } as unknown as Dom; |
| 24 | +} |
| 25 | + |
| 26 | +describe('incremental list items', () => { |
| 27 | + const src = `# Agenda |
| 28 | +
|
| 29 | + - Testing Integrations |
| 30 | +-- |
| 31 | + - OpenAPI |
| 32 | +-- |
| 33 | + - Pact |
| 34 | +-- |
| 35 | + - Conclusions |
| 36 | +-- |
| 37 | + - Questions`; |
| 38 | + |
| 39 | + it('parses into 5 slides', () => { |
| 40 | + const parser = new Parser(); |
| 41 | + expect(parser.parse(src)).toHaveLength(5); |
| 42 | + }); |
| 43 | + |
| 44 | + it('renders each incremental slide with the correct number of list items', () => { |
| 45 | + const slideshow = new Slideshow(new EventEmitter(), makeDom(), {}); |
| 46 | + slideshow.loadFromString(src); |
| 47 | + const slides = slideshow.getSlides(); |
| 48 | + |
| 49 | + slides.forEach((slide, i) => { |
| 50 | + const html = convertMarkdown(slide.content); |
| 51 | + const liCount = (html.match(/<li>/g) || []).length; |
| 52 | + expect(liCount).toBe(i + 1); |
| 53 | + }); |
| 54 | + }); |
| 55 | +}); |
0 commit comments