parameter-row.jsx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. import React from "react"
  2. import { List, fromJS } from "immutable"
  3. import { render } from "enzyme"
  4. import ParameterRow from "components/parameter-row"
  5. describe("<ParameterRow/>", () => {
  6. const createProps = ({ param, isOAS3 }) => ({
  7. getComponent: () => "div",
  8. specSelectors: {
  9. parameterWithMetaByIdentity: () => param,
  10. isOAS3: () => isOAS3,
  11. isSwagger2: () => !isOAS3
  12. },
  13. oas3Selectors: { activeExamplesMember: () => {} },
  14. param,
  15. rawParam: param,
  16. pathMethod: [],
  17. getConfigs: () => ({})
  18. })
  19. it("Can render Swagger 2 parameter type with format", () => {
  20. const param = fromJS({
  21. name: "petUuid",
  22. in: "path",
  23. description: "UUID that identifies a pet",
  24. type: "string",
  25. format: "uuid"
  26. })
  27. const props = createProps({ param, isOAS3: false })
  28. const wrapper = render(<ParameterRow {...props}/>)
  29. expect(wrapper.find(".parameter__type").length).toEqual(1)
  30. expect(wrapper.find(".parameter__type").text()).toEqual("string($uuid)")
  31. })
  32. it("Can render Swagger 2 parameter type without format", () => {
  33. const param = fromJS({
  34. name: "petId",
  35. in: "path",
  36. description: "ID that identifies a pet",
  37. type: "string"
  38. })
  39. const props = createProps({ param, isOAS3: false })
  40. const wrapper = render(<ParameterRow {...props}/>)
  41. expect(wrapper.find(".parameter__type").length).toEqual(1)
  42. expect(wrapper.find(".parameter__type").text()).toEqual("string")
  43. })
  44. it("Can render OAS3 parameter type with format", () => {
  45. const param = fromJS({
  46. name: "petUuid",
  47. in: "path",
  48. description: "UUID that identifies a pet",
  49. schema: {
  50. type: "string",
  51. format: "uuid"
  52. }
  53. })
  54. const props = createProps({ param, isOAS3: true })
  55. const wrapper = render(<ParameterRow {...props}/>)
  56. expect(wrapper.find(".parameter__type").length).toEqual(1)
  57. expect(wrapper.find(".parameter__type").text()).toEqual("string($uuid)")
  58. })
  59. it("Can render OAS3 parameter type without format", () => {
  60. const param = fromJS({
  61. name: "petId",
  62. in: "path",
  63. description: "ID that identifies a pet",
  64. schema: {
  65. type: "string"
  66. }
  67. })
  68. const props = createProps({ param, isOAS3: true })
  69. const wrapper = render(<ParameterRow {...props}/>)
  70. expect(wrapper.find(".parameter__type").length).toEqual(1)
  71. expect(wrapper.find(".parameter__type").text()).toEqual("string")
  72. })
  73. })
  74. describe("bug #5573: zero default and example values", function () {
  75. it("should apply a Swagger 2.0 default value of zero", function () {
  76. const paramValue = fromJS({
  77. description: "a pet",
  78. type: "integer",
  79. default: 0
  80. })
  81. let props = {
  82. getComponent: () => "div",
  83. specSelectors: {
  84. security() { },
  85. parameterWithMetaByIdentity() { return paramValue },
  86. isOAS3() { return false },
  87. isSwagger2() { return true }
  88. },
  89. fn: {},
  90. operation: { get: () => { } },
  91. onChange: jest.fn(),
  92. param: paramValue,
  93. rawParam: paramValue,
  94. onChangeConsumes: () => { },
  95. pathMethod: [],
  96. getConfigs: () => { return {} },
  97. specPath: List([])
  98. }
  99. render(<ParameterRow {...props} />)
  100. expect(props.onChange).toHaveBeenCalled()
  101. expect(props.onChange).toHaveBeenCalledWith(paramValue, "0", false)
  102. })
  103. it("should apply a Swagger 2.0 example value of zero", function () {
  104. const paramValue = fromJS({
  105. description: "a pet",
  106. type: "integer",
  107. schema: {
  108. example: 0
  109. }
  110. })
  111. let props = {
  112. getComponent: () => "div",
  113. specSelectors: {
  114. security() { },
  115. parameterWithMetaByIdentity() { return paramValue },
  116. isOAS3() { return false },
  117. isSwagger2() { return true }
  118. },
  119. fn: {},
  120. operation: { get: () => { } },
  121. onChange: jest.fn(),
  122. param: paramValue,
  123. rawParam: paramValue,
  124. onChangeConsumes: () => { },
  125. pathMethod: [],
  126. getConfigs: () => { return {} },
  127. specPath: List([])
  128. }
  129. render(<ParameterRow {...props} />)
  130. expect(props.onChange).toHaveBeenCalled()
  131. expect(props.onChange).toHaveBeenCalledWith(paramValue, "0", false)
  132. })
  133. it("should apply an OpenAPI 3.0 default value of zero", function () {
  134. const paramValue = fromJS({
  135. description: "a pet",
  136. schema: {
  137. type: "integer",
  138. default: 0
  139. }
  140. })
  141. let props = {
  142. getComponent: () => "div",
  143. specSelectors: {
  144. security() { },
  145. parameterWithMetaByIdentity() { return paramValue },
  146. isOAS3() { return true },
  147. isSwagger2() { return false }
  148. },
  149. oas3Selectors: {
  150. activeExamplesMember: () => null
  151. },
  152. fn: {},
  153. operation: { get: () => { } },
  154. onChange: jest.fn(),
  155. param: paramValue,
  156. rawParam: paramValue,
  157. onChangeConsumes: () => { },
  158. pathMethod: [],
  159. getConfigs: () => { return {} },
  160. specPath: List([])
  161. }
  162. render(<ParameterRow {...props} />)
  163. expect(props.onChange).toHaveBeenCalled()
  164. expect(props.onChange).toHaveBeenCalledWith(paramValue, "0", false)
  165. })
  166. it("should apply an OpenAPI 3.0 example value of zero", function () {
  167. const paramValue = fromJS({
  168. description: "a pet",
  169. schema: {
  170. type: "integer",
  171. example: 0
  172. }
  173. })
  174. let props = {
  175. getComponent: () => "div",
  176. specSelectors: {
  177. security() { },
  178. parameterWithMetaByIdentity() { return paramValue },
  179. isOAS3() { return true },
  180. isSwagger2() { return false }
  181. },
  182. oas3Selectors: {
  183. activeExamplesMember: () => null
  184. },
  185. fn: {},
  186. operation: { get: () => { } },
  187. onChange: jest.fn(),
  188. param: paramValue,
  189. rawParam: paramValue,
  190. onChangeConsumes: () => { },
  191. pathMethod: [],
  192. getConfigs: () => { return {} },
  193. specPath: List([])
  194. }
  195. render(<ParameterRow {...props} />)
  196. expect(props.onChange).toHaveBeenCalled()
  197. expect(props.onChange).toHaveBeenCalledWith(paramValue, "0", false)
  198. })
  199. })