@@ -28,6 +28,17 @@ describe('merge.js', () => {
2828 "description" : "Gimme yea name lad" ,
2929 "type" : "string"
3030 } ,
31+ "shoe" : {
32+ "title" : "Shoes" ,
33+ "description" : "Shoe details" ,
34+ "type" : "array" ,
35+ "items" : {
36+ "type" : "object" ,
37+ "properties" : {
38+ "brand" : { "type" :"string" }
39+ }
40+ }
41+ } ,
3142 "gender" : {
3243 "readOnly" : true ,
3344 "title" : "Choose" ,
@@ -48,53 +59,38 @@ describe('merge.js', () => {
4859 } )
4960
5061 describe ( 'merge' , ( ) => {
51- it ( 'should combine a schema and form definition, regardless of order' , ( ) => {
52- merge ( schema , [ 'name' , 'gender' ] ) . should . be . deep . equal ( stdForm . form ) ;
53- merge ( schema , [ 'gender' ] ) . should . be . deep . equal ( [ stdForm . form [ 1 ] ] ) ;
54- merge ( schema , [ 'gender' , 'name' ] ) . should . be . deep . equal ( [ stdForm . form [ 1 ] , stdForm . form [ 0 ] ] ) ;
62+ it ( 'should handle a schema lookup or schema for first argument' , ( ) => {
63+ merge ( stdForm . lookup , [ 'name' , 'shoe' , 'gender' ] ) . should . be . deep . equal ( stdForm . form ) ;
64+ merge ( schema , [ '*' ] ) . should . be . deep . equal ( stdForm . form ) ;
5565 } ) ;
5666
5767 it ( 'should handle a wildcard * in the form definition' , ( ) => {
5868 merge ( schema , [ '*' ] ) . should . be . deep . equal ( stdForm . form ) ;
5969 } ) ;
6070
71+ it ( 'should not handle a wildcard * if the schema is a lookup' , ( ) => {
72+ merge ( stdForm . lookup , [ '*' ] ) . should . not . be . deep . equal ( stdForm . form ) ;
73+ } ) ;
74+
75+ it ( 'should combine a schema and form definition, regardless of order' , ( ) => {
76+ merge ( schema , [ 'name' , 'shoe' , 'gender' ] ) . should . be . deep . equal ( stdForm . form ) ;
77+ merge ( schema , [ 'gender' ] ) . should . be . deep . equal ( [ stdForm . form [ 2 ] ] ) ;
78+ merge ( schema , [ 'gender' , 'name' ] ) . should . be . deep . equal ( [ stdForm . form [ 2 ] , stdForm . form [ 0 ] ] ) ;
79+ } ) ;
80+
81+
6182 it ( 'should allow items that are not in the schema' , ( ) => {
6283 merge ( schema , [ '*' , { type :'fieldset' } ] ) . should . be . deep . equal ( stdForm . form . concat ( [ { type :'fieldset' } ] ) ) ;
6384 } ) ;
64- } ) ;
65- /**
66- it('should translate "readOnly" in schema to "readonly" on the merged form defintion', () => {
67- inject(function(schemaForm){
68- var schema = {
69- "type": "object",
70- "properties": {
71- "name": {
72- "title": "Name",
73- "description": "Gimme yea name lad",
74- "type": "string"
75- },
76- "gender": {
77- "readOnly": true,
78- "title": "Choose",
79- "type": "string",
80- "enum": [
81- "undefined",
82- "null",
83- "NaN",
84- ]
85- }
86- }
87- };
8885
89- var merged = schemaForm.merge(schema, ['gender']);
86+ it ( 'should translate "readOnly" in schema to "readonly" on the merged form defintion' , ( ) => {
87+ var merged = merge ( schema , [ 'gender' ] ) ;
9088 merged [ 0 ] . should . have . property ( 'readonly' ) ;
9189 merged [ 0 ] . readonly . should . eq ( true )
9290 } ) ;
93- });
9491
95- it('should push readOnly in schema down into objects and arrays', () => {
96- inject(function(schemaForm) {
97- var schema = {
92+ it ( 'should push readOnly in schema down into objects and arrays' , ( ) => {
93+ let subschema = {
9894 'type' : 'object' ,
9995 'readOnly' : true ,
10096 'properties' : {
@@ -117,7 +113,7 @@ describe('merge.js', () => {
117113 }
118114 } ;
119115
120- var merged = schemaForm. merge(schema , ['*']);
116+ var merged = merge ( subschema , [ '*' ] ) ;
121117
122118 //sub
123119 merged [ 0 ] . should . have . property ( 'readonly' ) ;
@@ -130,13 +126,10 @@ describe('merge.js', () => {
130126 //array items
131127 merged [ 0 ] . items [ 0 ] . items [ 0 ] . should . have . property ( 'readonly' ) ;
132128 merged [ 0 ] . items [ 0 ] . items [ 0 ] . readonly . should . eq ( true ) ;
133-
134129 } ) ;
135- });
136130
137- it('should push readonly in form def down into objects and arrays', () => {
138- inject(function(schemaForm) {
139- var schema = {
131+ it ( 'should push readonly in form def down into objects and arrays' , ( ) => {
132+ let subschema = {
140133 'type' : 'object' ,
141134 'properties' : {
142135 'sub' : {
@@ -158,7 +151,7 @@ describe('merge.js', () => {
158151 }
159152 } ;
160153
161- var merged = schemaForm. merge(schema , [{key: 'sub', readonly: true}]);
154+ var merged = merge ( subschema , [ { key : 'sub' , readonly : true } ] ) ;
162155
163156 //sub
164157 merged [ 0 ] . should . have . property ( 'readonly' ) ;
@@ -171,8 +164,6 @@ describe('merge.js', () => {
171164 //array items
172165 merged [ 0 ] . items [ 0 ] . items [ 0 ] . should . have . property ( 'readonly' ) ;
173166 merged [ 0 ] . items [ 0 ] . items [ 0 ] . readonly . should . eq ( true ) ;
174-
175167 } ) ;
176168 } ) ;
177- */
178169} ) ;
0 commit comments