diff --git a/src/core/components/model-example.jsx b/src/core/components/model-example.jsx index 3974bdd5209..f3c9836bdbb 100644 --- a/src/core/components/model-example.jsx +++ b/src/core/components/model-example.jsx @@ -1,6 +1,8 @@ import React from "react" import PropTypes from "prop-types" import ImPropTypes from "react-immutable-proptypes" +import cx from "classnames" +import randomBytes from "randombytes" export default class ModelExample extends React.Component { static propTypes = { @@ -31,11 +33,11 @@ export default class ModelExample extends React.Component { } this.state = { - activeTab: activeTab + activeTab, } } - activeTab =( e ) => { + activeTab = ( e ) => { let { target : { dataset : { name } } } = e this.setState({ @@ -58,42 +60,83 @@ export default class ModelExample extends React.Component { let { defaultModelExpandDepth } = getConfigs() const ModelWrapper = getComponent("ModelWrapper") const HighlightCode = getComponent("highlightCode") + const exampleTabId = randomBytes(5).toString("base64") + const examplePanelId = randomBytes(5).toString("base64") + const modelTabId = randomBytes(5).toString("base64") + const modelPanelId = randomBytes(5).toString("base64") let isOAS3 = specSelectors.isOAS3() - return
- -
- { - this.state.activeTab === "example" ? ( - example ? example : ( + return ( +
+
    +
  • + +
  • + { schema && ( +
  • + +
  • + )} +
+ {this.state.activeTab === "example" && ( +
+ {example ? example : ( - ) - ) : null - } - { - this.state.activeTab === "model" && + )} +
+ )} - - } + {this.state.activeTab === "model" && ( +
+ +
+ )}
-
+ ) } } diff --git a/test/e2e-cypress/tests/a11y/response-tabs.js b/test/e2e-cypress/tests/a11y/response-tabs.js new file mode 100644 index 00000000000..e6f9a454c4a --- /dev/null +++ b/test/e2e-cypress/tests/a11y/response-tabs.js @@ -0,0 +1,35 @@ +describe("Response tab elements", () => { + describe("ModelExample within Operation", () => { + it("should render Example tabpanel by default", () => { + cy + .visit("/?url=/documents/petstore-expanded.openapi.yaml") + .get("#operations-default-addPet") + .click() + .get("div[data-name=examplePanel]") + .first() + .should("have.attr", "aria-hidden", "false") + }) + it("should click Schema tab button and render Schema tabpanel for OpenAPI 3", () => { + cy + .visit("/?url=/documents/petstore-expanded.openapi.yaml") + .get("#operations-default-addPet") + .click() + .get("button.tablinks[data-name=model]") + .first() + .click() + .get("div[data-name=modelPanel]") + .first() + .should("have.attr", "aria-hidden", "false") + }) + it("should click Model tab button and render Model tabpanel for OpenAPI 2", () => { + cy + .visit("/?url=/documents/petstore.swagger.yaml") + .get("#operations-pet-addPet") + .click() + .get("button.tablinks[data-name=model]") + .click() + .get("div[data-name=modelPanel]") + .should("have.attr", "aria-hidden", "false") + }) + }) +}) \ No newline at end of file diff --git a/test/e2e-cypress/tests/bugs/swos-63.js b/test/e2e-cypress/tests/bugs/swos-63.js index 77dbdf03f2d..0e8199f9705 100644 --- a/test/e2e-cypress/tests/bugs/swos-63.js +++ b/test/e2e-cypress/tests/bugs/swos-63.js @@ -19,7 +19,7 @@ describe("SWOS-63: Schema/Model labeling", () => { .visit("/?url=/documents/petstore-expanded.openapi.yaml") .get("#operations-default-findPets") .click() - .get("a.tablinks[data-name=model]") + .get("button.tablinks[data-name=model]") .contains("Schema") }) it("should render `Models` for OpenAPI 2", () => { @@ -28,7 +28,7 @@ describe("SWOS-63: Schema/Model labeling", () => { .get("section.models > h4") .get("#operations-pet-addPet") .click() - .get("a.tablinks[data-name=model]") + .get("button.tablinks[data-name=model]") .contains("Model") }) })