@@ -89,6 +89,36 @@ func makeTestTree() *v3.Node {
8989 return root
9090}
9191
92+ func makeRootChangeTree () * v3.Node {
93+ openapiChange := & whatChangedModel.Change {
94+ ChangeType : whatChangedModel .Modified ,
95+ Property : "openapi" ,
96+ Original : "3.0.0" ,
97+ New : "3.1.0" ,
98+ Breaking : true ,
99+ }
100+ infoChange := & whatChangedModel.Change {
101+ ChangeType : whatChangedModel .Modified ,
102+ Property : "version" ,
103+ Original : "1.0" ,
104+ New : "2.0" ,
105+ }
106+
107+ infoNode := & v3.Node {
108+ Label : "Info" ,
109+ Type : "Info" ,
110+ }
111+ infoNode .AppendChange (& mockChanged {changes : []* whatChangedModel.Change {infoChange }})
112+
113+ root := & v3.Node {
114+ Label : "Document" ,
115+ Type : "Document" ,
116+ Children : []* v3.Node {infoNode },
117+ }
118+ root .AppendChange (& mockChanged {changes : []* whatChangedModel.Change {openapiChange }})
119+ return root
120+ }
121+
92122func TestFlattenNodeTree_AllExpanded (t * testing.T ) {
93123 root := makeTestTree ()
94124 tm := newTreeModel (root , 20 )
@@ -130,6 +160,29 @@ func TestCursorStartsOnFirstLeaf(t *testing.T) {
130160 assert .Equal (t , "deprecated" , entry .change .Property )
131161}
132162
163+ func TestFlattenNodeTree_IncludesRootOwnedLeaves (t * testing.T ) {
164+ root := makeRootChangeTree ()
165+ tm := newTreeModel (root , 20 )
166+
167+ require .Len (t , tm .entries , 3 )
168+ require .NotNil (t , tm .entries [0 ].change )
169+ assert .Equal (t , "openapi" , tm .entries [0 ].change .Property )
170+ assert .Equal (t , "Info" , tm .entries [1 ].node .Label )
171+ require .NotNil (t , tm .entries [2 ].change )
172+ assert .Equal (t , "version" , tm .entries [2 ].change .Property )
173+ }
174+
175+ func TestCursorStartsOnRootOwnedLeaf (t * testing.T ) {
176+ root := makeRootChangeTree ()
177+ tm := newTreeModel (root , 20 )
178+
179+ require .Equal (t , 0 , tm .cursor )
180+ entry := tm .selectedEntry ()
181+ require .NotNil (t , entry )
182+ require .NotNil (t , entry .change )
183+ assert .Equal (t , "openapi" , entry .change .Property )
184+ }
185+
133186func TestMoveDown_SkipsBranchNodes (t * testing.T ) {
134187 root := makeTestTree ()
135188 tm := newTreeModel (root , 20 )
0 commit comments