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

Commit 13808f1

Browse files
SimeonSimeon
Simeon
authored and
Simeon
committed
Add tests for #107
1 parent d17889c commit 13808f1

File tree

2 files changed

+49
-10
lines changed

2 files changed

+49
-10
lines changed

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,9 @@
2929
"karma-ng-html2js-preprocessor": "^0.1.0",
3030
"karma-phantomjs-launcher": "~0.1.4"
3131
},
32+
"scripts": {
33+
"postinstall": "bower install",
34+
"test": "gulp test"
35+
},
3236
"license": "MIT"
3337
}

test/select.spec.js

Lines changed: 45 additions & 10 deletions
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-
11+
scope.selection = {}
1212
scope.getGroupLabel = function(person) {
1313
return person.age % 2 ? 'even' : 'odd';
1414
};
@@ -42,7 +42,7 @@ describe('ui-select tests', function() {
4242
}
4343

4444
return compileTemplate(
45-
'<ui-select ng-model="selection"' + attrsHtml + '> \
45+
'<ui-select ng-model="selection.selected"' + attrsHtml + '> \
4646
<ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
4747
<ui-select-choices repeat="person in people | filter: $select.search"> \
4848
<div ng-bind-html="person.name | highlight: $select.search"></div> \
@@ -102,7 +102,7 @@ describe('ui-select tests', function() {
102102
});
103103

104104
it('should correctly render initial state', function() {
105-
scope.selection = scope.people[0];
105+
scope.selection.selected = scope.people[0];
106106

107107
var el = createUiSelect();
108108

@@ -178,7 +178,7 @@ describe('ui-select tests', function() {
178178
scope.items = ['false'];
179179

180180
var el = compileTemplate(
181-
'<ui-select ng-model="selection"> \
181+
'<ui-select ng-model="selection.selected"> \
182182
<ui-select-match>{{$select.selected}}</ui-select-match> \
183183
<ui-select-choices repeat="item in items | filter: $select.search"> \
184184
<div ng-bind-html="item | highlight: $select.search"></div> \
@@ -199,7 +199,7 @@ describe('ui-select tests', function() {
199199
}
200200
function createUiSelect() {
201201
return compileTemplate(
202-
'<ui-select ng-model="selection"> \
202+
'<ui-select ng-model="selection.selected"> \
203203
<ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
204204
<ui-select-choices group-by="\'group\'" repeat="person in people | filter: $select.search"> \
205205
<div ng-bind-html="person.name | highlight: $select.search"></div> \
@@ -249,7 +249,7 @@ describe('ui-select tests', function() {
249249
describe('choices group by function', function() {
250250
function createUiSelect() {
251251
return compileTemplate(
252-
'<ui-select ng-model="selection"> \
252+
'<ui-select ng-model="selection.selected"> \
253253
<ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
254254
<ui-select-choices group-by="getGroupLabel" repeat="person in people | filter: $select.search"> \
255255
<div ng-bind-html="person.name | highlight: $select.search"></div> \
@@ -268,7 +268,7 @@ describe('ui-select tests', function() {
268268
it('should throw when no ui-select-choices found', function() {
269269
expect(function() {
270270
compileTemplate(
271-
'<ui-select ng-model="selection"> \
271+
'<ui-select ng-model="selection.selected"> \
272272
<ui-select-match></ui-select-match> \
273273
</ui-select>'
274274
);
@@ -278,7 +278,7 @@ describe('ui-select tests', function() {
278278
it('should throw when no repeat attribute is provided to ui-select-choices', function() {
279279
expect(function() {
280280
compileTemplate(
281-
'<ui-select ng-model="selection"> \
281+
'<ui-select ng-model="selection.selected"> \
282282
<ui-select-choices></ui-select-choices> \
283283
</ui-select>'
284284
);
@@ -288,9 +288,44 @@ describe('ui-select tests', function() {
288288
it('should throw when no ui-select-match found', function() {
289289
expect(function() {
290290
compileTemplate(
291-
'<ui-select ng-model="selection"> \
291+
'<ui-select ng-model="selection.selected"> \
292292
<ui-select-choices repeat="item in items"></ui-select-choices> \
293293
</ui-select>'
294294
);
295295
}).toThrow(new Error('[ui.select:transcluded] Expected 1 .ui-select-match but got \'0\'.'));
296-
});});
296+
});
297+
298+
it('should parse and format the model correctly using alias', function() {
299+
var el = compileTemplate(
300+
'<ui-select ng-model="selection.selected"> \
301+
<ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
302+
<ui-select-choices repeat="person as person in people | filter: $select.search"> \
303+
<div ng-bind-html="person.name | highlight: $select.search"></div> \
304+
<div ng-bind-html="person.email | highlight: $select.search"></div> \
305+
</ui-select-choices> \
306+
</ui-select>'
307+
);
308+
clickItem(el, 'Samantha');
309+
expect(scope.selection.selected).toBe(scope.people[5]);
310+
});
311+
312+
it('should parse and format the model correctly using property of alias', function() {
313+
var el = compileTemplate(
314+
'<ui-select ng-model="selection.selected"> \
315+
<ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
316+
<ui-select-choices repeat="person.name as person in people | filter: $select.search"> \
317+
<div ng-bind-html="person.name | highlight: $select.search"></div> \
318+
<div ng-bind-html="person.email | highlight: $select.search"></div> \
319+
</ui-select-choices> \
320+
</ui-select>'
321+
);
322+
clickItem(el, 'Samantha');
323+
expect(scope.selection.selected).toBe('Samantha');
324+
});
325+
326+
it('should parse and format the model correctly without alias', function() {
327+
var el = createUiSelect();
328+
clickItem(el, 'Samantha');
329+
expect(scope.selection.selected).toBe(scope.people[5]);
330+
});
331+
});

0 commit comments

Comments
 (0)