您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

127 行
3.0 KiB

  1. /* eslint-env mocha */
  2. import React from "react"
  3. import expect from "expect"
  4. import { render } from "enzyme"
  5. import { fromJS } from "immutable"
  6. import DeepLink from "components/deep-link"
  7. import Operations from "components/operations"
  8. import {Collapse} from "components/layout-utils"
  9. const components = {
  10. Collapse,
  11. DeepLink,
  12. OperationContainer: ({ path, method }) => <span className="mocked-op" id={`${path}-${method}`} />,
  13. OperationTag: "div",
  14. }
  15. describe("<Operations/>", function(){
  16. it("should render a Swagger2 `get` method, but not a `trace` or `foo` method", function(){
  17. let props = {
  18. fn: {},
  19. specActions: {},
  20. layoutActions: {},
  21. getComponent: (name)=> {
  22. return components[name] || null
  23. },
  24. getConfigs: () => {
  25. return {}
  26. },
  27. specSelectors: {
  28. isOAS3() { return false },
  29. taggedOperations() {
  30. return fromJS({
  31. "default": {
  32. "operations": [
  33. {
  34. "path": "/pets/{id}",
  35. "method": "get"
  36. },
  37. {
  38. "path": "/pets/{id}",
  39. "method": "trace"
  40. },
  41. {
  42. "path": "/pets/{id}",
  43. "method": "foo"
  44. },
  45. ]
  46. }
  47. })
  48. },
  49. },
  50. layoutSelectors: {
  51. currentFilter() {
  52. return null
  53. },
  54. isShown() {
  55. return true
  56. },
  57. show() {
  58. return true
  59. }
  60. }
  61. }
  62. let wrapper = render(<Operations {...props}/>)
  63. expect(wrapper.find("span.mocked-op").length).toEqual(1)
  64. expect(wrapper.find("span.mocked-op").eq(0).attr("id")).toEqual("/pets/{id}-get")
  65. })
  66. it("should render an OAS3 `get` and `trace` method, but not a `foo` method", function(){
  67. let props = {
  68. fn: {},
  69. specActions: {},
  70. layoutActions: {},
  71. getComponent: (name)=> {
  72. return components[name] || null
  73. },
  74. getConfigs: () => {
  75. return {}
  76. },
  77. specSelectors: {
  78. isOAS3() { return true },
  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. })