Skip to content

Commit

Permalink
Slugify Collectives and Pages (try fix cypress)
Browse files Browse the repository at this point in the history
Signed-off-by: Kostiantyn Miakshyn <[email protected]>
  • Loading branch information
Koc committed Jan 4, 2025
1 parent 3f6dcdc commit 00b17ff
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions cypress/e2e/pages-links.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,8 @@ describe('Page link handling', function() {

cy.url().then((newBaseUrl) => {
const url = new URL(href, newBaseUrl)
const encodedCollectiveName = encodeURIComponent('Link Testing')
const pathname = isPublic
? url.pathname.replace(`/${encodedCollectiveName}`, `/p/\\w+/${encodedCollectiveName}`)
? url.pathname.replace(`/Link-Testing`, `/p/\\w+/Link-Testing`)

Check failure on line 128 in cypress/e2e/pages-links.spec.js

View workflow job for this annotation

GitHub Actions / NPM lint

Strings must use singlequote

Check failure on line 128 in cypress/e2e/pages-links.spec.js

View workflow job for this annotation

GitHub Actions / NPM lint

Strings must use singlequote
: url.pathname
cy.location().should((loc) => {
expect(loc.pathname).to.match(new RegExp(`^${expectedPathname || pathname}$`))
Expand Down Expand Up @@ -268,7 +267,7 @@ describe('Page link handling', function() {
// const href = `./Link%20Target?fileId=${linkTargetPageId}`
const href = `/index.php/apps/files/?dir=/&openfile=${linkTargetPageId}#relPath=./Link%20Target`
testLinkToSameTab(href, {
expectedPathname: '/index.php/apps/collectives/Link%20Testing/Link%20Target',
expectedPathname: '/index.php/apps/collectives/Link-Testing-4/page-70-Link-Target',
expectedSearch: `?fileId=${linkTargetPageId}`,
})
}
Expand All @@ -278,15 +277,15 @@ describe('Page link handling', function() {
if (!['stable27', 'stable28'].includes(Cypress.env('ncVersion'))) {
const href = `./Link%20Target%20Outdated?fileId=${linkTargetPageId}`
testLinkToSameTab(href, {
expectedPathname: '/index.php/apps/collectives/Link%20Testing/Link%20Target',
expectedPathname: '/index.php/apps/collectives/Link-Testing-4/page-70-Link-Target',
expectedSearch: `?fileId=${linkTargetPageId}`,
})
} else {
// Link without origin and containing `fileId` param gets rewritten by editor rendering
// const href = `./Link%20Target%20Outdated?fileId=${linkTargetPageId}`
const href = `/index.php/apps/files/?dir=/&openfile=${linkTargetPageId}#relPath=./Link%20Target%20Outdated`
testLinkToSameTab(href, {
expectedPathname: '/index.php/apps/collectives/Link%20Testing/Link%20Target',
expectedPathname: '/index.php/apps/collectives/Link-Testing-4/page-70-Link-Target',
expectedSearch: `?fileId=${linkTargetPageId}`,
})
}
Expand All @@ -295,7 +294,7 @@ describe('Page link handling', function() {
const href = './Link%20Target'
if (!['stable27', 'stable28'].includes(Cypress.env('ncVersion'))) {
testLinkToSameTab(href, {
expectedPathname: '/index.php/apps/collectives/Link%20Testing/Link%20Target',
expectedPathname: '/index.php/apps/collectives/Link-Testing-4/page-70-Link-Target',
expectedSearch: `?fileId=${linkTargetPageId}`,
})
} else {
Expand All @@ -307,11 +306,11 @@ describe('Page link handling', function() {
const href = './Link%20Target.md'
if (!['stable27', 'stable28'].includes(Cypress.env('ncVersion'))) {
testLinkToSameTab(href, {
expectedPathname: '/index.php/apps/collectives/Link%20Testing/Link%20Target',
expectedPathname: '/index.php/apps/collectives/Link-Testing-4/page-70-Link-Target',
expectedSearch: `?fileId=${linkTargetPageId}`,
})
} else {
testLinkToSameTab(href, { expectedPathname: '/index.php/apps/collectives/Link%20Testing/Link%20Target' })
testLinkToSameTab(href, { expectedPathname: '/index.php/apps/collectives/Link-Testing-4/page-70-Link-Target' })
}
})

Expand All @@ -337,7 +336,7 @@ describe('Page link handling', function() {
// const href = `../Link%20Target.md?fileId=${linkTargetPageId}`
const href = `/index.php/apps/files/?dir=&openfile=${linkTargetPageId}#relPath=../Link%20Target.md`
testLinkToSameTab(href, {
expectedPathname: '/index.php/apps/collectives/Link%20Testing/Link%20Target',
expectedPathname: '/index.php/apps/collectives/Link-Testing-4/page-70-Link-Target',
expectedSearch: `?fileId=${linkTargetPageId}`,
})
}
Expand All @@ -350,7 +349,7 @@ describe('Page link handling', function() {
// const href = `./Link%20Target?fileId=${linkTargetPageId}`
const href = `/index.php/apps/files/?dir=/&openfile=${linkTargetPageId}#relPath=./Link%20Target`
testLinkToSameTab(href, {
expectedPathname: '/index.php/apps/collectives/Link%20Testing/Link%20Target',
expectedPathname: '/index.php/apps/collectives/Link-Testing-4/page-70-Link-Target',
expectedSearch: `?fileId=${linkTargetPageId}`,
})
}
Expand All @@ -359,7 +358,7 @@ describe('Page link handling', function() {

describe('Link handling to collectives in edit mode', function() {
it('Opens link with URL to page in this collective in same tab', function() {
const href = `${baseUrl}/index.php/apps/collectives/Link%20Testing/Link%20Target`
const href = `${baseUrl}/index.php/apps/collectives/Link-Testing-4/page-70-Link-Target`
cy.switchToEditMode()
// Starting with Nextcloud 29, internal links will always open in same tab (also in edit mode)
if (!['stable27', 'stable28'].includes(Cypress.env('ncVersion'))) {
Expand All @@ -372,7 +371,7 @@ describe('Page link handling', function() {
}
})
it('Opens link with absolute path to page in this collective in same tab', function() {
const href = '/index.php/apps/collectives/Link%20Testing/Link%20Target'
const href = '/index.php/apps/collectives/Link-Testing-4/page-70-Link-Target'
cy.switchToEditMode()
// Starting with Nextcloud 29, internal links will always open in same tab (also in edit mode)
if (!['stable27', 'stable28'].includes(Cypress.env('ncVersion'))) {
Expand Down Expand Up @@ -401,7 +400,7 @@ describe('Page link handling', function() {
if (!['stable27', 'stable28'].includes(Cypress.env('ncVersion'))) {
testLinkToSameTab(href, {
edit: true,
expectedPathname: '/index.php/apps/collectives/Link%20Testing/Link%20Target',
expectedPathname: '/index.php/apps/collectives/Link-Testing-4/page-70-Link-Target',
expectedSearch: `?fileId=${linkTargetPageId}`,
})
} else {
Expand Down Expand Up @@ -429,7 +428,7 @@ describe('Page link handling', function() {
if (!['stable27', 'stable28'].includes(Cypress.env('ncVersion'))) {
testLinkToSameTab(href, {
edit: true,
expectedPathname: '/index.php/apps/collectives/Link%20Testing/Link%20Target',
expectedPathname: '/index.php/apps/collectives/Link-Testing-4/page-70-Link-Target',
expectedSearch: `?fileId=${linkTargetPageId}`,
})
} else {
Expand Down Expand Up @@ -552,13 +551,13 @@ describe('Page link handling', function() {
it('Public share in view mode: opens link with absolute path to page in this collective in same tab', function() {
cy.logout()
cy.visit(`${shareUrl}/Link Source`)
const href = '/index.php/apps/collectives/Link%20Testing/Link%20Target'
const href = '/index.php/apps/collectives/Link-Testing-4/page-70-Link-Target'
testLinkToSameTab(href, { isPublic: true })
})
it('Public share in edit mode: opens link with absolute path to page in this collective in same tab', function() {
cy.logout()
cy.visit(`${shareUrl}/Link Source`)
const href = '/index.php/apps/collectives/Link%20Testing/Link%20Target'
const href = '/index.php/apps/collectives/Link-Testing-4/page-70-Link-Target'
cy.switchToEditMode()
if (!['stable27', 'stable28'].includes(Cypress.env('ncVersion'))) {
testLinkToSameTab(href, { edit: true, isPublic: true })
Expand Down

0 comments on commit 00b17ff

Please sign in to comment.