-
Notifications
You must be signed in to change notification settings - Fork 66.9k
Expand file tree
/
Copy pathannotations.ts
More file actions
54 lines (49 loc) · 2.44 KB
/
annotations.ts
File metadata and controls
54 lines (49 loc) · 2.44 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { describe, expect, test } from 'vitest'
import cheerio from 'cheerio'
import { getDOM } from '@/tests/helpers/e2etest'
describe('annotations', () => {
test('code-snippet-with-hashbang', async () => {
const $: cheerio.Root = await getDOM('/get-started/foo/code-snippet-with-hashbang')
const annotations = $('#article-contents .annotate')
// Check http://localhost:4000/en/get-started/foo/code-snippet-with-hashbang
// to understand the confidence in the assertions.
// This fixture page has 2 bash annotations and 1 yaml
expect(annotations.length).toBe(2 + 1)
// First code snippet block
{
const annotation = annotations.eq(0)
expect(annotation.find('.annotate-header').length).toBe(1)
expect(annotation.find('.annotate-beside').length).toBe(1)
expect(annotation.find('.annotate-inline').length).toBe(1)
expect(annotation.find('.annotate-row').length).toBe(3)
const notes = $('.annotate-row .annotate-note p', annotation)
const noteTexts = notes.map((_, el) => $(el).text()).get()
expect(noteTexts).toEqual(["Let's get started", 'This is just a sample', 'End of the script'])
}
// Second code snippet block
{
const annotation = annotations.eq(1)
expect(annotation.find('.annotate-header').length).toBe(1)
expect(annotation.find('.annotate-beside').length).toBe(1)
expect(annotation.find('.annotate-inline').length).toBe(1)
expect(annotation.find('.annotate-row').length).toBe(2)
const notes = $('.annotate-row .annotate-note p', annotation)
const noteTexts = notes.map((_, el) => $(el).text()).get()
expect(noteTexts).toEqual(['Has to start with a comment.', 'This is the if statement'])
}
// Yaml code snippet that starts with an empty comment
{
const annotation = annotations.eq(2)
expect(annotation.find('.annotate-header').length).toBe(1)
expect(annotation.find('.annotate-beside').length).toBe(1)
expect(annotation.find('.annotate-inline').length).toBe(1)
expect(annotation.find('.annotate-row').length).toBe(3)
const notes = $('.annotate-row .annotate-note p', annotation)
const noteTexts = notes.map((_, el) => $(el).text()).get()
expect(noteTexts).toEqual([
'Configures this workflow to run every time a change is pushed to the branch called release.',
"This job checks out the repository contents ...\nAnd here's the second comment line.",
])
}
})
})