From 221a742728e5fc7e757452f85fa9ba07fd364c9b Mon Sep 17 00:00:00 2001 From: Kostiantyn Miakshyn Date: Sat, 4 Jan 2025 13:45:56 +0100 Subject: [PATCH] Slugify Collectives and Pages (try fix cypress) Signed-off-by: Kostiantyn Miakshyn --- cypress/e2e/pages-links.spec.js | 48 ++++++++++++++++----------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/cypress/e2e/pages-links.spec.js b/cypress/e2e/pages-links.spec.js index c79d855b8..93ad87065 100644 --- a/cypress/e2e/pages-links.spec.js +++ b/cypress/e2e/pages-links.spec.js @@ -5,13 +5,14 @@ const baseUrl = Cypress.env('baseUrl') let imageId, pdfId, textId, sourceUrl -let anotherCollectiveFirstPageId, linkTargetPageId +let anotherCollectiveFirstPageId, anotherCollectiveId, linkTargetPageId describe('Page link handling', function() { before(function() { cy.loginAs('bob') cy.deleteAndSeedCollective('Another Collective') - .seedPage('First Page', '', 'Readme.md').then(({ pageId }) => { + .seedPage('First Page', '', 'Readme.md').then(({ collectiveId, pageId }) => { + anotherCollectiveId = collectiveId anotherCollectiveFirstPageId = pageId }) cy.deleteAndSeedCollective('Link Testing') @@ -63,8 +64,8 @@ describe('Page link handling', function() { * Relative path to page in this collective without fileId: [Link Target](./Link%20Target) * Relative path to markdown file in this collective: [Link Target](./Link%20Target.md) -* URL to page in other collective with fileId: [Another Collective/First Page](${baseUrl}/index.php/apps/collectives/Another%20Collective/First%20Page?fileId=${anotherCollectiveFirstPageId}) -* Absolute path to page in other collective without fileId: [Another Collective/First Page](/index.php/apps/collectives/Another%20Collective/First%20Page) +* URL to page in other collective with fileId: [Another Collective/First Page](${baseUrl}/index.php/apps/collectives/Another-Collective-${anotherCollectiveId}/First%20Page?fileId=${anotherCollectiveFirstPageId}) +* Absolute path to page in other collective without fileId: [Another Collective/First Page](/index.php/apps/collectives/Another-Collective-${anotherCollectiveId}/page-${anotherCollectiveFirstPageId}-First-Page) ## Links supposed to open in new window @@ -124,9 +125,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`) : url.pathname cy.location().should((loc) => { expect(loc.pathname).to.match(new RegExp(`^${expectedPathname || pathname}$`)) @@ -268,7 +268,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}`, }) } @@ -278,7 +278,7 @@ 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 { @@ -286,7 +286,7 @@ describe('Page link handling', function() { // 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}`, }) } @@ -295,7 +295,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 { @@ -307,20 +307,20 @@ 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' }) } }) it('Opens link with URL to page in other collective with fileId in same tab', function() { - const href = `${baseUrl}/index.php/apps/collectives/Another%20Collective/First%20Page?fileId=${anotherCollectiveFirstPageId}` + const href = `${baseUrl}/index.php/apps/collectives/Another-Collective-${anotherCollectiveId}/First%20Page?fileId=${anotherCollectiveFirstPageId}` testLinkToSameTab(href) }) it('Opens link with absolute path to page in other collective without fileId in same tab', function() { - const href = '/index.php/apps/collectives/Another%20Collective/First%20Page' + const href = `/index.php/apps/collectives/Another-Collective-${anotherCollectiveId}/page-${anotherCollectiveFirstPageId}-First-Page` if (!['stable27', 'stable28'].includes(Cypress.env('ncVersion'))) { testLinkToSameTab(href, { expectedSearch: `?fileId=${anotherCollectiveFirstPageId}`, @@ -337,7 +337,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}`, }) } @@ -350,7 +350,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}`, }) } @@ -359,7 +359,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'))) { @@ -372,7 +372,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'))) { @@ -401,7 +401,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 { @@ -429,7 +429,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 { @@ -438,7 +438,7 @@ describe('Page link handling', function() { }) it('Opens link with URL to page in other collective with fileId in same tab', function() { - const href = `${baseUrl}/index.php/apps/collectives/Another%20Collective/First%20Page?fileId=${anotherCollectiveFirstPageId}` + const href = `${baseUrl}/index.php/apps/collectives/Another-Collective-${anotherCollectiveId}/First%20Page?fileId=${anotherCollectiveFirstPageId}` 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'))) { @@ -448,7 +448,7 @@ describe('Page link handling', function() { } }) it('Opens link with absolute path to page in other collective without fileId in same tab', function() { - const href = '/index.php/apps/collectives/Another%20Collective/First%20Page' + const href = `/index.php/apps/collectives/Another-Collective-${anotherCollectiveId}/page-${anotherCollectiveFirstPageId}-First-Page` 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'))) { @@ -552,13 +552,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 })