Skip to content

fix: urls.primaryName functionality regression #5097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/plugins/topbar/topbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,20 @@ export default class Topbar extends React.Component {
const urls = configs.urls || []

if(urls && urls.length) {
this.loadSpec(urls[this.state.selectedIndex].url)
var targetIndex = this.state.selectedIndex
let primaryName = configs["urls.primaryName"]
if(primaryName)
{
urls.forEach((spec, i) => {
if(spec.name === primaryName)
{
this.setState({selectedIndex: i})
targetIndex = i
}
})
}

this.loadSpec(urls[targetIndex].url)
}
}

Expand Down Expand Up @@ -116,7 +119,7 @@ export default class Topbar extends React.Component {
})

control.push(
<label className="select-label" htmlFor="select"><span>Select a spec</span>
<label className="select-label" htmlFor="select"><span>Select a definition</span>
<select id="select" disabled={isLoading} onChange={ this.onUrlSelect } value={urls[this.state.selectedIndex].url}>
{rows}
</select>
Expand Down
1 change: 1 addition & 0 deletions src/style/_topbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
width: 100%;
max-width: 600px;
margin: 0;
color: #f0f0f0;
span
{
font-size: 16px;
Expand Down
6 changes: 6 additions & 0 deletions test/e2e-cypress/static/configs/urls-primary-name.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
urls:
- name: One
url: /documents/features/urls/1.yaml
- name: Two
url: /documents/features/urls/2.yaml
urls.primaryName: Two
5 changes: 5 additions & 0 deletions test/e2e-cypress/static/configs/urls.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
urls:
- name: One
url: /documents/features/urls/1.yaml
- name: Two
url: /documents/features/urls/2.yaml
12 changes: 12 additions & 0 deletions test/e2e-cypress/static/documents/features/urls/1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
swagger: "2.0"

info:
title: One

paths:
/:
get:
summary: an operation
responses:
"200":
description: OK
12 changes: 12 additions & 0 deletions test/e2e-cypress/static/documents/features/urls/2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
openapi: "3.0.0"

info:
title: Two

paths:
/:
get:
summary: an operation
responses:
"200":
description: OK
38 changes: 38 additions & 0 deletions test/e2e-cypress/tests/features/urls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
describe("configuration options: `urls` and `urls.primaryName`", () => {
describe("`urls` only", () => {
it("should render a list of URLs correctly", () => {
cy.visit("/?configUrl=/configs/urls.yaml")
.get("select")
.children()
.should("have.length", 2)
.get("select > option")
.eq(0)
.should("have.text", "One")
.should("have.attr", "value", "/documents/features/urls/1.yaml")
.get("select > option")
.eq(1)
.should("have.text", "Two")
.should("have.attr", "value", "/documents/features/urls/2.yaml")
})

it("should render the first URL in the list", () => {
cy.visit("/?configUrl=/configs/urls.yaml")
.get("h2.title")
.should("have.text", "One")
.window()
.then(win => win.ui.specSelectors.url())
.should("equal", "/documents/features/urls/1.yaml")
})
})

it("should respect a `urls.primaryName`", () => {
cy.visit("/?configUrl=/configs/urls-primary-name.yaml")
.get("select")
.should("have.value", "/documents/features/urls/2.yaml")
.get("h2.title")
.should("have.text", "Two")
.window()
.then(win => win.ui.specSelectors.url())
.should("equal", "/documents/features/urls/2.yaml")
})
})