@@ -107,7 +107,7 @@ describe('SchemaTree', () => {
107107 } ) ;
108108 } ) ;
109109
110- describe ( 'array with refed items' , ( ) => {
110+ describe ( 'array with $reffed items' , ( ) => {
111111 let tree : SchemaTree ;
112112 let schema : JSONSchema4 ;
113113
@@ -163,4 +163,102 @@ describe('SchemaTree', () => {
163163 } ) ;
164164 } ) ;
165165 } ) ;
166+
167+ describe ( 'paths generation' , ( ) => {
168+ let schema : JSONSchema4 ;
169+ let tree : SchemaTree ;
170+
171+ beforeEach ( ( ) => {
172+ schema = {
173+ type : 'object' ,
174+ properties : {
175+ user : {
176+ type : 'object' ,
177+ properties : {
178+ name : {
179+ type : 'string' ,
180+ } ,
181+ address : {
182+ type : 'string' ,
183+ } ,
184+ } ,
185+ } ,
186+ permissions : {
187+ type : 'array' ,
188+ items : {
189+ $ref : '#/properties/user' ,
190+ } ,
191+ } ,
192+ } ,
193+ } ;
194+
195+ tree = new SchemaTree ( schema , new SchemaTreeState ( ) , {
196+ expandedDepth : Infinity ,
197+ mergeAllOf : false ,
198+ resolveRef : void 0 ,
199+ } ) ;
200+ } ) ;
201+
202+ test ( 'for root' , ( ) => {
203+ tree . populate ( ) ;
204+
205+ expect ( getNodeMetadata ( tree . itemAt ( 0 ) ! ) ) . toHaveProperty ( 'path' , [ ] ) ;
206+ } ) ;
207+
208+ test ( 'for plain object member' , ( ) => {
209+ tree . populate ( ) ;
210+
211+ expect ( getNodeMetadata ( tree . itemAt ( 1 ) ! ) ) . toHaveProperty ( 'path' , [
212+ 'properties' ,
213+ 'user'
214+ ] ) ;
215+ } ) ;
216+
217+ test ( 'for deep object member' , ( ) => {
218+ tree . populate ( ) ;
219+
220+ expect ( getNodeMetadata ( tree . itemAt ( 2 ) ! ) ) . toHaveProperty ( 'path' , [
221+ 'properties' ,
222+ 'user' ,
223+ 'properties' ,
224+ 'name' ,
225+ ] ) ;
226+ } ) ;
227+
228+ test ( 'for array items' , ( ) => {
229+ tree . populate ( ) ;
230+
231+ expect ( getNodeMetadata ( tree . itemAt ( tree . count - 1 ) ! ) ) . toHaveProperty ( 'path' , [
232+ 'properties' ,
233+ 'permissions' ,
234+ ] ) ;
235+ } ) ;
236+
237+ test ( 'for $reffed array items' , ( ) => {
238+ tree . populate ( ) ;
239+ tree . unwrap ( tree . itemAt ( tree . count - 1 ) as TreeListParentNode ) ;
240+
241+ expect ( getNodeMetadata ( tree . itemAt ( tree . count - 3 ) ! ) ) . toHaveProperty ( 'path' , [
242+ 'properties' ,
243+ 'permissions' ,
244+ 'items' ,
245+ ] ) ;
246+
247+ expect ( getNodeMetadata ( tree . itemAt ( tree . count - 2 ) ! ) ) . toHaveProperty ( 'path' , [
248+ 'properties' ,
249+ 'permissions' ,
250+ 'items' ,
251+ 'properties' ,
252+ 'name' ,
253+ ] ) ;
254+
255+ expect ( getNodeMetadata ( tree . itemAt ( tree . count - 1 ) ! ) ) . toHaveProperty ( 'path' , [
256+ 'properties' ,
257+ 'permissions' ,
258+ 'items' ,
259+ 'properties' ,
260+ 'address' ,
261+ ] ) ;
262+ } ) ;
263+ } ) ;
166264} ) ;
0 commit comments