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

Commit c2183c2

Browse files
committed
Merge pull request #108 from SimeonC/feat-modelmapper
Add tests for #107
2 parents d17889c + 82d6aec commit c2183c2

File tree

2 files changed

+101
-10
lines changed

2 files changed

+101
-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: 97 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,96 @@ 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 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 the model correctly using 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 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+
scope.selection.selected = scope.people[5];
323+
scope.$digest();
324+
expect(getMatchLabel(el)).toEqual('Samantha');
325+
});
326+
327+
it('should format the model correctly using property of alias', function() {
328+
var el = compileTemplate(
329+
'<ui-select ng-model="selection.selected"> \
330+
<ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
331+
<ui-select-choices repeat="person.name as person in people | filter: $select.search"> \
332+
<div ng-bind-html="person.name | highlight: $select.search"></div> \
333+
<div ng-bind-html="person.email | highlight: $select.search"></div> \
334+
</ui-select-choices> \
335+
</ui-select>'
336+
);
337+
clickItem(el, 'Samantha');
338+
expect(scope.selection.selected).toBe('Samantha');
339+
});
340+
341+
it('should parse the model correctly using property of alias', function() {
342+
var el = compileTemplate(
343+
'<ui-select ng-model="selection.selected"> \
344+
<ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
345+
<ui-select-choices repeat="person.name as person in people | filter: $select.search"> \
346+
<div ng-bind-html="person.name | highlight: $select.search"></div> \
347+
<div ng-bind-html="person.email | highlight: $select.search"></div> \
348+
</ui-select-choices> \
349+
</ui-select>'
350+
);
351+
scope.selection.selected = 'Samantha';
352+
scope.$digest();
353+
expect(getMatchLabel(el)).toEqual('Samantha');
354+
});
355+
356+
it('should parse the model correctly using property of alias but passed whole object', function() {
357+
var el = compileTemplate(
358+
'<ui-select ng-model="selection.selected"> \
359+
<ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
360+
<ui-select-choices repeat="person.name as person in people | filter: $select.search"> \
361+
<div ng-bind-html="person.name | highlight: $select.search"></div> \
362+
<div ng-bind-html="person.email | highlight: $select.search"></div> \
363+
</ui-select-choices> \
364+
</ui-select>'
365+
);
366+
scope.selection.selected = scope.people[5];
367+
scope.$digest();
368+
expect(getMatchLabel(el)).toEqual('Samantha');
369+
});
370+
371+
it('should format the model correctly without alias', function() {
372+
var el = createUiSelect();
373+
clickItem(el, 'Samantha');
374+
expect(scope.selection.selected).toBe(scope.people[5]);
375+
});
376+
377+
it('should parse the model correctly without alias', function() {
378+
var el = createUiSelect();
379+
scope.selection.selected = scope.people[5];
380+
scope.$digest();
381+
expect(getMatchLabel(el)).toEqual('Samantha');
382+
});
383+
});

0 commit comments

Comments
 (0)