Skip to content

Commit

Permalink
fix(OAS3): servers component update on definition change (#6280)
Browse files Browse the repository at this point in the history
* fix(OAS3): servers component should use nextProps

* test(OAS3): cypress tests for selecting multiple servers

* test(OAS3): multiple server test with definition change
  • Loading branch information
tim-lai committed Jul 31, 2020
1 parent abcc383 commit 22668ee
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core/plugins/oas3/components/servers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export default class Servers extends React.Component {
servers,
setServerVariableValue,
getServerVariable
} = this.props
} = nextProps

if(this.props.currentServer !== nextProps.currentServer) {
if (this.props.currentServer !== nextProps.currentServer || this.props.servers !== nextProps.servers) {
// Server has changed, we may need to set default values
let currentServerDefinition = servers
.find(v => v.get("url") === nextProps.currentServer)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
openapi: 3.0.2
servers:
- url: /test-url-switch-1
- url: /test-url-switch-2
info:
title: multi-server test, switch
version: 0.0.1
description: |-
a simple test to select different servers
paths:
/:
get:
summary: an operation
responses:
"200":
description: OK
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
openapi: 3.0.2
servers:
- url: /test-url-1
- url: /test-url-2
info:
title: multi-server test
version: 0.0.1
description: |-
a simple test to select different servers
paths:
/:
get:
summary: an operation
responses:
"200":
description: OK
82 changes: 82 additions & 0 deletions test/e2e-cypress/tests/features/oas3-multiple-servers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* @prettier
*/

describe("OpenAPI 3.0 Multiple Servers", () => {
it("should render and execute for server '/test-url-1'", () => {
cy.visit(
"/?url=/documents/features/oas3-multiple-servers.yaml"
)
.get(".scheme-container .schemes .servers label > select")
.select("/test-url-1")
.get("#operations-default-get_")
.click()
// Expand Try It Out
.get(".try-out__btn")
.click()
// Execute
.get(".execute.opblock-control__btn")
.click()
.get(".responses-wrapper .request-url")
.should("contains.text", "/test-url-1")
})
it("should render and execute for server '/test-url-2'", () => {
cy.visit(
"/?url=/documents/features/oas3-multiple-servers.yaml"
)
.get(".scheme-container .schemes .servers label > select")
.select("/test-url-2")
.get("#operations-default-get_")
.click()
// Expand Try It Out
.get(".try-out__btn")
.click()
// Execute
.get(".execute.opblock-control__btn")
.click()
.get(".responses-wrapper .request-url")
.should("contains.text", "/test-url-2")
})
it("should render and execute for server '/test-url-1' after sequence: select '/test-url-2' -> Try-It-Out -> select '/test-url-1'", () => {
cy.visit(
"/?url=/documents/features/oas3-multiple-servers.yaml"
)
.get(".scheme-container .schemes .servers label > select")
.select("/test-url-2")
.get("#operations-default-get_")
.click()
// Expand Try It Out
.get(".try-out__btn")
.click()
// Select a different server
.get(".scheme-container .schemes .servers label > select")
.select("/test-url-1")
// Execute
.get(".execute.opblock-control__btn")
.click()
.get(".responses-wrapper .request-url")
.should("contains.text", "/test-url-1")
})
it("should render and execute for server '/test-url-switch-1' after changing api defintion", () => {
cy.visit(
"/?url=/documents/features/oas3-multiple-servers.yaml"
)
.get(".scheme-container .schemes .servers label > select")
.select("/test-url-2")
cy.visit(
"/?url=/documents/features/oas3-multiple-servers-switch.yaml"
)
.get(".scheme-container .schemes .servers label > select")
.select("/test-url-switch-2")
.get("#operations-default-get_")
.click()
// Expand Try It Out
.get(".try-out__btn")
.click()
// Execute
.get(".execute.opblock-control__btn")
.click()
.get(".responses-wrapper .request-url")
.should("contains.text", "/test-url-switch-2")
})
})

0 comments on commit 22668ee

Please sign in to comment.