4557-default-parameter-values.jsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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("bug #4557: default parameter values", function(){
  6. it("should apply a Swagger 2.0 default value", function(){
  7. const paramValue = fromJS({
  8. description: "a pet",
  9. type: "string",
  10. default: "MyDefaultValue"
  11. })
  12. let props = {
  13. getComponent: ()=> "div",
  14. specSelectors: {
  15. security(){},
  16. parameterWithMetaByIdentity(){ return paramValue },
  17. isOAS3(){ return false },
  18. isSwagger2(){ return true }
  19. },
  20. fn: {},
  21. operation: {get: ()=>{}},
  22. onChange: jest.fn(),
  23. param: paramValue,
  24. rawParam: paramValue,
  25. onChangeConsumes: () => {},
  26. pathMethod: [],
  27. getConfigs: () => { return {} },
  28. specPath: List([])
  29. }
  30. render(<ParameterRow {...props}/>)
  31. expect(props.onChange).toHaveBeenCalled()
  32. expect(props.onChange).toHaveBeenCalledWith(paramValue, "MyDefaultValue", false)
  33. })
  34. it("should apply an OpenAPI 3.0 default value", function(){
  35. const paramValue = fromJS({
  36. description: "a pet",
  37. schema: {
  38. type: "string",
  39. default: "MyDefaultValue"
  40. }
  41. })
  42. let props = {
  43. getComponent: ()=> "div",
  44. specSelectors: {
  45. security(){},
  46. parameterWithMetaByIdentity(){ return paramValue },
  47. isOAS3(){ return true },
  48. isSwagger2() { return false }
  49. },
  50. oas3Selectors: {
  51. activeExamplesMember: () => null
  52. },
  53. fn: {},
  54. operation: {get: ()=>{}},
  55. onChange: jest.fn(),
  56. param: paramValue,
  57. rawParam: paramValue,
  58. onChangeConsumes: () => {},
  59. pathMethod: [],
  60. getConfigs: () => { return {} },
  61. specPath: List([])
  62. }
  63. render(<ParameterRow {...props}/>)
  64. expect(props.onChange).toHaveBeenCalled()
  65. expect(props.onChange).toHaveBeenCalledWith(paramValue, "MyDefaultValue", false)
  66. })
  67. })