-
Notifications
You must be signed in to change notification settings - Fork 66.9k
Expand file tree
/
Copy pathminitoc.ts
More file actions
39 lines (32 loc) · 1.67 KB
/
minitoc.ts
File metadata and controls
39 lines (32 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { describe, expect, test } from 'vitest'
import cheerio from 'cheerio'
import { getDOM } from '@/tests/helpers/e2etest'
describe('minitoc', () => {
test('renders mini TOC in articles with more than one heading', async () => {
const $: cheerio.Root = await getDOM('/en/get-started/minitocs/multiple-headings')
expect($('h2#in-this-article').length).toBe(1)
expect($('h2#in-this-article + nav ul li').length).toBeGreaterThan(1)
})
test('does not render mini TOC in articles with only one heading', async () => {
const $: cheerio.Root = await getDOM('/en/get-started/minitocs/one-heading')
expect($('h2#in-this-article').length).toBe(0)
})
test('does not render mini TOC in articles with no headings', async () => {
const $: cheerio.Root = await getDOM('/en/get-started/minitocs/no-heading')
expect($('h2#in-this-article').length).toBe(0)
})
test('does not render mini TOC in non-articles', async () => {
const $: cheerio.Root = await getDOM('/en/get-started')
expect($('h2#in-this-article').length).toBe(0)
})
test('renders mini TOC with correct links when headings contain markup', async () => {
const $: cheerio.Root = await getDOM('/en/get-started/minitocs/markup-heading')
expect($('h2#in-this-article + nav ul li a[href="#on"]').length).toBe(1)
})
test("max heading doesn't exceed h2", async () => {
const $: cheerio.Root = await getDOM('/en/get-started/minitocs/multiple-headings')
expect($('h2#in-this-article').length).toBe(1)
expect($('h2#in-this-article + nav ul').length).toBeGreaterThan(0) // non-indented items
expect($('h2#in-this-article + nav ul div ul div').length).toBe(0) // indented items
})
})