Skip to content

Commit

Permalink
Fix the filter to avoid filtering by the strings "true/false" when en…
Browse files Browse the repository at this point in the history
…abled
  • Loading branch information
Lucia committed Oct 8, 2020
1 parent d9de60b commit fe69fe8
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/core/components/operations.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default class Operations extends React.Component {
let filter = layoutSelectors.currentFilter()

if (filter) {
if (filter !== true) {
if (filter !== true && filter !== "true" && filter !== "false") {
taggedOps = fn.opsFilter(taggedOps, filter)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/containers/filter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class FilterContainer extends React.Component {

return (
<div>
{filter === null || filter === false ? null :
{filter === null || filter === false || filter === "false" ? null :
<div className="filter-container">
<Col className="filter wrapper" mobile={12}>
<input className={classNames.join(" ")} placeholder="Filter by tag" type="text"
Expand Down
43 changes: 43 additions & 0 deletions test/e2e-cypress/tests/bugs/6276.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
describe("#6276: Query parameter filter=true is filtering by the value 'true'", () => {
describe("With filter=true", () => {
it("should display the filter bar", () => {
cy.visit("/?url=/documents/petstore.swagger.yaml&filter=true")
.get(".operation-filter-input")
.should("exist")
.should("be.empty")
.get('.opblock-tag[data-tag="pet"]')
.should("exist")
.get('.opblock-tag[data-tag="store"]')
.should("exist")
.get('.opblock-tag[data-tag="user"]')
.should("exist")
})
})
describe("With filter=false", () => {
it("should not display the filter bar", () => {
cy.visit("/?url=/documents/petstore.swagger.yaml&filter=false")
.get(".operation-filter-input")
.should("not.exist")
.get('.opblock-tag[data-tag="pet"]')
.should("exist")
.get('.opblock-tag[data-tag="store"]')
.should("exist")
.get('.opblock-tag[data-tag="user"]')
.should("exist")
})
})
describe("With filter=pet", () => {
it("should display the filter bar and only show the operations tagged with pet", () => {
cy.visit("/?url=/documents/petstore.swagger.yaml&filter=pet")
.get(".operation-filter-input")
.should("exist")
.should("have.value", "pet")
.get('.opblock-tag[data-tag="pet"]')
.should("exist")
.get('.opblock-tag[data-tag="store"]')
.should("not.exist")
.get('.opblock-tag[data-tag="user"]')
.should("not.exist")
})
})
})

0 comments on commit fe69fe8

Please sign in to comment.