-
Notifications
You must be signed in to change notification settings - Fork 132
Expand file tree
/
Copy pathsections.spec.js
More file actions
143 lines (127 loc) Β· 3.59 KB
/
Copy pathsections.spec.js
File metadata and controls
143 lines (127 loc) Β· 3.59 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import { randUser } from '../utils/index.js'
const user = randUser()
const fileName = 'empty.md'
const clickOutline = () => {
cy.getActionEntry('headings')
.click()
cy.get('.v-popper__wrapper .open').getActionEntry('outline')
.click()
}
let currentFolder
describe('Content Sections', () => {
before(function() {
cy.createUser(user)
})
beforeEach(function() {
cy.login(user)
cy.createTestFolder().then(folderName => {
currentFolder = folderName
cy.uploadFile(fileName, 'text/markdown', `${currentFolder}/${fileName}`)
})
})
describe('Heading anchors', () => {
it('Anchor exists', () => {
cy.visitTestFolder()
cy.openFile(fileName, { force: true })
cy.getContent()
.type('# Heading\nText\n## Heading 2\nText\n## Heading 2')
cy.getContent().find('a.heading-anchor')
.should(($anchor) => {
expect($anchor).to.have.length(3)
expect($anchor.eq(0)).to.have.attr('href').and.equal('#h-heading')
expect($anchor.eq(1)).to.have.attr('href').and.equal('#h-heading-2')
expect($anchor.eq(2)).to.have.attr('href').and.equal('#h-heading-2--1')
})
})
it('Anchor ID is updated', () => {
cy.visitTestFolder()
cy.openFile(fileName, { force: true })
cy.insertLine('# Heading 1')
cy.getContent()
.find('h1 > a')
.should('have.attr', 'id')
.and('equal', 'h-heading-1')
cy.getContent()
.find('a.heading-anchor')
.should('have.attr', 'href')
.and('equal', '#h-heading-1')
cy.getContent().type('{backspace}{backspace}2{enter}')
cy.getContent()
.find('h1 > a')
.should('have.attr', 'id')
.and('equal', 'h-heading-2')
cy.getContent()
.find('a.heading-anchor')
.should('have.attr', 'href')
.and('equal', '#h-heading-2')
})
it('scrolls anchor into view', () => {
cy.uploadFile('anchors.md', 'text/markdown', `${currentFolder}/anchors.md`)
cy.visitTestFolder()
cy.openFile('anchors.md')
cy.getContent()
.get('h2 > a[id="h-bottom"]')
.should('not.be.inViewport')
cy.getContent()
.find('a[href="#h-bottom"]:not(.heading-anchor)')
.click()
cy.getContent()
.get('h2 > a[id="h-bottom"]')
.should('be.inViewport')
})
it('Can change heading level', () => {
cy.visitTestFolder()
cy.openFile(fileName, { force: true })
// Issue #2868
cy.insertLine('# Heading 1')
cy.getContent()
.find('h1 > a')
.should('have.attr', 'id')
.and('equal', 'h-heading-1')
cy.getContent()
.find('h1')
.click({ force: true, position: 'center' })
cy.getActionEntry('headings').click()
cy.get('.v-popper__wrapper .open').getActionEntry('headings-h3').click()
cy.getContent().find('h3 > a')
.should('have.attr', 'id')
.and('equal', 'h-heading-1')
})
})
describe('Table of Contents', () => {
it('sidebar toc', () => {
cy.visitTestFolder()
cy.openFile(fileName, { force: true })
cy.getContent()
.type('# T1 \n## T2 \n### T3 \n#### T4 \n##### T5 \n###### T6\n')
cy.closeFile()
.then(() => cy.openFile(fileName, { force: true }))
.then(clickOutline)
cy.getOutline()
.find('header')
.should('exist')
cy.getTOC()
.find('ul li')
.should('have.length', 6)
cy.getTOC()
.find('ul li')
.each((el, index) => {
cy.wrap(el)
.should('have.attr', 'data-toc-level')
.and('equal', String(index + 1))
cy.wrap(el)
.find('a')
.should('have.attr', 'href')
.and('equal', `#h-t${index + 1}`)
})
})
it('empty toc', () => {
cy.visitTestFolder()
cy.openFile(fileName, { force: true })
.then(clickOutline)
cy.getOutline()
.find('ul')
.should('be.empty')
})
})
})