@@ -102,7 +102,6 @@ describe('treeControl', function() {
102102 beforeEach ( function ( ) {
103103 $rootScope . label = "exLabel" ;
104104 $rootScope . treedata = createSubTree ( 2 , 2 ) ;
105- $rootScope . treedata . push ( { } ) ;
106105 element = $compile ( '<treecontrol tree-model="treedata">{{label}} - {{node.label}}</treecontrol>' ) ( $rootScope ) ;
107106 $rootScope . $digest ( ) ;
108107 } ) ;
@@ -113,6 +112,88 @@ describe('treeControl', function() {
113112 } ) ;
114113 } ) ;
115114
115+ describe ( 'support special members in label scope' , function ( ) {
116+ beforeEach ( function ( ) {
117+ $rootScope . label = "exLabel" ;
118+ $rootScope . treedata = createSubTree ( 2 , 4 ) ;
119+ } ) ;
120+
121+ it ( 'should render $parentNode for a tree with multiple roots' , function ( ) {
122+ element = $compile ( '<treecontrol tree-model="treedata">{{node.label}} parent:{{$parentNode?$parentNode.label:"N/A"}}</treecontrol>' ) ( $rootScope ) ;
123+ $rootScope . $digest ( ) ;
124+ expect ( element . find ( 'li:eq(0) span' ) . text ( ) ) . toBe ( 'node 1 parent:N/A' ) ;
125+ expect ( element . find ( 'li:eq(1) span' ) . text ( ) ) . toBe ( 'node 6 parent:N/A' ) ;
126+ expect ( element . find ( 'li:eq(2) span' ) . text ( ) ) . toBe ( 'node 11 parent:N/A' ) ;
127+ expect ( element . find ( 'li:eq(3) span' ) . text ( ) ) . toBe ( 'node 16 parent:N/A' ) ;
128+ element . find ( 'li:eq(0) .tree-branch-head' ) . click ( ) ;
129+ expect ( element . find ( 'li:eq(0) li:eq(0) span' ) . text ( ) ) . toBe ( 'node 2 parent:node 1' ) ;
130+ } ) ;
131+
132+ it ( 'should render $parentNode for a tree with a single root' , function ( ) {
133+ num = 1 ;
134+ $rootScope . treedata = createSubTree ( 2 , 1 ) ;
135+ element = $compile ( '<treecontrol tree-model="treedata">{{node.label}} parent:{{$parentNode?$parentNode.label:"N/A"}}</treecontrol>' ) ( $rootScope ) ;
136+ $rootScope . $digest ( ) ;
137+ expect ( element . find ( 'li:eq(0) span' ) . text ( ) ) . toBe ( 'node 1 parent:N/A' ) ;
138+ element . find ( 'li:eq(0) .tree-branch-head' ) . click ( ) ;
139+ expect ( element . find ( 'li:eq(0) li:eq(0) span' ) . text ( ) ) . toBe ( 'node 2 parent:node 1' ) ;
140+ } ) ;
141+
142+ it ( 'should render $index' , function ( ) {
143+ element = $compile ( '<treecontrol tree-model="treedata">{{node.label}} index:{{$index}}</treecontrol>' ) ( $rootScope ) ;
144+ $rootScope . $digest ( ) ;
145+ expect ( element . find ( 'li:eq(0) span' ) . text ( ) ) . toBe ( 'node 1 index:0' ) ;
146+ expect ( element . find ( 'li:eq(1) span' ) . text ( ) ) . toBe ( 'node 6 index:1' ) ;
147+ expect ( element . find ( 'li:eq(2) span' ) . text ( ) ) . toBe ( 'node 11 index:2' ) ;
148+ expect ( element . find ( 'li:eq(3) span' ) . text ( ) ) . toBe ( 'node 16 index:3' ) ;
149+ } ) ;
150+
151+ it ( 'should render $first' , function ( ) {
152+ element = $compile ( '<treecontrol tree-model="treedata">{{node.label}} first:{{$first}}</treecontrol>' ) ( $rootScope ) ;
153+ $rootScope . $digest ( ) ;
154+ expect ( element . find ( 'li:eq(0) span' ) . text ( ) ) . toBe ( 'node 1 first:true' ) ;
155+ expect ( element . find ( 'li:eq(1) span' ) . text ( ) ) . toBe ( 'node 6 first:false' ) ;
156+ expect ( element . find ( 'li:eq(2) span' ) . text ( ) ) . toBe ( 'node 11 first:false' ) ;
157+ expect ( element . find ( 'li:eq(3) span' ) . text ( ) ) . toBe ( 'node 16 first:false' ) ;
158+ } ) ;
159+
160+ it ( 'should render $middle' , function ( ) {
161+ element = $compile ( '<treecontrol tree-model="treedata">{{node.label}} middle:{{$middle}}</treecontrol>' ) ( $rootScope ) ;
162+ $rootScope . $digest ( ) ;
163+ expect ( element . find ( 'li:eq(0) span' ) . text ( ) ) . toBe ( 'node 1 middle:false' ) ;
164+ expect ( element . find ( 'li:eq(1) span' ) . text ( ) ) . toBe ( 'node 6 middle:true' ) ;
165+ expect ( element . find ( 'li:eq(2) span' ) . text ( ) ) . toBe ( 'node 11 middle:true' ) ;
166+ expect ( element . find ( 'li:eq(3) span' ) . text ( ) ) . toBe ( 'node 16 middle:false' ) ;
167+ } ) ;
168+
169+ it ( 'should render $last' , function ( ) {
170+ element = $compile ( '<treecontrol tree-model="treedata">{{node.label}} last:{{$last}}</treecontrol>' ) ( $rootScope ) ;
171+ $rootScope . $digest ( ) ;
172+ expect ( element . find ( 'li:eq(0) span' ) . text ( ) ) . toBe ( 'node 1 last:false' ) ;
173+ expect ( element . find ( 'li:eq(1) span' ) . text ( ) ) . toBe ( 'node 6 last:false' ) ;
174+ expect ( element . find ( 'li:eq(2) span' ) . text ( ) ) . toBe ( 'node 11 last:false' ) ;
175+ expect ( element . find ( 'li:eq(3) span' ) . text ( ) ) . toBe ( 'node 16 last:true' ) ;
176+ } ) ;
177+
178+ it ( 'should render $even' , function ( ) {
179+ element = $compile ( '<treecontrol tree-model="treedata">{{node.label}} even:{{$even}}</treecontrol>' ) ( $rootScope ) ;
180+ $rootScope . $digest ( ) ;
181+ expect ( element . find ( 'li:eq(0) span' ) . text ( ) ) . toBe ( 'node 1 even:true' ) ;
182+ expect ( element . find ( 'li:eq(1) span' ) . text ( ) ) . toBe ( 'node 6 even:false' ) ;
183+ expect ( element . find ( 'li:eq(2) span' ) . text ( ) ) . toBe ( 'node 11 even:true' ) ;
184+ expect ( element . find ( 'li:eq(3) span' ) . text ( ) ) . toBe ( 'node 16 even:false' ) ;
185+ } ) ;
186+
187+ it ( 'should render $odd' , function ( ) {
188+ element = $compile ( '<treecontrol tree-model="treedata">{{node.label}} odd:{{$odd}}</treecontrol>' ) ( $rootScope ) ;
189+ $rootScope . $digest ( ) ;
190+ expect ( element . find ( 'li:eq(0) span' ) . text ( ) ) . toBe ( 'node 1 odd:false' ) ;
191+ expect ( element . find ( 'li:eq(1) span' ) . text ( ) ) . toBe ( 'node 6 odd:true' ) ;
192+ expect ( element . find ( 'li:eq(2) span' ) . text ( ) ) . toBe ( 'node 11 odd:false' ) ;
193+ expect ( element . find ( 'li:eq(3) span' ) . text ( ) ) . toBe ( 'node 16 odd:true' ) ;
194+ } ) ;
195+ } ) ;
196+
116197 describe ( 'selection' , function ( ) {
117198 it ( 'should publish the currently selected node on scope' , function ( ) {
118199 $rootScope . treedata = createSubTree ( 2 , 2 ) ;
0 commit comments