未验证 提交 22668ee8 编写于 作者: T Tim Lai 提交者: GitHub

fix(OAS3): servers component update on definition change (#6280)

* fix(OAS3): servers component should use nextProps

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

* test(OAS3): multiple server test with definition change
上级 abcc3837
......@@ -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)
......
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
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
/**
* @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")
})
})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册