primitive-model.jsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import React from "react"
  2. import { shallow } from "enzyme"
  3. import { fromJS } from "immutable"
  4. import PrimitiveModel from "components/primitive-model"
  5. describe("<PrimitiveModel/>", function () {
  6. describe("Model name", function () {
  7. const dummyComponent = () => null
  8. const components = {
  9. Markdown: dummyComponent,
  10. EnumModel: dummyComponent,
  11. Property: dummyComponent,
  12. }
  13. const props = {
  14. getComponent: c => components[c],
  15. getConfigs: () => ({
  16. showExtensions: false
  17. }),
  18. name: "Name from props",
  19. depth: 1,
  20. schema: fromJS({
  21. type: "string",
  22. title: "Custom model title"
  23. })
  24. }
  25. it("renders the schema's title", function () {
  26. // When
  27. const wrapper = shallow(<PrimitiveModel {...props} />)
  28. const modelTitleEl = wrapper.find("span.model-title")
  29. expect(modelTitleEl.length).toEqual(1)
  30. // Then
  31. expect(modelTitleEl.text()).toEqual("Custom model title")
  32. })
  33. it("falls back to the passed-in `name` prop for the title", function () {
  34. // When
  35. props.schema = fromJS({
  36. type: "string"
  37. })
  38. const wrapper = shallow(<PrimitiveModel {...props} />)
  39. const modelTitleEl = wrapper.find("span.model-title")
  40. expect(modelTitleEl.length).toEqual(1)
  41. // Then
  42. expect(modelTitleEl.text()).toEqual("Name from props")
  43. })
  44. })
  45. })