Skip to content

Commit

Permalink
Merge pull request #254 from dkamburov/master
Browse files Browse the repository at this point in the history
 Use 'null' as a null value for the model of igCombo instead of empty array for single selection
  • Loading branch information
mpavlinov committed Mar 13, 2018
2 parents dc42f8d + 4ee2c50 commit 3eef34d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/igcombo/igcombo.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export class IgComboComponent extends IgControlBase<IgCombo> implements ControlV
jQuery(this._el).on(this._widgetName.toLowerCase() + "selectionchanged", function (evt, ui) {
var items = ui.items;

if (items.length <= 0) {
that._model.viewToModelUpdate(ui.owner.value());
if (items.length <= 0 && !ui.owner.options.multiSelection.enabled) {
that._model.viewToModelUpdate(null);
return;
}

Expand Down
45 changes: 34 additions & 11 deletions tests/unit/igcombo/combo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function main() {
});

it('should initialize correctly', (done) => {
var template = '<div><ig-combo [(widgetId)]="comboID" [(options)]="options" [changeDetectionInterval]="cdi" [(ngModel)]="combo.value1"></ig-combo></div>';
var template = '<div><ig-combo [(widgetId)]="comboID" [(options)]="options" [(ngModel)]="combo.value1"></ig-combo></div>';
TestBed.overrideComponent(TestComponent, {
set: {
template: template
Expand All @@ -32,7 +32,7 @@ export function main() {
});

it('should initialize ig-combo without ngModel', (done) => {
var template = '<div><ig-combo [(widgetId)]="comboID" [(options)]="options" [changeDetectionInterval]="cdi"></ig-combo></div>';
var template = '<div><ig-combo [(widgetId)]="comboID" [(options)]="options"></ig-combo></div>';
TestBed.overrideComponent(TestComponent, {
set: {
template: template
Expand Down Expand Up @@ -71,7 +71,7 @@ export function main() {


it('should be updated correctly if the ngModel value is updated', (done) => {
var template = '<div><ig-combo [(widgetId)]="comboID" [(options)]="options" [changeDetectionInterval]="cdi" [(ngModel)]="combo.value1" [dataSource]="northwind"></ig-combo></div>';
var template = '<div><ig-combo [(widgetId)]="comboID" [(options)]="options" [(ngModel)]="combo.value1" [dataSource]="northwind"></ig-combo></div>';
TestBed.overrideComponent(TestComponent, {
set: {
template: template
Expand All @@ -91,7 +91,7 @@ export function main() {
});

it('should be updated correctly if the ngModel value is cleared.', (done) => {
var template = '<div><ig-combo [(widgetId)]="comboID" [(options)]="options" [changeDetectionInterval]="cdi" [(ngModel)]="combo.value1" [dataSource]="northwind"></ig-combo></div>';
var template = '<div><ig-combo [(widgetId)]="comboID" [(options)]="options" [(ngModel)]="combo.value1" [dataSource]="northwind"></ig-combo></div>';
TestBed.overrideComponent(TestComponent, {
set: {
template: template
Expand All @@ -107,15 +107,39 @@ export function main() {
$("#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();
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>';
TestBed.overrideComponent(TestComponent, {
set: {
template: template
}
});
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();
fixture.detectChanges();
setTimeout(function(){
expect(fixture.componentInstance.combo.value1 instanceof Array && fixture.componentInstance.combo.value1.length === 0).toBeTruthy();
done();
}, 10);
}, 10);
});
});

it('the ngModel should be updated correctly if the combo selection is updated', (done) => {
var template = '<div><ig-combo [(widgetId)]="comboID" [(options)]="options" [changeDetectionInterval]="cdi" [(ngModel)]="combo.value1" [dataSource]="northwind"></ig-combo></div>';
var template = '<div><ig-combo [(widgetId)]="comboID" [(options)]="options" [(ngModel)]="combo.value1" [dataSource]="northwind"></ig-combo></div>';
TestBed.overrideComponent(TestComponent, {
set: {
template: template
Expand All @@ -137,7 +161,7 @@ export function main() {
});

it('the ngModel should be updated correctly if the combo selection is updated and multiple items are selected', (done) => {
var template = '<div><ig-combo [(widgetId)]="comboID" [dataSource]="northwind" [(options)]="optionsMultipleSelection" [changeDetectionInterval]="cdi" [(ngModel)]="combo.value1"></ig-combo></div>';
var template = '<div><ig-combo [(widgetId)]="comboID" [dataSource]="northwind" [(options)]="optionsMultipleSelection" [(ngModel)]="combo.value1"></ig-combo></div>';
TestBed.overrideComponent(TestComponent, {
set: {
template: template
Expand All @@ -159,7 +183,7 @@ export function main() {
});

it('should reflect changes when a record in the data changes', (done) => {
var template = '<div><ig-combo [(widgetId)]="comboID" [dataSource]="northwind" [(options)]="options" [changeDetectionInterval]="cdi" [(ngModel)]="combo.value1"></ig-combo></div>';
var template = '<div><ig-combo [(widgetId)]="comboID" [dataSource]="northwind" [(options)]="options" [(ngModel)]="combo.value1"></ig-combo></div>';
TestBed.overrideComponent(TestComponent, {
set: {
template: template
Expand All @@ -182,7 +206,7 @@ export function main() {
});

it('should apply the model if there is a new data assigned', (done) => {
var template = '<div><ig-combo [(widgetId)]="comboID" [valueKey]="\'ProductID\'" [textKey]="\'ProductName\'" [changeDetectionInterval]="cdi" [dataSource]="data" [(ngModel)]="combo.value1"></ig-combo></div>';
var template = '<div><ig-combo [(widgetId)]="comboID" [valueKey]="\'ProductID\'" [textKey]="\'ProductName\'" [dataSource]="data" [(ngModel)]="combo.value1"></ig-combo></div>';
TestBed.overrideComponent(TestComponent, {
set: {
template: template
Expand All @@ -209,7 +233,7 @@ export function main() {
dataType: 'json',
responseText: '[{"ProductID": 1, "ProductName": "Chai"}]'
});
var template = '<div><ig-combo [(widgetId)]="comboID" [(options)]="options2" [changeDetectionInterval]="cdi" [(ngModel)]="combo.value1"></ig-combo></div>';
var template = '<div><ig-combo [(widgetId)]="comboID" [(options)]="options2" [(ngModel)]="combo.value1"></ig-combo></div>';
TestBed.overrideComponent(TestComponent, {
set: {
template: template
Expand Down Expand Up @@ -237,7 +261,6 @@ class TestComponent {
public northwind: any;
public combo: any;
private comboID: string
private cdi = 10;
public data: Array<any> = [];
@ViewChild(Infragistics.IgComboComponent) public viewChild: Infragistics.IgComboComponent;

Expand Down

0 comments on commit 3eef34d

Please sign in to comment.