Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit 9290cc9

Browse files
committed
test(choices): should work correctly with child array as choices
1 parent 7c49685 commit 9290cc9

File tree

1 file changed

+48
-5
lines changed

1 file changed

+48
-5
lines changed

test/select.spec.js

+48-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe('ui-select tests', function() {
88
$rootScope = _$rootScope_;
99
scope = $rootScope.$new();
1010
$compile = _$compile_;
11-
scope.selection = {}
11+
scope.selection = {}
1212
scope.getGroupLabel = function(person) {
1313
return person.age % 2 ? 'even' : 'odd';
1414
};
@@ -23,6 +23,18 @@ describe('ui-select tests', function() {
2323
{ name: 'Nicole', email: '[email protected]', group: 'bar', age: 43 },
2424
{ name: 'Natasha', email: '[email protected]', group: 'Baz', age: 54 }
2525
];
26+
27+
scope.someObject = {};
28+
scope.someObject.people = [
29+
{ name: 'Adam', email: '[email protected]', group: 'Foo', age: 12 },
30+
{ name: 'Amalie', email: '[email protected]', group: 'Foo', age: 12 },
31+
{ name: 'Estefanía', email: 'estefaní[email protected]', group: 'Foo', age: 21 },
32+
{ name: 'Adrian', email: '[email protected]', group: 'Foo', age: 21 },
33+
{ name: 'Wladimir', email: '[email protected]', group: 'Foo', age: 30 },
34+
{ name: 'Samantha', email: '[email protected]', group: 'bar', age: 30 },
35+
{ name: 'Nicole', email: '[email protected]', group: 'bar', age: 43 },
36+
{ name: 'Natasha', email: '[email protected]', group: 'Baz', age: 54 }
37+
];
2638
}));
2739

2840

@@ -305,7 +317,7 @@ describe('ui-select tests', function() {
305317
);
306318
}).toThrow(new Error('[ui.select:transcluded] Expected 1 .ui-select-match but got \'0\'.'));
307319
});
308-
320+
309321
it('should format the model correctly using alias', function() {
310322
var el = compileTemplate(
311323
'<ui-select ng-model="selection.selected"> \
@@ -317,7 +329,7 @@ describe('ui-select tests', function() {
317329
</ui-select>'
318330
);
319331
clickItem(el, 'Samantha');
320-
expect(scope.selection.selected).toBe(scope.people[5]);
332+
expect(scope.selection.selected).toBe(scope.people[5]);
321333
});
322334

323335
it('should parse the model correctly using alias', function() {
@@ -346,7 +358,7 @@ describe('ui-select tests', function() {
346358
</ui-select>'
347359
);
348360
clickItem(el, 'Samantha');
349-
expect(scope.selection.selected).toBe('Samantha');
361+
expect(scope.selection.selected).toBe('Samantha');
350362
});
351363

352364
it('should parse the model correctly using property of alias', function() {
@@ -364,6 +376,7 @@ describe('ui-select tests', function() {
364376
expect(getMatchLabel(el)).toEqual('Samantha');
365377
});
366378

379+
//TODO Is this really something we should expect?
367380
it('should parse the model correctly using property of alias but passed whole object', function() {
368381
var el = compileTemplate(
369382
'<ui-select ng-model="selection.selected"> \
@@ -382,7 +395,7 @@ describe('ui-select tests', function() {
382395
it('should format the model correctly without alias', function() {
383396
var el = createUiSelect();
384397
clickItem(el, 'Samantha');
385-
expect(scope.selection.selected).toBe(scope.people[5]);
398+
expect(scope.selection.selected).toBe(scope.people[5]);
386399
});
387400

388401
it('should parse the model correctly without alias', function() {
@@ -391,4 +404,34 @@ describe('ui-select tests', function() {
391404
scope.$digest();
392405
expect(getMatchLabel(el)).toEqual('Samantha');
393406
});
407+
408+
it('should display choices correctly with child array', function() {
409+
var el = compileTemplate(
410+
'<ui-select ng-model="selection.selected"> \
411+
<ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
412+
<ui-select-choices repeat="person in someObject.people | filter: $select.search"> \
413+
<div ng-bind-html="person.name | highlight: $select.search"></div> \
414+
<div ng-bind-html="person.email | highlight: $select.search"></div> \
415+
</ui-select-choices> \
416+
</ui-select>'
417+
);
418+
scope.selection.selected = scope.people[5];
419+
scope.$digest();
420+
expect(getMatchLabel(el)).toEqual('Samantha');
421+
});
422+
423+
it('should format the model correctly using property of alias and when using child array for choices', function() {
424+
var el = compileTemplate(
425+
'<ui-select ng-model="selection.selected"> \
426+
<ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
427+
<ui-select-choices repeat="person.name as person in someObject.people | filter: $select.search"> \
428+
<div ng-bind-html="person.name | highlight: $select.search"></div> \
429+
<div ng-bind-html="person.email | highlight: $select.search"></div> \
430+
</ui-select-choices> \
431+
</ui-select>'
432+
);
433+
clickItem(el, 'Samantha');
434+
expect(scope.selection.selected).toBe('Samantha');
435+
});
436+
394437
});

0 commit comments

Comments
 (0)