Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for bug 247937 #242

Merged
merged 10 commits into from
Jan 24, 2018
13 changes: 13 additions & 0 deletions src/igcontrolbase/igcontrolbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,24 @@ export class IgControlBase<Model> implements DoCheck {
isArray(value) {
return Object.prototype.toString.call(value) === "[object Array]";
}

isNode(o) {
return typeof Node === "object" ? o instanceof Node :
o && typeof o === "object" && typeof o.nodeType === "number" && typeof o.nodeName==="string";
}

isDOM(o) {
return typeof HTMLElement === "object" ? o instanceof HTMLElement :
o && typeof o === "object" && o !== null && o.nodeType === 1 && typeof o.nodeName==="string"
}

equalsDiff(o1, o2, diff?) {
if (o1 === o2) { return true; }
if (o1 === null || o2 === null) { return false; }
if (o1 !== o1 && o2 !== o2) { return true; }// NaN === NaN
if (this.isDOM(o1) || this.isNode(o1)) {
return;
}
var t1 = typeof o1, t2 = typeof o2, length, key, keySet, dirty, skipDiff = false, changedVals = [];
if (t1 === t2) {
if (t1 === "object") {
Expand Down
47 changes: 47 additions & 0 deletions tests/unit/iggrid/grid.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,53 @@ export function main() {
}, 10);
});
});
//issue #242 (bug #247937)
it('should detect changes properly when grid column with validation is updated and then an option(s) change has been performed', (done) => {
var template = '<div><ig-grid [(widgetId)]="gridID" [(options)]="opts" [changeDetectionInterval]="0"></ig-grid></div>';
TestBed.overrideComponent(TestComponent, {
set: {
template: template
}
});
TestBed.compileComponents().then(() => {
let fixture = TestBed.createComponent(TestComponent);
var res = fixture.componentInstance.viewChild.equalsDiff( $("<div id='1'></div>"), $("<div id='2'></div>"));
expect(res).toBe(false);
done();
});
});
it('test if grid option is DOM element', (done) => {
var template = '<div><ig-grid [(widgetId)]="gridID" [(options)]="opts"></ig-grid></div>';
TestBed.overrideComponent(TestComponent, {
set: {
template: template
}
});
TestBed.compileComponents().then(() => {
let fixture = TestBed.createComponent(TestComponent);
let divElement = document.createElement("div");
var res = fixture.componentInstance.viewChild.isDOM(divElement);
expect(res).toBe(true);
done();
});
});
it('test if grid option is Node element', (done) => {
var template = '<div><ig-grid [(widgetId)]="gridID" [(options)]="opts"></ig-grid></div>';
TestBed.overrideComponent(TestComponent, {
set: {
template: template
}
});
TestBed.compileComponents().then(() => {
let fixture = TestBed.createComponent(TestComponent);
let para = document.createElement("p");
let node = document.createTextNode("node test");
para.appendChild(node);
var res = fixture.componentInstance.viewChild.isNode(node);
expect(res).toBe(true);
done();
});
});
});
}

Expand Down