Skip to content

Commit f918e10

Browse files
committedMay 11, 2023
Add Cypress test for relative links to non-markdown files
Don't run the Cypress test on stable25, Cypress seems to choke on the PDF viewer there. Signed-off-by: Jonas <jonas@freesources.org>
1 parent 565f9ab commit f918e10

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed
 

‎cypress/e2e/pages-links.spec.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626

2727
const baseUrl = Cypress.env('baseUrl')
2828
const sourceUrl = new URL(`${baseUrl}/index.php/apps/collectives/Link%20Testing/Link%20Source`)
29-
let imageId, textId
29+
let imageId, pdfId, textId
3030
let anotherCollectiveFirstPageId, linkTargetPageId
3131

32-
describe('Page', function() {
32+
describe('Page Link Handling', function() {
3333
before(function() {
3434
cy.login('bob', { route: '/apps/collectives' })
3535
cy.deleteAndSeedCollective('Another Collective')
@@ -48,12 +48,16 @@ describe('Page', function() {
4848
cy.uploadFile('test.png', 'image/png').then((id) => {
4949
imageId = id
5050
})
51+
cy.uploadFile('test.pdf', 'application/pdf', 'Collectives/Link%20Testing/').then((id) => {
52+
pdfId = id
53+
})
5154
}).then(() => {
5255
cy.seedPageContent('Link%20Testing/Link%20Source.md', `
5356
## Links supposed to open in viewer
5457
5558
* Absolute path to image in Nextcloud: [image](//test.png?fileId=${imageId})
5659
* Absolute path to text file in Nextcloud: [test.md](//test.md?fileId=${textId})
60+
* Relative path to pdf file in Nextcloud: [test.pdf](test.pdf?fileId=${pdfId})
5761
5862
## Links supposed to open in same window
5963
@@ -176,6 +180,12 @@ describe('Page', function() {
176180
edit: true,
177181
})
178182
})
183+
it('Opens link with relative path to pdf in Nextcloud in viewer', function() {
184+
let href = `/index.php/apps/files/?dir=/&openfile=${pdfId}#relPath=test.pdf`
185+
testLinkToViewer(href, { fileName: 'test.pdf', viewerFileElement: 'iframe' })
186+
href = `/index.php/apps/files/?dir=/Collectives/Link Testing&openfile=${pdfId}#relPath=test.pdf`
187+
testLinkToViewer(href, { fileName: 'test.pdf', viewerFileElement: 'iframe', edit: true })
188+
})
179189
})
180190

181191
describe('Link handling to collectives', function() {

‎cypress/fixtures/test.pdf

6.24 KB
Binary file not shown.

‎cypress/support/commands.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ Cypress.Commands.add('seedPage', (name, parentFilePath, parentFileName) => {
230230
/**
231231
* Upload a file
232232
*/
233-
Cypress.Commands.add('uploadFile', (path, mimeType) => {
233+
Cypress.Commands.add('uploadFile', (path, mimeType, remotePath = '') => {
234234
// Get fixture
235235
return cy.fixture(path, 'base64').then(file => {
236236
// convert the base64 string to a blob
@@ -240,13 +240,13 @@ Cypress.Commands.add('uploadFile', (path, mimeType) => {
240240
return cy.window()
241241
.its('app')
242242
.then(async app => {
243-
const response = await axios.put(`${Cypress.env('baseUrl')}/remote.php/webdav/${path}`, file, {
243+
const response = await axios.put(`${Cypress.env('baseUrl')}/remote.php/webdav/${remotePath}${path}`, file, {
244244
headers: {
245245
requesttoken: app.OC.requestToken,
246246
'Content-Type': mimeType,
247247
},
248248
})
249-
cy.log(`Uploaded file to ${path}`)
249+
cy.log(`Uploaded file to ${remotePath}${path}`)
250250
const ocFileId = response.headers['oc-fileid']
251251
const fileId = parseInt(ocFileId.substring(0, ocFileId.indexOf('oc')))
252252
return fileId

0 commit comments

Comments
 (0)
Please sign in to comment.