-
Notifications
You must be signed in to change notification settings - Fork 132
Expand file tree
/
Copy pathLinks.spec.js
More file actions
269 lines (223 loc) Β· 6.92 KB
/
Copy pathLinks.spec.js
File metadata and controls
269 lines (223 loc) Β· 6.92 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/**
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { randUser } from '../utils/index.js'
const user = randUser()
const fileName = 'empty.md'
describe('test link marks', function() {
before(function() {
cy.createUser(user)
})
beforeEach(function() {
cy.login(user)
cy.isolateTest({
sourceFile: fileName,
onBeforeLoad(win) {
cy.stub(win, 'open')
.as('winOpen')
},
})
cy.openFile(fileName, { force: true })
})
describe('link bubble', function() {
/**
* Find link and click on it
*
* @param {string} link The link URL
* @param {object|null} options the click options
*/
const clickLink = (link, options = {}) => {
cy.getContent()
.find(`a[href*="${link}"]`)
.click(options)
}
it('shows a link preview in the bubble after clicking link', () => {
const link = 'https://nextcloud.com/'
cy.insertLine(link)
clickLink(link)
cy.get('.link-view-bubble .widget-default', { timeout: 10000 })
.find('.widget-default--name')
.contains('Nextcloud')
.click({ force: true })
})
it('shows a link preview in the bubble after browsing to link', () => {
const link = 'https://nextcloud.com/'
cy.insertLine(link)
cy.getContent()
.find(`a[href*="${link}"]`)
cy.getContent()
.type('{upArrow}')
cy.get('.link-view-bubble .widget-default', { timeout: 10000 })
.find('.widget-default--name')
.contains('Nextcloud')
})
it('closes the link bubble when clicking elsewhere', () => {
const link = 'https://nextcloud.com/'
cy.insertLine(link)
clickLink(link)
cy.get('.link-view-bubble .widget-default', { timeout: 10000 })
.find('.widget-default--name')
.contains('Nextcloud')
cy.get('[role="dialog"] h2.modal-header__name')
.contains(fileName)
.click()
cy.get('.link-view-bubble .widget-default')
.should('not.exist')
})
it('allows to edit a link in the bubble', () => {
cy.insertLine('https://example.org')
clickLink('https://example.org')
cy.get('.link-view-bubble button[title="Edit link"]')
.click()
cy.get('.link-view-bubble input')
.type('{selectAll}https://nextcloud.com')
cy.get('.link-view-bubble button[title="Save changes"]')
.click()
cy.getContent()
.find('a[href*="https://nextcloud.com"]')
})
it('allows to remove a link in the bubble', () => {
const link = 'https://nextcloud.com'
cy.insertLine(link)
clickLink(link)
cy.get('.link-view-bubble button[title="Remove link"]')
.click()
cy.getContent()
.find(`a[href*="${link}"]`)
.should('not.exist')
})
it('Ctrl-click on a link opens a new tab', () => {
const link = 'https://nextcloud.com/'
cy.insertLine(link)
clickLink(link, { ctrlKey: true })
cy.get('@winOpen')
.should('have.been.calledOnce')
.should('have.been.calledWith', link)
})
it('Handles typed in markdown links with text', () => {
const link = 'https://nextcloud.com/'
cy.insertLine(`[text](${link})`)
clickLink(link)
cy.get('.link-view-bubble .widget-default', { timeout: 10000 })
.find('.widget-default--name')
.contains('Nextcloud')
cy.get('.link-view-bubble a')
.should('have.attr', 'href', link)
})
it('Leaves out link to other protocols', () => {
const link = 'other://protocol'
cy.insertLine(`[text](${link})`)
cy.getContent()
.find(`a[href*="${link}"]`)
.should('not.exist')
clickLink('#')
cy.get('.link-view-bubble__title', { timeout: 10000 })
.contains('other://protocol')
cy.get('.link-view-bubble a')
.should('not.exist')
})
})
describe('autolink', function() {
it('with protocol to files app and fileId', () => {
cy.getFile(fileName)
.then($el => {
const id = $el.data('cyFilesListRowFileid')
const link = `${Cypress.env('baseUrl')}/apps/files/?dir=/&openfile=${id}#relPath=/${fileName}`
cy.clearContent()
cy.insertLine(link)
cy.getContent()
.find(`a[href*="${Cypress.env('baseUrl')}"]`)
})
})
it('without protocol', () => {
cy.clearContent()
cy.insertLine('google.com')
cy.getContent()
.find('a[href*="google.com"]')
.should('not.exist')
})
it('with protocol but without space', () => {
cy.getContent().type('https://nextcloud.com')
cy.getContent()
.find('a[href*="nextcloud.com"]')
.should('not.exist')
})
})
describe('link menu', function() {
beforeEach(() => cy.clearContent())
const text = 'some text'
describe('link to website', function() {
const url = 'https://nextcloud.com/'
// Helper to reduce duplicated code, checking inserting with and without selected text
const checkLinkWebsite = (url, text) => {
cy.getSubmenuEntry('insert-link', 'insert-link-website').click()
cy.getActionSubEntry('insert-link-input').find('input[type="text"]').type(`${url}{enter}`)
cy.getContent()
.find(`a[href*="${url}"]`)
.should('have.text', text) // ensure correct text used
.click({ force: true })
}
beforeEach(cy.clearContent)
it('Link website without selection', () => {
cy.getFile(fileName)
.then($el => {
checkLinkWebsite(url, url)
})
})
it('Link website with selection', () => {
cy.getFile(fileName)
.then($el => {
cy.getContent().type(`${text}{selectAll}`)
checkLinkWebsite(url, text)
})
})
})
describe('link to local file', function() {
// Helper to reduce duplicated code, checking inserting with and without selected text
const checkLinkFile = (filename, text, isFolder = false) => {
cy.getSubmenuEntry('insert-link', 'insert-link-file').click()
cy.get('.file-picker').within(() => {
cy.get(`[data-testid="file-list-row"][data-filename="${filename}"]`).click()
cy.get(isFolder ? '.empty-content__name' : '.file-picker__files')
cy.contains('button', isFolder ? 'Choose' : `Choose ${filename}`).click()
})
return cy.getContent()
.find(`a[href*="/index.php/f/${fileId}"]`)
.should('have.text', text === undefined ? filename : text)
}
let fileId = null
beforeEach(() => cy.clearContent())
it('without text', () => {
cy.getFileId(fileName).then((id) => {
fileId = id
})
cy.getFile(fileName)
.then($el => {
checkLinkFile(fileName)
cy.get('.modal-header__name').should('include.text', fileName)
})
})
it('with selected text', () => {
cy.getFileId(fileName).then((id) => {
fileId = id
})
cy.getFile(fileName)
.then($el => {
cy.getContent().type(`${text}{selectAll}`)
checkLinkFile(fileName, text)
cy.get('.modal-header__name').should('include.text', fileName)
})
})
it('link to directory', () => {
cy.createFolder(`${window.__currentDirectory}/dummy folder`).then((folderId) => {
fileId = folderId
})
cy.getFile(fileName).then($el => {
cy.getContent().type(`${text}{selectAll}`)
checkLinkFile('dummy folder', text, true)
})
})
})
})
})