Skip to content

Commit 7271e2f

Browse files
committed
PTNFLY-1122 : Additional tests for pfSelect directive
Tests for the bootstrap select generated <div> element to be in sync with ng-options and ng-model (along with the <select> element)
1 parent b501175 commit 7271e2f

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

test/select/select.spec.js

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ describe('pf-select', function () {
44

55
beforeEach(module('patternfly.select'));
66

7-
beforeEach(inject(function (_$rootScope_, _$compile_) {
7+
beforeEach(inject(function (_$rootScope_, _$compile_, _$timeout_) {
88
$scope = _$rootScope_;
99
$compile = _$compile_;
10+
$timeout = _$timeout_;
1011
}));
1112

1213
describe('Page with pf-select directive', function () {
@@ -24,8 +25,19 @@ describe('pf-select', function () {
2425

2526
var select = compileSelect('<select pf-select ng-model="modelValue" ng-options="o as o for o in options"></select>', $scope);
2627

28+
$timeout.flush();
29+
2730
expect(select.text()).toBe('abc');
2831
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');
2941
});
3042

3143
it('should respond to changes in ng-options', function () {
@@ -37,12 +49,24 @@ describe('pf-select', function () {
3749
expect(select.text()).toBe('abc');
3850
expect(select).toEqualSelect([['a'], 'b', 'c']);
3951

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+
4057
$scope.$apply(function() {
4158
$scope.options.push('d');
4259
});
4360

61+
$timeout.flush();
62+
4463
expect(select.text()).toBe('abcd');
4564
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');
4670
});
4771

4872
it('should respond to ng-model changes', function () {
@@ -54,19 +78,40 @@ describe('pf-select', function () {
5478
expect(select.text()).toBe('abc');
5579
expect(select).toEqualSelect([['a'], 'b', 'c']);
5680

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+
5790
$scope.$apply(function() {
5891
$scope.modelValue = $scope.options[1];
5992
});
6093

94+
$timeout.flush();
95+
6196
expect(select.text()).toBe('abc');
6297
expect(select).toEqualSelect(['a', ['b'], 'c']);
6398

99+
bsSelected = bsSelect.find('li.selected');
100+
expect(bsSelected.length).toBe(1);
101+
expect(bsSelected.text()).toBe('b');
102+
64103
$scope.$apply(function() {
65104
$scope.modelValue = $scope.options[2];
66105
});
67106

107+
$timeout.flush();
108+
68109
expect(select.text()).toBe('abc');
69110
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');
70115
});
71116

72117
});

0 commit comments

Comments
 (0)