Skip to content

Commit

Permalink
fix: label formatting (ng-select#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
varnastadeus authored Mar 8, 2018
1 parent 463773f commit 05572a1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
4 changes: 2 additions & 2 deletions ng-select/items-list.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NgOption } from './ng-select.types';
import * as searchHelper from './search-helper';
import { NgSelectComponent } from './ng-select.component';
import { isObject } from './utils';
import { isObject, isDefined } from './utils';

export class ItemsList {

Expand Down Expand Up @@ -180,7 +180,7 @@ export class ItemsList {
const label = this.resolveNested(item, this._ngSelect.bindLabel);
return {
index: index,
label: label || '',
label: isDefined(label) ? label.toString() : '',
value: item,
disabled: item.disabled,
};
Expand Down
23 changes: 20 additions & 3 deletions ng-select/ng-select.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@ import { MockNgZone, MockNgWindow } from '../testing/mocks';

describe('NgSelectComponent', function () {

describe('init', () => {
it('should map items correctly', fakeAsync(() => {
const fixture = createTestingModule(
NgSelectSelectedSimpleCmp,
`<ng-select [searchable]="false"
[clearable]="false"
[items]="[0, 30, 60, 90, 120, 180, 240]"
[(ngModel)]="selectedCity">
</ng-select>`);

fixture.componentInstance.selectedCity = 0;
tickAndDetectChanges(fixture);
expect(fixture.componentInstance.selectedCity).toEqual(0);
expect(fixture.componentInstance.select.itemsList.items[0].label).toEqual('0');
}));
});

describe('Model bindings', () => {
it('should update ngModel on value change', fakeAsync(() => {
const fixture = createTestingModule(
Expand Down Expand Up @@ -560,7 +577,7 @@ describe('NgSelectComponent', function () {
tickAndDetectChanges(fixture);
const selected = fixture.componentInstance.select.selectedItems[0];
expect(selected.label).toEqual('');
expect(selected.value).toEqual({name: null, id: 2});
expect(selected.value).toEqual({ name: null, id: 2 });
}));
});

Expand Down Expand Up @@ -616,7 +633,7 @@ describe('NgSelectComponent', function () {
bindLabel="name"
[(ngModel)]="city">
</ng-select>`);

const select = fixture.componentInstance.select;
select.open();

Expand All @@ -642,7 +659,7 @@ describe('NgSelectComponent', function () {
[virtualScroll]="true"
[(ngModel)]="city">
</ng-select>`);

const select = fixture.componentInstance.select;
select.open();

Expand Down

0 comments on commit 05572a1

Please sign in to comment.