No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

126 líneas
3.0 KiB

  1. /* eslint-env mocha */
  2. import React from "react"
  3. import expect, { createSpy } 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. }
  14. describe("<Operations/>", function(){
  15. it("should render a Swagger2 `get` method, but not a `trace` or `foo` method", function(){
  16. let props = {
  17. fn: {},
  18. specActions: {},
  19. layoutActions: {},
  20. getComponent: (name)=> {
  21. return components[name] || null
  22. },
  23. getConfigs: () => {
  24. return {}
  25. },
  26. specSelectors: {
  27. isOAS3() { return false },
  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. taggedOperations() {
  79. return fromJS({
  80. "default": {
  81. "operations": [
  82. {
  83. "path": "/pets/{id}",
  84. "method": "get"
  85. },
  86. {
  87. "path": "/pets/{id}",
  88. "method": "trace"
  89. },
  90. {
  91. "path": "/pets/{id}",
  92. "method": "foo"
  93. },
  94. ]
  95. }
  96. })
  97. },
  98. },
  99. layoutSelectors: {
  100. currentFilter() {
  101. return null
  102. },
  103. isShown() {
  104. return true
  105. },
  106. show() {
  107. return true
  108. }
  109. }
  110. }
  111. let wrapper = render(<Operations {...props}/>)
  112. expect(wrapper.find("span.mocked-op").length).toEqual(2)
  113. expect(wrapper.find("span.mocked-op").eq(0).attr("id")).toEqual("/pets/{id}-get")
  114. expect(wrapper.find("span.mocked-op").eq(1).attr("id")).toEqual("/pets/{id}-trace")
  115. })
  116. })