operations.jsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import React from "react"
  2. import { render } from "enzyme"
  3. import { fromJS } from "immutable"
  4. import DeepLink from "components/deep-link"
  5. import Operations from "components/operations"
  6. import {Collapse} from "components/layout-utils"
  7. const components = {
  8. Collapse,
  9. DeepLink,
  10. OperationContainer: ({ path, method }) => <span className="mocked-op" id={`${path}-${method}`} />,
  11. OperationTag: "div",
  12. }
  13. describe("<Operations/>", function(){
  14. it("should render a Swagger2 `get` method, but not a `trace` or `foo` method", function(){
  15. let props = {
  16. fn: {},
  17. specActions: {},
  18. layoutActions: {},
  19. getComponent: (name)=> {
  20. return components[name] || null
  21. },
  22. getConfigs: () => {
  23. return {}
  24. },
  25. specSelectors: {
  26. isOAS3() { return false },
  27. url() { return "https://petstore.swagger.io/v2/swagger.json" },
  28. taggedOperations() {
  29. return fromJS({
  30. "default": {
  31. "operations": [
  32. {
  33. "path": "/pets/{id}",
  34. "method": "get"
  35. },
  36. {
  37. "path": "/pets/{id}",
  38. "method": "trace"
  39. },
  40. {
  41. "path": "/pets/{id}",
  42. "method": "foo"
  43. },
  44. ]
  45. }
  46. })
  47. },
  48. },
  49. layoutSelectors: {
  50. currentFilter() {
  51. return null
  52. },
  53. isShown() {
  54. return true
  55. },
  56. show() {
  57. return true
  58. }
  59. }
  60. }
  61. let wrapper = render(<Operations {...props}/>)
  62. expect(wrapper.find("span.mocked-op").length).toEqual(1)
  63. expect(wrapper.find("span.mocked-op").eq(0).attr("id")).toEqual("/pets/{id}-get")
  64. })
  65. it("should render an OAS3 `get` and `trace` method, but not a `foo` method", function(){
  66. let props = {
  67. fn: {},
  68. specActions: {},
  69. layoutActions: {},
  70. getComponent: (name)=> {
  71. return components[name] || null
  72. },
  73. getConfigs: () => {
  74. return {}
  75. },
  76. specSelectors: {
  77. isOAS3() { return true },
  78. url() { return "https://petstore.swagger.io/v2/swagger.json" },
  79. taggedOperations() {
  80. return fromJS({
  81. "default": {
  82. "operations": [
  83. {
  84. "path": "/pets/{id}",
  85. "method": "get"
  86. },
  87. {
  88. "path": "/pets/{id}",
  89. "method": "trace"
  90. },
  91. {
  92. "path": "/pets/{id}",
  93. "method": "foo"
  94. },
  95. ]
  96. }
  97. })
  98. },
  99. },
  100. layoutSelectors: {
  101. currentFilter() {
  102. return null
  103. },
  104. isShown() {
  105. return true
  106. },
  107. show() {
  108. return true
  109. }
  110. }
  111. }
  112. let wrapper = render(<Operations {...props}/>)
  113. expect(wrapper.find("span.mocked-op").length).toEqual(2)
  114. expect(wrapper.find("span.mocked-op").eq(0).attr("id")).toEqual("/pets/{id}-get")
  115. expect(wrapper.find("span.mocked-op").eq(1).attr("id")).toEqual("/pets/{id}-trace")
  116. })
  117. })