25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

4557-default-parameter-values.jsx 2.0 KiB

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