Skip to content

Commit

Permalink
Merge branch 'master' into dkamburov/fix-268
Browse files Browse the repository at this point in the history
  • Loading branch information
mpavlinov committed Jul 24, 2018
2 parents 2d93765 + c2becae commit 40fb10f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/igcombo/igcombo.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export class IgComboComponent extends IgControlBase<IgCombo> implements ControlV

ngOnInit() {
let that = this;
const valueKey = this["valueKey"] || this.options.valueKey;
if (this._dataSource === null || this._dataSource === undefined) {
this._dataSource = this.options["dataSource"];
}
Expand All @@ -45,6 +44,7 @@ export class IgComboComponent extends IgControlBase<IgCombo> implements ControlV
// D.P. #244 only attach selectionchanged handler if there's a model to update
jQuery(this._el).on(this._widgetName.toLowerCase() + "selectionchanged", function (evt, ui) {
var items = ui.items;
const valueKey = ui.owner.options.valueKey;

if (items.length <= 0 && !ui.owner.options.multiSelection.enabled) {
that._model.viewToModelUpdate(null);
Expand Down
90 changes: 55 additions & 35 deletions tests/unit/igcombo/combo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,29 +90,29 @@ export function main() {
});
});

it('should be updated correctly if the ngModel value is cleared.', (done) => {
var template = '<div><ig-combo [(widgetId)]="comboID" [(options)]="options" [(ngModel)]="combo.value1" [dataSource]="northwind"></ig-combo></div>';
TestBed.overrideComponent(TestComponent, {
set: {
template: template
}
});
it('should be updated correctly if the ngModel value is cleared.', (done) => {
var template = '<div><ig-combo [(widgetId)]="comboID" [(options)]="options" [(ngModel)]="combo.value1" [dataSource]="northwind"></ig-combo></div>';
TestBed.overrideComponent(TestComponent, {
set: {
template: template
}
});
TestBed.compileComponents().then(() => {
let fixture = TestBed.createComponent(TestComponent);
fixture.detectChanges();
fixture.componentInstance.combo.value1 = 1;
fixture.detectChanges();
fixture.componentInstance.combo.value1 = 1;
fixture.detectChanges();
setTimeout(function () {
//clear
$("#combo1").parents("ig-combo").find(".ui-igcombo-clearicon").click();
fixture.detectChanges();
setTimeout(function(){
expect(fixture.componentInstance.combo.value1).toBeNull();
done();
}, 10);
//clear
$("#combo1").parents("ig-combo").find(".ui-igcombo-clearicon").click();
fixture.detectChanges();
setTimeout(function () {
expect(fixture.componentInstance.combo.value1).toBeNull();
done();
}, 10);
}, 10);
});
});
});

it('should be updated correctly if the ngModel value is cleared when multiple selection.', (done) => {
var template = '<div><ig-combo [(widgetId)]="comboID" [(options)]="optionsMultipleSelection" [(ngModel)]="combo.value1" [dataSource]="northwind"></ig-combo></div>';
Expand All @@ -122,21 +122,40 @@ export function main() {
}
});
TestBed.compileComponents().then(() => {
let fixture = TestBed.createComponent(TestComponent);
fixture.detectChanges();
fixture.componentInstance.combo.value1 = 1;
fixture.detectChanges();
setTimeout(function () {
//clear
$("#combo1").parents("ig-combo").find(".ui-igcombo-clearicon").click();
let fixture = TestBed.createComponent(TestComponent);
fixture.detectChanges();
setTimeout(function(){
expect(fixture.componentInstance.combo.value1 instanceof Array && fixture.componentInstance.combo.value1.length === 0).toBeTruthy();
done();
fixture.componentInstance.combo.value1 = 1;
fixture.detectChanges();
setTimeout(function () {
//clear
$("#combo1").parents("ig-combo").find(".ui-igcombo-clearicon").click();
fixture.detectChanges();
setTimeout(function () {
expect(fixture.componentInstance.combo.value1 instanceof Array && fixture.componentInstance.combo.value1.length === 0).toBeTruthy();
done();
}, 10);
}, 10);
}, 10);
});
});

it('should apply ngModel when multiple selection and no valueKey set.', (done) => {
var template = '<div><ig-combo [(widgetId)]="comboID" [options]="{multiSelection: {enabled: true, showCheckboxes: true}}" [(ngModel)]="val" [dataSource]="[\'foo\', \'bar\', \'bas\']"></ig-combo></div>';
TestBed.overrideComponent(TestComponent, {
set: {
template: template
}
});
TestBed.compileComponents().then(() => {
let fixture = TestBed.createComponent(TestComponent);
fixture.detectChanges();
var elem = $("#combo1").igCombo("itemsFromIndex", 0)["element"];
$("#combo1").igCombo("select", elem, {}, true);
fixture.detectChanges();
expect(fixture.componentInstance.val.length).toBe(1);
expect(fixture.componentInstance.val[0]).toBe("foo");
done();
});
});
});

it('the ngModel should be updated correctly if the combo selection is updated', (done) => {
var template = '<div><ig-combo [(widgetId)]="comboID" [(options)]="options" [(ngModel)]="combo.value1" [dataSource]="northwind"></ig-combo></div>';
Expand Down Expand Up @@ -220,19 +239,19 @@ export function main() {
fixture.detectChanges();
expect($("#combo1").igCombo("value")).toBe(fixture.componentInstance.combo.value1);
expect($("#combo1").val())
.toBe(fixture.componentInstance.northwind[fixture.componentInstance.combo.value1 - 1].ProductName);
.toBe(fixture.componentInstance.northwind[fixture.componentInstance.combo.value1 - 1].ProductName);
done();
}, 10);
});
});

it('should initialize correctly when datasource is remote', (done) => {
$['mockjax']({
url: "myURL/Northwind",
contentType: 'application/json',
dataType: 'json',
responseText: '[{"ProductID": 1, "ProductName": "Chai"}]'
});
url: "myURL/Northwind",
contentType: 'application/json',
dataType: 'json',
responseText: '[{"ProductID": 1, "ProductName": "Chai"}]'
});
var template = '<div><ig-combo [(widgetId)]="comboID" [(options)]="options2" [(ngModel)]="combo.value1"></ig-combo></div>';
TestBed.overrideComponent(TestComponent, {
set: {
Expand Down Expand Up @@ -262,6 +281,7 @@ class TestComponent {
public combo: any;
private comboID: string
public data: Array<any> = [];
public val = [];
@ViewChild(Infragistics.IgComboComponent) public viewChild: Infragistics.IgComboComponent;

constructor() {
Expand Down

0 comments on commit 40fb10f

Please sign in to comment.