response.jsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import React from "react"
  2. import { shallow } from "enzyme"
  3. import { fromJS, List } from "immutable"
  4. import Response from "components/response"
  5. import ModelExample from "components/model-example"
  6. import { inferSchema } from "corePlugins/samples/fn"
  7. describe("<Response />", function () {
  8. const dummyComponent = () => null
  9. const components = {
  10. headers: dummyComponent,
  11. highlightCode: dummyComponent,
  12. modelExample: ModelExample,
  13. Markdown: dummyComponent,
  14. operationLink: dummyComponent,
  15. contentType: dummyComponent
  16. }
  17. const props = {
  18. getComponent: c => components[c],
  19. getConfigs: () => {
  20. return {}
  21. },
  22. specSelectors: {
  23. isOAS3() {
  24. return false
  25. }
  26. },
  27. fn: {
  28. inferSchema
  29. },
  30. contentType: "application/json",
  31. className: "for-test",
  32. specPath: List(),
  33. response: fromJS({
  34. schema: {
  35. type: "object",
  36. properties: {
  37. // Note reverse order: c, b, a
  38. "c": {
  39. type: "integer"
  40. },
  41. "b": {
  42. type: "boolean"
  43. },
  44. "a": {
  45. type: "string"
  46. }
  47. }
  48. }
  49. }),
  50. code: "200"
  51. }
  52. it("renders the model-example schema properties in order", function () {
  53. const wrapper = shallow(<Response {...props} />)
  54. const renderedModelExample = wrapper.find(ModelExample)
  55. expect(renderedModelExample.length).toEqual(1)
  56. // Assert the schema's properties have maintained their order
  57. const modelExampleSchemaProperties = renderedModelExample.props().schema.toJS().properties
  58. expect(Object.keys(modelExampleSchemaProperties)).toEqual(["c", "b", "a"])
  59. })
  60. })