1+ import React from "react"
2+ import expect from "expect"
3+ import { shallow } from "enzyme"
4+ import { fromJS } from "immutable"
5+ import ObjectModel from "components/object-model"
6+ import ModelExample from "components/model-example"
7+ import Immutable from "immutable"
8+ import Model from "components/model"
9+ import ModelCollapse from "components/model-collapse"
10+ import { inferSchema } from "corePlugins/samples/fn"
11+
12+ describe ( "<ObjectModel />" , function ( ) {
13+ const dummyComponent = ( ) => null
14+ const components = {
15+ "JumpToPath" : dummyComponent ,
16+ "Markdown" : dummyComponent ,
17+ "Model" : Model ,
18+ "ModelCollapse" : ModelCollapse
19+ }
20+ const props = {
21+ getComponent : c => components [ c ] ,
22+ isRef : false ,
23+ schema : Immutable . fromJS (
24+ {
25+ "properties" : {
26+ // Note reverse order: c, b, a
27+ c : {
28+ type : "integer" ,
29+ name : "c"
30+ } ,
31+ b : {
32+ type : "boolean" ,
33+ name : "b"
34+ } ,
35+ a : {
36+ type : "string" ,
37+ name : "a"
38+ }
39+ }
40+ }
41+ ) ,
42+ specSelectors : {
43+ isOAS3 ( ) {
44+ return false
45+ }
46+ } ,
47+ className : "for-test"
48+ }
49+ it ( "renders a callapsible header" , function ( ) {
50+ const wrapper = shallow ( < ObjectModel { ...props } /> )
51+ const renderedModelCollapse = wrapper . find ( ModelCollapse )
52+ expect ( renderedModelCollapse . length ) . toEqual ( 1 )
53+ } )
54+
55+ it ( "renders the object properties in order" , function ( ) {
56+ const wrapper = shallow ( < ObjectModel { ...props } /> )
57+ const renderedModel = wrapper . find ( Model )
58+ expect ( renderedModel . length ) . toEqual ( 3 )
59+
60+ // Assert the schema's properties have maintained their order
61+ //const modelExampleSchemaProperties = renderedModel.props().schema.toJS().properties
62+ console . log ( renderedModel . get ( 0 ) . props ) ;
63+
64+ expect ( renderedModel . get ( 0 ) . props . schema . get ( "name" ) ) . toEqual ( "c" )
65+ expect ( renderedModel . get ( 1 ) . props . schema . get ( "name" ) ) . toEqual ( "b" )
66+ expect ( renderedModel . get ( 2 ) . props . schema . get ( "name" ) ) . toEqual ( "a" )
67+ //expect( Object.keySeq(modelExampleSchemaProperties) ).toEqual(["c", "b", "a"])
68+ } )
69+ } )
0 commit comments