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

Commit

Permalink
Add test for null/undefined values
Browse files Browse the repository at this point in the history
  • Loading branch information
homerjam committed Mar 29, 2016
1 parent b787159 commit 7800e65
Showing 1 changed file with 54 additions and 16 deletions.
70 changes: 54 additions & 16 deletions test/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1610,42 +1610,42 @@ describe('ui-select tests', function() {
expect(el.find('.ui-select-match-item').length).toBe(0);
});

it('should render intial state with data-multiple attribute', function () {
// ensure match template has been loaded by having more than one selection
scope.selection.selectedMultiple = [scope.people[0], scope.people[1]];

it('should render intial state with data-multiple attribute', function () {
// ensure match template has been loaded by having more than one selection
scope.selection.selectedMultiple = [scope.people[0], scope.people[1]];

var el = compileTemplate(
'<ui-select data-multiple ng-model="selection.selectedMultiple" theme="bootstrap" style="width: 800px;"> \
<ui-select-match placeholder="Pick one...">{{$item.name}} &lt;{{$item.email}}&gt;</ui-select-match> \
<ui-select-choices repeat="person in people | filter: $select.search"> \
<div ng-bind-html="person.name | highlight: $select.search"></div> \
<div ng-bind-html="person.email | highlight: $select.search"></div> \
</ui-select-choices> \
</ui-select>'
);

</ui-select>'
);

expect(el).toHaveClass('ui-select-multiple');
expect(el.scope().$select.selected.length).toBe(2);
expect(el.find('.ui-select-match-item').length).toBe(2);
expect(el.find('.ui-select-match-item').length).toBe(2);
});

it('should render intial state with x-multiple attribute', function () {
// ensure match template has been loaded by having more than one selection
scope.selection.selectedMultiple = [scope.people[0], scope.people[1]];

it('should render intial state with x-multiple attribute', function () {
// ensure match template has been loaded by having more than one selection
scope.selection.selectedMultiple = [scope.people[0], scope.people[1]];

var el = compileTemplate(
'<ui-select x-multiple ng-model="selection.selectedMultiple" theme="bootstrap" style="width: 800px;"> \
<ui-select-match placeholder="Pick one...">{{$item.name}} &lt;{{$item.email}}&gt;</ui-select-match> \
<ui-select-choices repeat="person in people | filter: $select.search"> \
<div ng-bind-html="person.name | highlight: $select.search"></div> \
<div ng-bind-html="person.email | highlight: $select.search"></div> \
</ui-select-choices> \
</ui-select>'
);

</ui-select>'
);

expect(el).toHaveClass('ui-select-multiple');
expect(el.scope().$select.selected.length).toBe(2);
expect(el.find('.ui-select-match-item').length).toBe(2);
expect(el.find('.ui-select-match-item').length).toBe(2);
});

it('should set model as an empty array if ngModel isnt defined after an item is selected', function () {
Expand Down Expand Up @@ -2206,6 +2206,44 @@ describe('ui-select tests', function() {
expect(el.scope().$select.multiple).toBe(true);
});

it('should have tolerance for undefined values', function () {

scope.modelValue = undefined;

var el = compileTemplate(
'<ui-select multiple ng-model="modelValue" theme="bootstrap" style="width: 800px;"> \
<ui-select-match placeholder="Pick one...">{{$item.name}} &lt;{{$item.email}}&gt;</ui-select-match> \
<ui-select-choices repeat="person.email as person in people | filter: $select.search"> \
<div ng-bind-html="person.name | highlight: $select.search"></div> \
<div ng-bind-html="person.email | highlight: $select.search"></div> \
</ui-select-choices> \
</ui-select> \
'
);

expect($(el).scope().$select.selected).toEqual([]);

});

it('should have tolerance for null values', function () {

scope.modelValue = null;

var el = compileTemplate(
'<ui-select multiple ng-model="modelValue" theme="bootstrap" style="width: 800px;"> \
<ui-select-match placeholder="Pick one...">{{$item.name}} &lt;{{$item.email}}&gt;</ui-select-match> \
<ui-select-choices repeat="person.email as person in people | filter: $select.search"> \
<div ng-bind-html="person.name | highlight: $select.search"></div> \
<div ng-bind-html="person.email | highlight: $select.search"></div> \
</ui-select-choices> \
</ui-select> \
'
);

expect($(el).scope().$select.selected).toEqual([]);

});

it('should allow paste tag from clipboard', function() {
scope.taggingFunc = function (name) {
return {
Expand Down

0 comments on commit 7800e65

Please # to comment.