diff --git a/test/components/operations.js b/test/components/operations.js new file mode 100644 index 00000000..7609b985 --- /dev/null +++ b/test/components/operations.js @@ -0,0 +1,120 @@ +/* eslint-env mocha */ +import React from "react" +import expect, { createSpy } from "expect" +import { render } from "enzyme" +import { fromJS } from "immutable" +import Operations from "components/operations" +import {Collapse} from "components/layout-utils" + +const components = { + Collapse, + OperationContainer: ({ path, method }) => +} + +describe.only("", function(){ + it("should render a Swagger2 `get` method, but not a `trace` or `foo` method", function(){ + + let props = { + getComponent: (name)=> { + + return components[name] || null + }, + getConfigs: () => { + return {} + }, + specSelectors: { + isOAS3() { return false }, + taggedOperations() { + return fromJS({ + "default": { + "operations": [ + { + "path": "/pets/{id}", + "method": "get" + }, + { + "path": "/pets/{id}", + "method": "trace" + }, + { + "path": "/pets/{id}", + "method": "foo" + }, + ] + } + }) + }, + }, + layoutSelectors: { + currentFilter() { + return null + }, + isShown() { + return true + }, + show() { + return true + } + } + } + + let wrapper = render() + + expect(wrapper.find("span.mocked-op").length).toEqual(2) + expect(wrapper.find("span.mocked-op").eq(0).attr("id")).toEqual("/pets/{id}-get") + expect(wrapper.find("span.mocked-op").eq(1).attr("id")).toEqual("/pets/{id}-trace") + }) + + it("should render an OAS3 `get` and `trace` method, but not a `foo` method", function(){ + + let props = { + getComponent: (name)=> { + + return components[name] || null + }, + getConfigs: () => { + return {} + }, + specSelectors: { + isOAS3() { return true }, + taggedOperations() { + return fromJS({ + "default": { + "operations": [ + { + "path": "/pets/{id}", + "method": "get" + }, + { + "path": "/pets/{id}", + "method": "trace" + }, + { + "path": "/pets/{id}", + "method": "foo" + }, + ] + } + }) + }, + }, + layoutSelectors: { + currentFilter() { + return null + }, + isShown() { + return true + }, + show() { + return true + } + } + } + + let wrapper = render() + + expect(wrapper.find("span.mocked-op").length).toEqual(2) + expect(wrapper.find("span.mocked-op").eq(0).attr("id")).toEqual("/pets/{id}-get") + expect(wrapper.find("span.mocked-op").eq(1).attr("id")).toEqual("/pets/{id}-trace") + }) +})