@@ -15,34 +15,72 @@ describe('selectpicker', function() {
15
15
} ) ;
16
16
17
17
it ( 'should set to selectpicker element value the scope value' , function ( ) {
18
- return inject ( function ( $compile , $rootScope , $timeout ) {
18
+ return inject ( function ( $compile , $rootScope ) {
19
19
var scope = $rootScope . $new ( ) ;
20
20
var html = '<select selectpicker ng-model="selected" class="">' +
21
21
'<option>Mustard</option>' +
22
22
'<option>Ketchup</option>' +
23
23
'<option>Relish</option>' +
24
24
'</select>' ;
25
25
var element = $compile ( html ) ( scope ) ;
26
+ scope . $digest ( ) ;
26
27
scope . $apply ( function ( ) {
27
28
scope . selected = 'Ketchup' ;
28
29
} ) ;
29
- $timeout . flush ( ) ;
30
30
expect ( element . val ( ) ) . toEqual ( 'Ketchup' ) ;
31
31
} ) ;
32
32
} ) ;
33
33
34
- it ( 'should set selectpicker select element options with ng-options ' , function ( ) {
35
- return inject ( function ( $compile , $rootScope , $timeout ) {
34
+ it ( 'should set selectpicker selected option element, changing the model value ' , function ( ) {
35
+ return inject ( function ( $compile , $rootScope ) {
36
36
var scope = $rootScope . $new ( ) ;
37
- scope . colors = [ { name : 'Red' } , { name : 'Green' } , { name : 'Blue' } ] ;
38
- var html = '<select selectpicker ng-model="selected" ng-options="color .name for color in colors"></select>' ;
37
+ scope . colors = [ { id : 10 , name : 'Red' } , { id : 20 , name : 'Green' } , { id : 30 , name : 'Blue' } ] ;
38
+ var html = '<select selectpicker ng-model="selected" ng-options="c .name as c.name for c in colors"></select>' ;
39
39
var element = $compile ( html ) ( scope ) ;
40
+ scope . $digest ( ) ;
40
41
scope . $apply ( function ( ) {
41
- scope . selected = 1 ;
42
+ scope . selected = 'Green' ;
42
43
} ) ;
43
- $timeout . flush ( ) ;
44
44
expect ( element . val ( ) ) . toEqual ( '1' ) ;
45
45
} ) ;
46
46
} ) ;
47
+
48
+ it ( 'should set selectpicker selected option element, changing the model value with options tracked by name' , function ( ) {
49
+ return inject ( function ( $compile , $rootScope ) {
50
+ var scope = $rootScope . $new ( ) ;
51
+ scope . colors = [ { id : 10 , name : 'Red' } , { id : 20 , name : 'Green' } , { id : 30 , name : 'Blue' } ] ;
52
+ var html = '<select selectpicker ng-model="selected" ng-options="c.name as c.name for c in colors track by c.name"></select>' ;
53
+ var element = $compile ( html ) ( scope ) ;
54
+ scope . $digest ( ) ;
55
+ scope . $apply ( function ( ) {
56
+ scope . selected = 'Green' ;
57
+ } ) ;
58
+ expect ( element . val ( ) ) . toEqual ( 'Green' ) ;
59
+ } ) ;
60
+ } ) ;
61
+
62
+ it ( 'should set model value, changing selectpicker selected element tracked by id' , function ( ) {
63
+ return inject ( function ( $compile , $rootScope ) {
64
+ var scope = $rootScope . $new ( ) ;
65
+ scope . colors = [ { id : 10 , name : 'Red' } , { id : 20 , name : 'Green' } , { id : 30 , name : 'Blue' } ] ;
66
+ var html = '<select selectpicker ng-model="selected" ng-options="c.name as c.name for c in colors track by c.id"></select>' ;
67
+ var element = $compile ( html ) ( scope ) ;
68
+ scope . $digest ( ) ;
69
+ element . selectpicker ( 'val' , '20' ) ;
70
+ expect ( scope . selected ) . toEqual ( 'Green' ) ;
71
+ } ) ;
72
+ } ) ;
73
+
74
+ it ( 'should set model value, changing selectpicker selected element tracked by name' , function ( ) {
75
+ return inject ( function ( $compile , $rootScope ) {
76
+ var scope = $rootScope . $new ( ) ;
77
+ scope . colors = [ { id : 10 , name : 'Red' } , { id : 20 , name : 'Green' } , { id : 30 , name : 'Blue' } ] ;
78
+ var html = '<select selectpicker ng-model="selected" ng-options="c.name as c.name for c in colors track by c.name"></select>' ;
79
+ var element = $compile ( html ) ( scope ) ;
80
+ scope . $digest ( ) ;
81
+ element . selectpicker ( 'val' , 'Green' ) ;
82
+ expect ( scope . selected ) . toEqual ( 'Green' ) ;
83
+ } ) ;
84
+ } ) ;
47
85
48
86
} ) ;
0 commit comments