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

Commit 9920e5d

Browse files
committed
Fix tests
1 parent d807466 commit 9920e5d

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

test/select.spec.js

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('ui-select tests', function() {
2222
}));
2323

2424

25-
// Utility functions
25+
// DSL (domain-specific language)
2626

2727
function compileTemplate(template) {
2828
var el = $compile(angular.element(template))(scope);
@@ -53,7 +53,7 @@ describe('ui-select tests', function() {
5353
}
5454

5555
function clickItem(el, text) {
56-
$(el).find('.ui-select-choices-row > div:contains("' + text + '")').click();
56+
$(el).find('.ui-select-choices-row div:contains("' + text + '")').click();
5757
scope.$digest();
5858
}
5959

@@ -62,6 +62,15 @@ describe('ui-select tests', function() {
6262
scope.$digest();
6363
}
6464

65+
function isDropdownOpened(el) {
66+
// Does not work with jQuery 2.*, have to use jQuery 1.11.*
67+
// This will be fixed in AngularJS 1.3
68+
// See issue with unit-testing directive using karma https://github.com/angular/angular.js/issues/4640#issuecomment-35002427
69+
return el.scope().$select.open && el.hasClass('open');
70+
}
71+
72+
73+
// Tests
6574

6675
it('should compile child directives', function() {
6776
var el = createUiSelect();
@@ -78,8 +87,8 @@ describe('ui-select tests', function() {
7887
var choicesContainerEl = $(el).find('.ui-select-choices');
7988
expect(choicesContainerEl.length).toEqual(1);
8089

81-
var choicesElems = $(el).find('.ui-select-choices-row');
82-
expect(choicesElems.length).toEqual(8);
90+
var choicesEls = $(el).find('.ui-select-choices-row');
91+
expect(choicesEls.length).toEqual(8);
8392
});
8493

8594
it('should correctly render initial state', function() {
@@ -93,15 +102,11 @@ describe('ui-select tests', function() {
93102
it('should display the choices when activated', function() {
94103
var el = createUiSelect();
95104

96-
// Does not work with jQuery 2.*, have to use jQuery 1.11.*
97-
// This will be fixed in AngularJS 1.3
98-
// See issue with unit-testing directive using karma https://github.com/angular/angular.js/issues/4640#issuecomment-35002427
99-
expect(el.scope().$select.open).toEqual(false);
105+
expect(isDropdownOpened(el)).toEqual(false);
100106

101107
clickMatch(el);
102108

103-
expect(el.scope().$select.open).toEqual(true);
104-
expect($(el).find('.ui-select-choices').parent().hasClass('select2-display-none')).toEqual(false);
109+
expect(isDropdownOpened(el)).toEqual(true);
105110
});
106111

107112
it('should select an item', function() {
@@ -132,37 +137,35 @@ describe('ui-select tests', function() {
132137
it('should close the choices when an item is selected', function() {
133138
var el = createUiSelect();
134139

135-
$(el).find('.ui-select-match').click();
136-
scope.$digest();
140+
clickMatch(el);
137141

138-
expect(el.scope().$select.open).toEqual(true);
142+
expect(isDropdownOpened(el)).toEqual(true);
139143

140144
clickItem(el, 'Samantha');
141145

142-
expect(el.scope().$select.open).toEqual(false);
143-
expect($(el).find('.ui-select-choices').parent().hasClass('select2-display-none')).toEqual(true);
146+
expect(isDropdownOpened(el)).toEqual(false);
144147
});
145148

146149
it('should be disabled if the attribute says so', function() {
147150
var el1 = createUiSelect({disabled: true});
148151
expect(el1.scope().$select.disabled).toEqual(true);
149152
clickMatch(el1);
150-
expect(el1.scope().$select.open).toEqual(false);
153+
expect(isDropdownOpened(el1)).toEqual(false);
151154

152155
var el2 = createUiSelect({disabled: false});
153156
expect(el2.scope().$select.disabled).toEqual(false);
154157
clickMatch(el2);
155-
expect(el2.scope().$select.open).toEqual(true);
158+
expect(isDropdownOpened(el2)).toEqual(true);
156159

157160
var el3 = createUiSelect();
158161
expect(el3.scope().$select.disabled).toEqual(false);
159162
clickMatch(el3);
160-
expect(el3.scope().$select.open).toEqual(true);
163+
expect(isDropdownOpened(el3)).toEqual(true);
161164
});
162165

163166
// See when an item that evaluates to false (such as "false" or "no") is selected, the placeholder is shown https://github.com/angular-ui/ui-select/pull/32
164167
it('should not display the placeholder when item evaluates to false', function() {
165-
scope.items = [ 'false' ];
168+
scope.items = ['false'];
166169

167170
var el = compileTemplate(
168171
'<ui-select ng-model="selection"> \

0 commit comments

Comments
 (0)