From 94c70e21cdb3a4e00bb916b91b03bc83e95d179d Mon Sep 17 00:00:00 2001 From: Chad Knight Date: Wed, 21 Sep 2022 10:24:00 -1000 Subject: [PATCH] fix(plugin): allow Topbar plugin to read url param on load (#8168) * fix(plugin): allow Topbar plugin to read url param on load * fix(plugin): add cypress tests for topbar w/o query config --- src/plugins/topbar/topbar.jsx | 3 +- .../static/pages/multiple-urls/index.html | 80 +++++++++++++++++++ .../topbar/linking-to-configured-urls.js | 23 ++++++ 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 test/e2e-cypress/static/pages/multiple-urls/index.html create mode 100644 test/e2e-cypress/tests/features/plugins/topbar/linking-to-configured-urls.js diff --git a/src/plugins/topbar/topbar.jsx b/src/plugins/topbar/topbar.jsx index 3549ece5a7c..9dc07ba451b 100644 --- a/src/plugins/topbar/topbar.jsx +++ b/src/plugins/topbar/topbar.jsx @@ -87,7 +87,8 @@ export default class Topbar extends React.Component { if(urls && urls.length) { var targetIndex = this.state.selectedIndex - let primaryName = configs["urls.primaryName"] + let search = parseSearch() + let primaryName = search["urls.primaryName"] || configs["urls.primaryName"] if(primaryName) { urls.forEach((spec, i) => { diff --git a/test/e2e-cypress/static/pages/multiple-urls/index.html b/test/e2e-cypress/static/pages/multiple-urls/index.html new file mode 100644 index 00000000000..e7d47542a49 --- /dev/null +++ b/test/e2e-cypress/static/pages/multiple-urls/index.html @@ -0,0 +1,80 @@ + + + + + + + Swagger UI + + + + + + + + +
+ + + + + + + diff --git a/test/e2e-cypress/tests/features/plugins/topbar/linking-to-configured-urls.js b/test/e2e-cypress/tests/features/plugins/topbar/linking-to-configured-urls.js new file mode 100644 index 00000000000..fc24aac044f --- /dev/null +++ b/test/e2e-cypress/tests/features/plugins/topbar/linking-to-configured-urls.js @@ -0,0 +1,23 @@ +describe("Loading specs by url.primaryName param", () => { + describe("with no param", () => { + it("should load the default spec", () => { + cy.visit("/pages/multiple-urls/index.html") + .get("span.url") + .contains("/documents/petstore-expanded.openapi.yaml") + }) + }) + describe("with an invalid param", () => { + it("should fall back to the default spec", () => { + cy.visit("/pages/multiple-urls/index.html?urls.primaryName=undefinedUrlName") + .get("span.url") + .contains("/documents/petstore-expanded.openapi.yaml") + }) + }) + describe("with a valid url.primaryName param", () => { + it("should render the requested spec", () => { + cy.visit("/pages/multiple-urls/index.html?urls.primaryName=Petstore Swagger") + .get("span.url") + .contains("/documents/petstore.swagger.yaml") + }) + }) +})