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

Commit d73f179

Browse files
committed
test(event): parameters for onSelect callback
1 parent 2ad31d8 commit d73f179

File tree

1 file changed

+45
-20
lines changed

1 file changed

+45
-20
lines changed

test/select.spec.js

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -460,29 +460,54 @@ describe('ui-select tests', function() {
460460

461461
it('should invoke select callback on select', function () {
462462

463-
scope.onSelectFn = function ($item, $model, $label) {
464-
scope.$item = $item;
465-
scope.$model = $model;
466-
};
467-
var el = compileTemplate(
468-
'<ui-select on-select="onSelectFn($item, $model)" ng-model="selection.selected"> \
469-
<ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
470-
<ui-select-choices repeat="person.name as person in people | filter: $select.search"> \
471-
<div ng-bind-html="person.name | highlight: $select.search"></div> \
472-
<div ng-bind-html="person.email | highlight: $select.search"></div> \
473-
</ui-select-choices> \
474-
</ui-select>'
475-
);
463+
scope.onSelectFn = function ($item, $model, $label) {
464+
scope.$item = $item;
465+
scope.$model = $model;
466+
};
467+
var el = compileTemplate(
468+
'<ui-select on-select="onSelectFn($item, $model)" ng-model="selection.selected"> \
469+
<ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
470+
<ui-select-choices repeat="person.name as person in people | filter: $select.search"> \
471+
<div ng-bind-html="person.name | highlight: $select.search"></div> \
472+
<div ng-bind-html="person.email | highlight: $select.search"></div> \
473+
</ui-select-choices> \
474+
</ui-select>'
475+
);
476+
477+
expect(scope.$item).toBeFalsy();
478+
expect(scope.$model).toBeFalsy();
476479

477-
expect(scope.$item).toBeFalsy();
478-
expect(scope.$model).toBeFalsy();
480+
clickItem(el, 'Samantha');
481+
expect(scope.selection.selected).toBe('Samantha');
479482

480-
clickItem(el, 'Samantha');
481-
expect(scope.selection.selected).toBe('Samantha');
483+
expect(scope.$item).toEqual(scope.people[5]);
484+
expect(scope.$model).toEqual('Samantha');
482485

483-
expect(scope.$item).toEqual(scope.people[5]);
484-
expect(scope.$model).toEqual('Samantha');
486+
});
485487

486-
});
488+
it('should set $item & $model correctly when invoking callback on select and no single prop. binding', function () {
489+
490+
scope.onSelectFn = function ($item, $model, $label) {
491+
scope.$item = $item;
492+
scope.$model = $model;
493+
};
494+
495+
var el = compileTemplate(
496+
'<ui-select on-select="onSelectFn($item, $model)" ng-model="selection.selected"> \
497+
<ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
498+
<ui-select-choices repeat="person in people | filter: $select.search"> \
499+
<div ng-bind-html="person.name | highlight: $select.search"></div> \
500+
<div ng-bind-html="person.email | highlight: $select.search"></div> \
501+
</ui-select-choices> \
502+
</ui-select>'
503+
);
504+
505+
expect(scope.$item).toBeFalsy();
506+
expect(scope.$model).toBeFalsy();
507+
508+
clickItem(el, 'Samantha');
509+
expect(scope.$item).toEqual(scope.$model);
510+
511+
});
487512

488513
});

0 commit comments

Comments
 (0)