@@ -4,9 +4,10 @@ describe('pf-select', function () {
4
4
5
5
beforeEach ( module ( 'patternfly.select' ) ) ;
6
6
7
- beforeEach ( inject ( function ( _$rootScope_ , _$compile_ ) {
7
+ beforeEach ( inject ( function ( _$rootScope_ , _$compile_ , _$timeout_ ) {
8
8
$scope = _$rootScope_ ;
9
9
$compile = _$compile_ ;
10
+ $timeout = _$timeout_ ;
10
11
} ) ) ;
11
12
12
13
describe ( 'Page with pf-select directive' , function ( ) {
@@ -24,8 +25,19 @@ describe('pf-select', function () {
24
25
25
26
var select = compileSelect ( '<select pf-select ng-model="modelValue" ng-options="o as o for o in options"></select>' , $scope ) ;
26
27
28
+ $timeout . flush ( ) ;
29
+
27
30
expect ( select . text ( ) ) . toBe ( 'abc' ) ;
28
31
expect ( select ) . toEqualSelect ( [ 'a' , [ 'b' ] , 'c' ] ) ;
32
+
33
+ var bsSelect = angular . element ( select ) . siblings ( '.bootstrap-select' ) ;
34
+ var bsSelItems = bsSelect . find ( 'li' ) ;
35
+ expect ( bsSelItems . length ) . toBe ( $scope . options . length ) ;
36
+ expect ( bsSelItems . text ( ) ) . toBe ( 'abc' ) ;
37
+
38
+ var bsSelected = bsSelect . find ( 'li.selected' ) ;
39
+ expect ( bsSelected . length ) . toBe ( 1 ) ;
40
+ expect ( bsSelected . text ( ) ) . toBe ( 'b' ) ;
29
41
} ) ;
30
42
31
43
it ( 'should respond to changes in ng-options' , function ( ) {
@@ -37,12 +49,24 @@ describe('pf-select', function () {
37
49
expect ( select . text ( ) ) . toBe ( 'abc' ) ;
38
50
expect ( select ) . toEqualSelect ( [ [ 'a' ] , 'b' , 'c' ] ) ;
39
51
52
+ var bsSelect = angular . element ( select ) . siblings ( '.bootstrap-select' ) ;
53
+ var bsSelItems = bsSelect . find ( 'li' ) ;
54
+ expect ( bsSelItems . length ) . toBe ( $scope . options . length ) ;
55
+ expect ( bsSelItems . text ( ) ) . toBe ( 'abc' ) ;
56
+
40
57
$scope . $apply ( function ( ) {
41
58
$scope . options . push ( 'd' ) ;
42
59
} ) ;
43
60
61
+ $timeout . flush ( ) ;
62
+
44
63
expect ( select . text ( ) ) . toBe ( 'abcd' ) ;
45
64
expect ( select ) . toEqualSelect ( [ [ 'a' ] , 'b' , 'c' , 'd' ] ) ;
65
+
66
+ bsSelect = angular . element ( select ) . siblings ( '.bootstrap-select' ) ;
67
+ bsSelItems = bsSelect . find ( 'li' ) ;
68
+ expect ( bsSelItems . length ) . toBe ( $scope . options . length ) ;
69
+ expect ( bsSelItems . text ( ) ) . toBe ( 'abcd' ) ;
46
70
} ) ;
47
71
48
72
it ( 'should respond to ng-model changes' , function ( ) {
@@ -54,19 +78,40 @@ describe('pf-select', function () {
54
78
expect ( select . text ( ) ) . toBe ( 'abc' ) ;
55
79
expect ( select ) . toEqualSelect ( [ [ 'a' ] , 'b' , 'c' ] ) ;
56
80
81
+ var bsSelect = angular . element ( select ) . siblings ( '.bootstrap-select' ) ;
82
+ var bsSelItems = bsSelect . find ( 'li' ) ;
83
+ expect ( bsSelItems . length ) . toBe ( $scope . options . length ) ;
84
+ expect ( bsSelItems . text ( ) ) . toBe ( 'abc' ) ;
85
+
86
+ var bsSelected = bsSelect . find ( 'li.selected' ) ;
87
+ expect ( bsSelected . length ) . toBe ( 1 ) ;
88
+ expect ( bsSelected . text ( ) ) . toBe ( 'a' ) ;
89
+
57
90
$scope . $apply ( function ( ) {
58
91
$scope . modelValue = $scope . options [ 1 ] ;
59
92
} ) ;
60
93
94
+ $timeout . flush ( ) ;
95
+
61
96
expect ( select . text ( ) ) . toBe ( 'abc' ) ;
62
97
expect ( select ) . toEqualSelect ( [ 'a' , [ 'b' ] , 'c' ] ) ;
63
98
99
+ bsSelected = bsSelect . find ( 'li.selected' ) ;
100
+ expect ( bsSelected . length ) . toBe ( 1 ) ;
101
+ expect ( bsSelected . text ( ) ) . toBe ( 'b' ) ;
102
+
64
103
$scope . $apply ( function ( ) {
65
104
$scope . modelValue = $scope . options [ 2 ] ;
66
105
} ) ;
67
106
107
+ $timeout . flush ( ) ;
108
+
68
109
expect ( select . text ( ) ) . toBe ( 'abc' ) ;
69
110
expect ( select ) . toEqualSelect ( [ 'a' , 'b' , [ 'c' ] ] ) ;
111
+
112
+ bsSelected = bsSelect . find ( 'li.selected' ) ;
113
+ expect ( bsSelected . length ) . toBe ( 1 ) ;
114
+ expect ( bsSelected . text ( ) ) . toBe ( 'c' ) ;
70
115
} ) ;
71
116
72
117
} ) ;
0 commit comments