From 5be2789e91512c2b3c6caab110b1ae647d00ec65 Mon Sep 17 00:00:00 2001 From: Martin Vanbrabant Date: Wed, 16 Oct 2024 15:00:14 +0200 Subject: [PATCH] Corrected the link created from a custom query's SHARE QUERY button for the case where the base URL includes a path --- CHANGELOG.md | 1 + main/package.json | 2 +- .../components/CustomQueryEditor/customQueryEditButton.jsx | 5 +---- test/cypress.config.js | 2 +- test/cypress/e2e/custom-query-editor.cy.js | 4 ++-- test/cypress/e2e/fetch-status.cy.js | 2 +- test/cypress/e2e/log-in.cy.js | 4 ++-- test/cypress/e2e/save-custom-queries-on-pod.cy.js | 2 +- test/cypress/e2e/sources-from-indexfile.cy.js | 2 +- test/cypress/e2e/sources-info.cy.js | 2 +- 10 files changed, 12 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73b19fc4..849feddf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Templated queries now also work for queries containing multiple occurrences of a template variable (#164). - Works when served from any base URL including a path (e.g. `https://www.example.com/your/preferred/path`) (#165). +- Corrected the link created from a custom query's SHARE QUERY button for the case where the base URL includes a path (#169). ## [1.4.0] - 2024-10-02 diff --git a/main/package.json b/main/package.json index b536e1c5..beca4cec 100644 --- a/main/package.json +++ b/main/package.json @@ -11,7 +11,7 @@ "lint:markdown": "markdownlint-cli2", "lint:markdown:fix": "markdownlint-cli2-fix", "preview": "vite preview", - "dev-with-path": "vite --base /random/path" + "dev-with-path": "vite --base /random/path/" }, "dependencies": { "@comunica/query-sparql": "^3.2.3", diff --git a/main/src/components/CustomQueryEditor/customQueryEditButton.jsx b/main/src/components/CustomQueryEditor/customQueryEditButton.jsx index 1a519fa0..f2e192b2 100644 --- a/main/src/components/CustomQueryEditor/customQueryEditButton.jsx +++ b/main/src/components/CustomQueryEditor/customQueryEditButton.jsx @@ -36,10 +36,7 @@ export default function CustomQueryEditButton({ queryID, submitted = false }) { const handleSave = () => { - const url = new URL(window.location.href); - const serverURL = `${url.protocol}//${url.hostname}${url.port ? ':' + url.port : ''}`; - - const savedUrl = `${serverURL}/#/customQuery?${customQuery.searchParams.toString()}`; + const savedUrl = `${window.location.href.split('/#/')[0]}/#/customQuery?${customQuery.searchParams.toString()}`; setCopyUrl(savedUrl); } diff --git a/test/cypress.config.js b/test/cypress.config.js index 698d3cc9..a5c70189 100644 --- a/test/cypress.config.js +++ b/test/cypress.config.js @@ -5,7 +5,7 @@ export default defineConfig({ experimentalStudio: true, experimentalRunAllSpecs: true, defaultCommandTimeout: 10000, /* is OK for very slow computers */ - baseUrl: 'http://localhost:5173/random/path', + baseUrl: 'http://localhost:5173/random/path/', /* include trailing slash */ video: false }, }); diff --git a/test/cypress/e2e/custom-query-editor.cy.js b/test/cypress/e2e/custom-query-editor.cy.js index 87e52fba..d3f8e7a5 100644 --- a/test/cypress/e2e/custom-query-editor.cy.js +++ b/test/cypress/e2e/custom-query-editor.cy.js @@ -138,7 +138,7 @@ SELECT * WHERE { }) - it("Saves the correct URL", () => { + it("Shares the correct URL", () => { cy.visit("/#/customQuery"); @@ -163,7 +163,7 @@ SELECT * WHERE { cy.get('button').contains("Share Query").click(); cy.get('textarea[name="queryURL"]').invoke('val').then((val) => { - expect(val).to.include('?name=new+query&description=new+description&queryString=PREFIX+schema%3A+%3Chttp%3A%2F%2Fschema.org%2F%3E+%0ASELECT+*+WHERE+%7B%0A++++%3Flist+schema%3Aname+%3FlistTitle%3B%0A++++++schema%3AitemListElement+%5B%0A++++++schema%3Aname+%3FbookTitle%3B%0A++++++schema%3Acreator+%5B%0A++++++++schema%3Aname+%3FauthorName%0A++++++%5D%0A++++%5D.%0A%7D&source=http%3A%2F%2Flocalhost%3A8080%2Fexample%2Fwish-list'); + expect(val).to.equal(Cypress.config('baseUrl') + '#/customQuery?name=new+query&description=new+description&queryString=PREFIX+schema%3A+%3Chttp%3A%2F%2Fschema.org%2F%3E+%0ASELECT+*+WHERE+%7B%0A++++%3Flist+schema%3Aname+%3FlistTitle%3B%0A++++++schema%3AitemListElement+%5B%0A++++++schema%3Aname+%3FbookTitle%3B%0A++++++schema%3Acreator+%5B%0A++++++++schema%3Aname+%3FauthorName%0A++++++%5D%0A++++%5D.%0A%7D&source=http%3A%2F%2Flocalhost%3A8080%2Fexample%2Fwish-list'); }); diff --git a/test/cypress/e2e/fetch-status.cy.js b/test/cypress/e2e/fetch-status.cy.js index 5546067e..1970fb68 100644 --- a/test/cypress/e2e/fetch-status.cy.js +++ b/test/cypress/e2e/fetch-status.cy.js @@ -49,7 +49,7 @@ describe("Fetch Status", () => { cy.contains("button", "Authorize").click(); }); - cy.url().should("eq", Cypress.config('baseUrl') + "/"); + cy.url().should("eq", Cypress.config('baseUrl')); // Go to the mixed book query cy.contains("For testing only").click(); diff --git a/test/cypress/e2e/log-in.cy.js b/test/cypress/e2e/log-in.cy.js index e1897c26..8671fba9 100644 --- a/test/cypress/e2e/log-in.cy.js +++ b/test/cypress/e2e/log-in.cy.js @@ -48,7 +48,7 @@ describe("Log in", () => { cy.contains("button", "Authorize").click(); }); - cy.url().should("eq", Cypress.config('baseUrl') + "/"); + cy.url().should("eq", Cypress.config('baseUrl')); }); it("Log in with an invalid IDP issuer", () => { @@ -83,7 +83,7 @@ describe("Log in", () => { cy.contains("button", "Authorize").click(); }); - cy.url().should("eq", Cypress.config('baseUrl') + "/"); + cy.url().should("eq", Cypress.config('baseUrl')); cy.contains("General examples").click(); cy.contains("A secret list of my favorite books").click(); diff --git a/test/cypress/e2e/save-custom-queries-on-pod.cy.js b/test/cypress/e2e/save-custom-queries-on-pod.cy.js index cfe72cdd..25f80cd4 100644 --- a/test/cypress/e2e/save-custom-queries-on-pod.cy.js +++ b/test/cypress/e2e/save-custom-queries-on-pod.cy.js @@ -31,7 +31,7 @@ describe("Saving custom queries on pods - logged in", () => { cy.contains("button", "Authorize").click(); }); - cy.url().should("eq", Cypress.config('baseUrl') + "/"); + cy.url().should("eq", Cypress.config('baseUrl')); cy.visit("/#"); }); diff --git a/test/cypress/e2e/sources-from-indexfile.cy.js b/test/cypress/e2e/sources-from-indexfile.cy.js index 1e299606..05ee03dc 100644 --- a/test/cypress/e2e/sources-from-indexfile.cy.js +++ b/test/cypress/e2e/sources-from-indexfile.cy.js @@ -95,7 +95,7 @@ describe("Sources from index file", () => { cy.contains("button", "Authorize").click(); }); - cy.url().should("eq", Cypress.config('baseUrl') + "/"); + cy.url().should("eq", Cypress.config('baseUrl')); //now try again cy.contains("For testing only").click(); diff --git a/test/cypress/e2e/sources-info.cy.js b/test/cypress/e2e/sources-info.cy.js index e689c08c..ec1caf85 100644 --- a/test/cypress/e2e/sources-info.cy.js +++ b/test/cypress/e2e/sources-info.cy.js @@ -63,7 +63,7 @@ describe("Sources info", () => { cy.contains("button", "Authorize").click(); }); - cy.url().should("eq", Cypress.config('baseUrl') + "/"); + cy.url().should("eq", Cypress.config('baseUrl')); cy.contains("General examples").click(); cy.contains("A secret list of my favorite books").click();