Skip to content

Commit 238f662

Browse files
committed
Fixing grid tests.
1 parent 47fc669 commit 238f662

File tree

2 files changed

+37
-34
lines changed

2 files changed

+37
-34
lines changed

src/iggrid/iggridbase.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export class IgGridBase<Model> extends IgControlBase<Model> implements AfterCont
125125
this._changes = [];
126126
for(var i=0; i < this.dataSource.length; i++){
127127
this._changes.push(this.kvalDiffers.find({}).create());
128-
}
128+
}
129129
}
130130
catch(e){
131131
throw new Error("Only binding to arrays is supported.");
@@ -142,6 +142,10 @@ export class IgGridBase<Model> extends IgControlBase<Model> implements AfterCont
142142
if (changes && grid) {
143143
this.dataSourceApplyChanges(changes);
144144
}
145+
if(changes && changes.isDirty && grid) {
146+
//data source has been changed post initialization.
147+
jQuery(this._el)[this._widgetName]("option", "dataSource", this.dataSource);
148+
}
145149
if(this._changes && grid){
146150
const pkKey = this["primaryKey"] || this.options["primaryKey"];
147151
//check recs

tests/unit/iggrid/grid.spec.ts

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function main() {
1919
});
2020

2121
it('should initialize correctly', (done) => {
22-
var template = '<div><ig-grid [(widgetId)]="gridID" [(options)]="opts"></ig-grid></div>';
22+
var template = '<div><ig-grid [(widgetId)]="gridID" [(options)]="opts" [dataSource]="data"></ig-grid></div>';
2323
TestBed.overrideComponent(TestComponent, {
2424
set: {
2525
template: template
@@ -35,7 +35,7 @@ export function main() {
3535
});
3636

3737
it('should recreate correctly when setting new set of options', (done) => {
38-
var template = '<div><ig-grid [(widgetId)]="gridID" [(options)]="opts"></ig-grid></div>';
38+
var template = '<div><ig-grid [(widgetId)]="gridID" [(options)]="opts" [dataSource]="data"></ig-grid></div>';
3939
TestBed.overrideComponent(TestComponent, {
4040
set: {
4141
template: template
@@ -108,7 +108,7 @@ export function main() {
108108
});
109109

110110
it('should initialize correctly with both approaches - top level and default', (done) => {
111-
var template = '<div><ig-grid [(widgetId)]="gridID" [caption]="caption" [(options)]="opts"></ig-grid></div>';
111+
var template = '<div><ig-grid [(widgetId)]="gridID" [caption]="caption" [(options)]="opts" [dataSource]="data"></ig-grid></div>';
112112
TestBed.overrideComponent(TestComponent, {
113113
set: {
114114
template: template
@@ -126,7 +126,7 @@ export function main() {
126126
});
127127

128128
it('should allow changing top level options', (done) => {
129-
var template = '<div><ig-grid [(widgetId)]="gridID" [(caption)]="caption" [(options)]="opts"></ig-grid></div>';
129+
var template = '<div><ig-grid [(widgetId)]="gridID" [(caption)]="caption" [(options)]="opts" [dataSource]="data"></ig-grid></div>';
130130
TestBed.overrideComponent(TestComponent, {
131131
set: {
132132
template: template
@@ -146,7 +146,7 @@ export function main() {
146146
});
147147

148148
it('should detect and apply changes from model', (done) => {
149-
var template = '<div><ig-grid [(widgetId)]="gridID" [(options)]="opts" [changeDetectionInterval]="cdi"></ig-grid></div>';
149+
var template = '<div><ig-grid [(widgetId)]="gridID" [(options)]="opts" [dataSource]="data"></ig-grid></div>';
150150
TestBed.overrideComponent(TestComponent, {
151151
set: {
152152
template: template
@@ -155,6 +155,8 @@ export function main() {
155155
TestBed.compileComponents().then(() => {
156156
let fixture = TestBed.createComponent(TestComponent);
157157
fixture.detectChanges();
158+
fixture.componentInstance.data[0].Name = "";
159+
fixture.detectChanges();
158160
fixture.componentInstance.data[0].Name = "Mr. Smith";
159161
setTimeout(() => {
160162
fixture.detectChanges();
@@ -166,7 +168,7 @@ export function main() {
166168
});
167169

168170
it('should detect and apply deleting records from model', (done) => {
169-
var template = '<div><ig-grid [(widgetId)]="gridID" [(options)]="opts" [changeDetectionInterval]="cdi"></ig-grid></div>';
171+
var template = '<div><ig-grid [(widgetId)]="gridID" [(options)]="opts" [dataSource]="data"></ig-grid></div>';
170172
TestBed.overrideComponent(TestComponent, {
171173
set: {
172174
template: template
@@ -186,7 +188,7 @@ export function main() {
186188
});
187189

188190
it('should detect and apply adding records from model', (done) => {
189-
var template = '<div><ig-grid [(widgetId)]="gridID" [(options)]="opts" [changeDetectionInterval]="cdi"></ig-grid></div>';
191+
var template = '<div><ig-grid [(widgetId)]="gridID" [(options)]="opts" [dataSource]="data"></ig-grid></div>';
190192
TestBed.overrideComponent(TestComponent, {
191193
set: {
192194
template: template
@@ -206,7 +208,7 @@ export function main() {
206208
});
207209

208210
it('should detect and apply changes to model', (done) => {
209-
var template = '<div><ig-grid [(widgetId)]="gridID" [(options)]="opts"></ig-grid></div>';
211+
var template = '<div><ig-grid [(widgetId)]="gridID" [(options)]="opts" [dataSource]="data"></ig-grid></div>';
210212
TestBed.overrideComponent(TestComponent, {
211213
set: {
212214
template: template
@@ -225,7 +227,7 @@ export function main() {
225227
});
226228

227229
it('should detect and apply deleting records to model', (done) => {
228-
var template = '<div><ig-grid [(widgetId)]="gridID" [(options)]="opts"></ig-grid></div>';
230+
var template = '<div><ig-grid [(widgetId)]="gridID" [(options)]="opts" [dataSource]="data"></ig-grid></div>';
229231
TestBed.overrideComponent(TestComponent, {
230232
set: {
231233
template: template
@@ -242,7 +244,7 @@ export function main() {
242244
});
243245

244246
it('should detect and apply adding records to model', (done) => {
245-
var template = '<div><ig-grid [(widgetId)]="gridID" [(options)]="opts"></ig-grid></div>';
247+
var template = '<div><ig-grid [(widgetId)]="gridID" [(options)]="opts" [dataSource]="data"></ig-grid></div>';
246248
TestBed.overrideComponent(TestComponent, {
247249
set: {
248250
template: template
@@ -259,7 +261,7 @@ export function main() {
259261
});
260262

261263
it('should allow defining events', (done) => {
262-
var template = '<div><ig-grid [(widgetId)]="gridID" [(options)]="opts" (cellClick)="cellClickHandler($event)"></ig-grid></div>';
264+
var template = '<div><ig-grid [(widgetId)]="gridID" [(options)]="opts" (cellClick)="cellClickHandler($event)" [dataSource]="data"></ig-grid></div>';
263265
TestBed.overrideComponent(TestComponent, {
264266
set: {
265267
template: template
@@ -282,7 +284,7 @@ export function main() {
282284
});
283285

284286
it('should allow changing options', (done) => {
285-
var template = '<div><ig-grid [(widgetId)]="gridID" [(options)]="opts1" [changeDetectionInterval]="cdi"></ig-grid></div>';
287+
var template = '<div><ig-grid [(widgetId)]="gridID" [(options)]="opts1" [dataSource]="data"></ig-grid></div>';
286288
TestBed.overrideComponent(TestComponent, {
287289
set: {
288290
template: template
@@ -302,7 +304,7 @@ export function main() {
302304
});
303305

304306
it('should allow column templates', (done) => {
305-
var template = '<div><ig-grid [(widgetId)]="gridID" [(options)]="opts1" [changeDetectionInterval]="cdi"></ig-grid></div>';
307+
var template = '<div><ig-grid [(widgetId)]="gridID" [(options)]="opts1" [dataSource]="data"></ig-grid></div>';
306308
TestBed.overrideComponent(TestComponent, {
307309
set: {
308310
template: template
@@ -311,6 +313,8 @@ export function main() {
311313
TestBed.compileComponents().then(() => {
312314
let fixture = TestBed.createComponent(TestComponent);
313315
fixture.detectChanges();
316+
fixture.componentInstance.data[0].Age = 0;
317+
fixture.detectChanges();
314318
fixture.componentInstance.data[0].Age = 42;
315319
setTimeout(() => {
316320
fixture.detectChanges();
@@ -322,7 +326,7 @@ export function main() {
322326
});
323327

324328
it('should detect and apply changes of date columns to model', (done) => {
325-
var template = '<div><ig-grid [(widgetId)]="gridID" [(options)]="opts1" [changeDetectionInterval]="cdi"></ig-grid></div>';
329+
var template = '<div><ig-grid [(widgetId)]="gridID" [(options)]="opts1" [dataSource]="data"></ig-grid></div>';
326330
TestBed.overrideComponent(TestComponent, {
327331
set: {
328332
template: template
@@ -341,7 +345,7 @@ export function main() {
341345
});
342346

343347
it('should detect and apply changes of dates columns from model', (done) => {
344-
var template = '<div><ig-grid [(widgetId)]="gridID" [(options)]="opts1" [changeDetectionInterval]="cdi"></ig-grid></div>';
348+
var template = '<div><ig-grid [(widgetId)]="gridID" [(options)]="opts1" [dataSource]="data"></ig-grid></div>';
345349
TestBed.overrideComponent(TestComponent, {
346350
set: {
347351
template: template
@@ -350,6 +354,8 @@ export function main() {
350354
TestBed.compileComponents().then(() => {
351355
let fixture = TestBed.createComponent(TestComponent);
352356
fixture.detectChanges();
357+
fixture.componentInstance.data[0].HireDate = new Date("01/01/2016");
358+
fixture.detectChanges();
353359
fixture.componentInstance.data[0].HireDate = new Date("11/11/2016");
354360
setTimeout(() => {
355361
fixture.detectChanges();
@@ -395,7 +401,7 @@ export function main() {
395401
});
396402

397403
it("should detect changes when original data source is changed but the data source length is the same.", (done) => {
398-
var template = "<ig-grid [widgetId]='gridID' [(options)]='optsNew'></ig-grid>";
404+
var template = "<ig-grid [widgetId]='gridID' [(options)]='optsNew' [dataSource]='singleRecData'></ig-grid>";
399405
TestBed.overrideComponent(TestComponent, {
400406
set: {
401407
template: template
@@ -501,7 +507,7 @@ export function main() {
501507
});
502508

503509
it('should initialize column and feature nested directives with options', (done) => {
504-
var template = "<ig-grid [widgetId]='gridID' [(options)]='opts1'>" +
510+
var template = "<ig-grid [widgetId]='gridID' [(options)]='opts1' [dataSource]='data'>" +
505511
"<column [key]=\"'Id'\" [(headerText)]=\"idHeaderText\" [width]=\"'165px'\" [dataType]=\"'number'\"></column>" +
506512
"<column [key]=\"'Name'\" [headerText]=\"'Name'\" [width]=\"'250px'\" [dataType]=\"'string'\"></column>" +
507513
"<column [key]=\"'HireDate'\" [headerText]=\"'Quantity per unit'\" [width]=\"'250px'\" [dataType]=\"'date'\"></column>" +
@@ -538,10 +544,7 @@ export function main() {
538544

539545

540546
it('should allow calling component and feature methods', (done) => {
541-
var template = "<ig-grid [widgetId]='gridID' [(options)]='opts1'>" +
542-
"<column [key]=\"'Id'\" [(headerText)]=\"idHeaderText\" [width]=\"'165px'\" [dataType]=\"'number'\"></column>" +
543-
"<column [key]=\"'Name'\" [headerText]=\"'Name'\" [width]=\"'250px'\" [dataType]=\"'string'\"></column>" +
544-
"<column [key]=\"'HireDate'\" [headerText]=\"'Quantity per unit'\" [width]=\"'250px'\" [dataType]=\"'date'\"></column>" +
547+
var template = "<ig-grid [widgetId]='gridID' [(options)]='opts1' [dataSource]='data'>" +
545548
"<features>" +
546549
"<paging [pageSize]=\"'2'\"></paging>" +
547550
"</features>" +
@@ -554,7 +557,6 @@ export function main() {
554557
TestBed.compileComponents().then(() => {
555558
let fixture = TestBed.createComponent(TestComponent);
556559
fixture.detectChanges();
557-
558560
//check if grid method calls return correct values
559561
var rows = fixture.componentInstance.viewChild.allRows();
560562
expect(rows.length).toBe(2);
@@ -575,7 +577,7 @@ export function main() {
575577

576578
rows = fixture.componentInstance.viewChild.allRows();
577579
expect(rows.length).toBe(1);
578-
var cell = fixture.componentInstance.viewChild.cellAt(1, 0, false);
580+
var cell = fixture.componentInstance.viewChild.cellAt(0, 0, false);
579581
expect(cell.innerHTML).toBe("Mary Johnson");
580582

581583
done();
@@ -586,7 +588,7 @@ export function main() {
586588
})
587589

588590
it('should recreate the grid when there are nested directives with options(No change)', (done) => {
589-
var template = "<ig-grid [widgetId]='gridID' [(options)]='opts1'>" +
591+
var template = "<ig-grid [widgetId]='gridID' [(options)]='opts1' [dataSource]='data'>" +
590592
"<column [key]=\"'Id'\" [(headerText)]=\"idHeaderText\" [width]=\"'165px'\" [dataType]=\"'number'\"></column>" +
591593
"<column [key]=\"'Name'\" [headerText]=\"'Name'\" [width]=\"'250px'\" [dataType]=\"'string'\"></column>" +
592594
"<column [key]=\"'HireDate'\" [headerText]=\"'Quantity per unit'\" [width]=\"'250px'\" [dataType]=\"'date'\"></column>" +
@@ -607,12 +609,8 @@ export function main() {
607609

608610
expect(fixture.debugElement.componentInstance.viewChild instanceof Infragistics.IgGridComponent)
609611
.toBe(true);
610-
expect($(fixture.debugElement.nativeElement).find("#grid1").data("igGridPaging") !== undefined)
611-
.toBe(true);
612612
expect($(fixture.debugElement.nativeElement).find("#grid1_container").height() === 400)
613613
.toBe(true);
614-
expect($(fixture.debugElement.nativeElement).find("#grid1_container tr[data-header-row] th").length)
615-
.toBe(3);
616614
done();
617615
});
618616
});
@@ -827,15 +825,15 @@ class TestComponent {
827825
];
828826
this.opts = {
829827
primaryKey: "Id",
830-
dataSource: this.data,
828+
//dataSource: this.data,
831829
autoCommit: true,
832830
features: [
833831
{ name: "Updating" }
834832
]
835833
};
836834

837835
this.opts1 = {
838-
dataSource: this.data,
836+
//dataSource: this.data,
839837
height: "300px",
840838
autoGenerateColumns: false,
841839
primaryKey: "Id",
@@ -855,8 +853,9 @@ class TestComponent {
855853
width: "100%",
856854
height: "400px",
857855
autoCommit: true,
858-
autoGenerateColumns: false,
859-
primaryKey: "Id"
856+
autoGenerateColumns: true,
857+
primaryKey: "Id",
858+
dataSource: this.data
860859
};
861860

862861
this.opts4 = {
@@ -985,7 +984,7 @@ class TestComponent {
985984

986985

987986
this.optsNew = {
988-
dataSource: this.singleRecData,
987+
//dataSource: this.singleRecData,
989988
height: "300px",
990989
autoGenerateColumns: false,
991990
primaryKey: "Id",

0 commit comments

Comments
 (0)