Skip to content

Commit

Permalink
Merge f5bfee9 into e5aea46
Browse files Browse the repository at this point in the history
  • Loading branch information
tbelcheva committed Jan 24, 2018
2 parents e5aea46 + f5bfee9 commit b5b149f
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
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

0 comments on commit b5b149f

Please sign in to comment.