You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

58 lines
1.8 KiB

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