22import { it , iit , describe , expect , inject , injectAsync , beforeEachProviders , fakeAsync , tick , TestComponentBuilder , AsyncTestCompleter } from 'angular2/testing_internal' ;
33import { Component , ViewChild , TemplateRef } from 'angular2/core' ;
44import * as Infragistics from '../../../src/igniteui.angular2' ;
5- import { NorthwindEmployees } from "../../../samples/data/northwind-employees" ;
65
76export function main ( ) {
87 describe ( 'Infragistics Angular2 HierarchicalGrid' , function ( ) {
@@ -25,11 +24,11 @@ export function main() {
2524 . createAsync ( TestComponent )
2625 . then ( ( fixture ) => {
2726 fixture . detectChanges ( ) ;
28- fixture . componentInstance . data [ 0 ] . FirstName = "Test" ;
27+ fixture . componentInstance . data [ 0 ] . Name = "Test" ;
2928 fixture . detectChanges ( ) ;
3029 setTimeout ( ( ) => {
3130 fixture . detectChanges ( ) ;
32- expect ( $ ( fixture . debugElement . nativeElement ) . find ( "#grid1 tr:first td[aria-describedby='grid1_FirstName ']" ) . text ( ) )
31+ expect ( $ ( fixture . debugElement . nativeElement ) . find ( "#grid1 tr:first td[aria-describedby='grid1_Name ']" ) . text ( ) )
3332 . toBe ( "Test" ) ;
3433 async . done ( ) ;
3534 } , 10 ) ;
@@ -49,9 +48,9 @@ export function main() {
4948 setTimeout ( ( ) => {
5049 fixture . detectChanges ( ) ;
5150 expect ( $ ( fixture . debugElement . nativeElement ) . find ( "#grid1 tr" ) . length )
52- . toBe ( 8 ) ;
53- expect ( $ ( fixture . debugElement . nativeElement ) . find ( "#grid1 tr:first td[aria-describedby='grid1_FirstName ']" ) . text ( ) )
54- . toBe ( "Andrew " ) ;
51+ . toBe ( 2 ) ;
52+ expect ( $ ( fixture . debugElement . nativeElement ) . find ( "#grid1 tr:first td[aria-describedby='grid1_Name ']" ) . text ( ) )
53+ . toBe ( "Beverages " ) ;
5554 async . done ( ) ;
5655 } , 10 ) ;
5756 } ) ;
@@ -65,13 +64,13 @@ export function main() {
6564 . then ( ( fixture ) => {
6665 fixture . detectChanges ( ) ;
6766 //add item
68- fixture . componentInstance . data . push ( { EmployeeID : 200 , LastName : "Snow" , FirstName : " John" , Title : "Vice President, Sales "} ) ;
67+ fixture . componentInstance . data . push ( { ID : 200 , Name : "John Snow " } ) ;
6968 setTimeout ( ( ) => {
7069 fixture . detectChanges ( ) ;
7170 expect ( $ ( fixture . debugElement . nativeElement ) . find ( "#grid1 tr" ) . length )
72- . toBe ( 10 ) ;
73- expect ( $ ( fixture . debugElement . nativeElement ) . find ( "#grid1 tr:last td[aria-describedby='grid1_FirstName ']" ) . text ( ) )
74- . toBe ( "John" ) ;
71+ . toBe ( 4 ) ;
72+ expect ( $ ( fixture . debugElement . nativeElement ) . find ( "#grid1 tr:last td[aria-describedby='grid1_Name ']" ) . text ( ) )
73+ . toBe ( "John Snow " ) ;
7574 async . done ( ) ;
7675 } , 10 ) ;
7776 } ) ;
@@ -86,10 +85,10 @@ export function main() {
8685 fixture . detectChanges ( ) ;
8786
8887 //update row
89- $ ( "#grid1" ) . igGridUpdating ( "updateRow" , 1 , { FirstName : "Maria" } ) ;
88+ $ ( "#grid1" ) . igGridUpdating ( "updateRow" , 0 , { Name : "Maria" } ) ;
9089 setTimeout ( ( ) => {
9190 fixture . detectChanges ( ) ;
92- var fName = fixture . componentInstance . data [ 0 ] . FirstName ;
91+ var fName = fixture . componentInstance . data [ 0 ] . Name ;
9392 expect ( fName ) . toBe ( "Maria" ) ;
9493 async . done ( ) ;
9594 } , 10 ) ;
@@ -104,11 +103,11 @@ export function main() {
104103 . then ( ( fixture ) => {
105104 fixture . detectChanges ( ) ;
106105 //delete row
107- $ ( "#grid1" ) . igGridUpdating ( "deleteRow" , 2 ) ;
106+ $ ( "#grid1" ) . igGridUpdating ( "deleteRow" , 0 ) ;
108107 setTimeout ( ( ) => {
109108 fixture . detectChanges ( ) ;
110- expect ( fixture . componentInstance . data . length ) . toBe ( 8 ) ;
111- expect ( fixture . componentInstance . data [ 1 ] . EmployeeID ) . toBe ( 3 ) ;
109+ expect ( fixture . componentInstance . data . length ) . toBe ( 2 ) ;
110+ expect ( fixture . componentInstance . data [ 0 ] . ID ) . toBe ( 1 ) ;
112111 async . done ( ) ;
113112 } , 10 ) ;
114113 } ) ;
@@ -121,11 +120,11 @@ export function main() {
121120 . createAsync ( TestComponent )
122121 . then ( ( fixture ) => {
123122 fixture . detectChanges ( ) ;
124- $ ( "#grid1" ) . igGridUpdating ( "addRow" , { EmployeeID : 200 , LastName : "Snow" , FirstName : "John" , Title : "Vice President, Sales "} ) ;
123+ $ ( "#grid1" ) . igGridUpdating ( "addRow" , { ID : 200 , Name : "Snow" } ) ;
125124 setTimeout ( ( ) => {
126125 fixture . detectChanges ( ) ;
127- expect ( fixture . componentInstance . data . length ) . toBe ( 10 ) ;
128- expect ( fixture . componentInstance . data [ 9 ] . EmployeeID ) . toBe ( 200 ) ;
126+ expect ( fixture . componentInstance . data . length ) . toBe ( 4 ) ;
127+ expect ( fixture . componentInstance . data [ 3 ] . ID ) . toBe ( 200 ) ;
129128 async . done ( ) ;
130129 } , 10 ) ;
131130 } ) ;
@@ -144,12 +143,12 @@ export function main() {
144143 var row = $ ( "#grid1" ) . igGrid ( "rowAt" , 0 ) ;
145144 $ ( "#grid1" ) . igHierarchicalGrid ( "expand" , row ) ;
146145 //change data child data
147- fixture . componentInstance . data [ 0 ] . Orders . results . removeAt ( 0 ) ;
146+ fixture . componentInstance . data [ 0 ] . Products . removeAt ( 0 ) ;
148147
149148 setTimeout ( ( ) => {
150149 fixture . detectChanges ( ) ;
151- expect ( $ ( fixture . debugElement . nativeElement ) . find ( "#grid1" ) . igHierarchicalGrid ( "option" , "dataSource" ) [ 0 ] . Orders . results . length )
152- . toBe ( 122 ) ;
150+ expect ( $ ( fixture . debugElement . nativeElement ) . find ( "#grid1" ) . igHierarchicalGrid ( "option" , "dataSource" ) [ 0 ] . Products . length )
151+ . toBe ( 0 ) ;
153152 async . done ( ) ;
154153 } , 10 ) ;
155154 } ) ;
@@ -166,11 +165,11 @@ export function main() {
166165 var row = $ ( "#grid1" ) . igGrid ( "rowAt" , 0 ) ;
167166 $ ( "#grid1" ) . igHierarchicalGrid ( "expand" , row ) ;
168167 //change data child data
169- fixture . componentInstance . data [ 0 ] . Orders . results [ 0 ] . ShipName = "Custom ShipName " ;
168+ fixture . componentInstance . data [ 0 ] . Products [ 0 ] . Name = "Custom Name " ;
170169 setTimeout ( ( ) => {
171170 fixture . detectChanges ( ) ;
172- expect ( $ ( $ ( fixture . debugElement . nativeElement ) . find ( "#grid1_1_Orders_child " ) . igGrid ( "cellAt" , 2 , 0 ) ) . text ( ) )
173- . toBe ( "Custom ShipName " ) ;
171+ expect ( $ ( $ ( fixture . debugElement . nativeElement ) . find ( "#grid1_0_Products_child " ) . igGrid ( "cellAt" , 1 , 0 ) ) . text ( ) )
172+ . toBe ( "Custom Name " ) ;
174173 async . done ( ) ;
175174 } , 10 ) ;
176175 } ) ;
@@ -191,49 +190,64 @@ class TestComponent {
191190 @ViewChild ( Infragistics . IgHierarchicalGridComponent ) public viewChild : Infragistics . IgHierarchicalGridComponent ;
192191
193192 constructor ( ) {
194- this . data = NorthwindEmployees . getData ( ) ;
193+ this . data = [
194+ {
195+ "ID" : 0 ,
196+ "Name" : "Food" ,
197+ "Products" : [
198+ { "ID" : 0 , "Name" : "Bread" , "Price" : "2.5" }
199+ ]
200+ } ,
201+ {
202+ "ID" : 1 ,
203+ "Name" : "Beverages" ,
204+ "Products" : [
205+ { "ID" : 1 , "Name" : "Milk" , "Price" : "3.5" } ,
206+ { "ID" : 2 , "Name" : "Vint soda" , "Price" : "20.9" }
207+ ]
208+ } ,
209+ {
210+ "ID" : 2 ,
211+ "Name" : "Electronics" ,
212+ "Products" : [
213+ { "ID" : 7 , "Name" : "DVD Player" , "Price" : "35.88" } ,
214+ { "ID" : 8 , "Name" : "LCD HDTV" , "Price" : "1088.8" }
215+ ]
216+ }
217+ ] ;
218+
195219 this . gridID = "grid1" ;
196220 this . opts = {
197221 autoCommit :true ,
198222 dataSource : this . data ,
199- primaryKey : "EmployeeID " ,
223+ primaryKey : "ID " ,
200224 width : "100%" ,
201225 height : "400px" ,
202226 autoGenerateColumns : false ,
203- autoGenerateColumnLayouts : false ,
204-
205- columns : [
206- { key : "EmployeeID" , headerText : "EmployeeID" , width :"25%" , dataType :"number" , hidden :true } ,
207- { key : "FirstName" , headerText : "First Name" , width :"25%" , dataType :"string" } ,
208- { key : "LastName" , headerText : "Last Name" , width :"25%" , dataType :"string" } ,
209- { key : "Title" , headerText : "Title" , width :"25%" , dataType :"string" } ,
210- { key : "BirthDate" , headerText : "Birth Date" , width :"25%" , dataType :"date" }
211- ] ,
227+ autoGenerateColumnLayouts : false ,
228+ columns : [
229+ { headerText : "ID" , key : "ID" , width : "50px" , dataType : "number" } ,
230+ { headerText : "Name" , key : "Name" , width : "130px" , dataType : "string" }
231+ ] ,
212232 features : [
213233 {
214234 name : "Updating"
215235 }
216236 ] ,
217237 columnLayouts : [
218- {
219- key : "Orders" ,
220- responseDataKey : "results" ,
221- primaryKey : "OrderID" ,
222- autoGenerateColumns : false ,
223- width : "100%" ,
224- columns : [
225- { key : "OrderID" , headerText : "OrderID" , width :"25%" , dataType :"string" } ,
226- { key : "Freight" , headerText : "Freight" , width :"25%" , dataType :"string" } ,
227- { key : "ShipName" , headerText : "ShipName" , width :"25%" , dataType :"string" } ,
228- { key : "ShipAddress" , headerText : "ShipAddress" , width :"25%" , dataType :"string" }
229- ] ,
230- features : [
231- {
232- name : "Updating"
233- }
234- ]
235- }
236- ]
238+ {
239+ key : "Products" ,
240+ responseDataKey : "" ,
241+ childrenDataProperty : "Products" ,
242+ autoGenerateColumns : false ,
243+ primaryKey : "ID" ,
244+ columns : [
245+ { key : "ID" , headerText : "ID" , width : "25px" } ,
246+ { key : "Name" , headerText : "Product Name" , width : "90px" } ,
247+ { key : "Price" , headerText : "Price" , dataType : "number" , width : "55px" }
248+ ]
249+ }
250+ ]
237251 } ;
238252 }
239253}
0 commit comments