Skip to content

Commit a2f58b7

Browse files
author
Dean Sofer
committed
fix(tests): Adjusted tests to pass properly
1 parent 6d09dc9 commit a2f58b7

File tree

4 files changed

+29
-38
lines changed

4 files changed

+29
-38
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ This directive allows you to enhance your select elements with behaviour from th
1010

1111
## Setup
1212

13-
1. Install **testacular**
14-
`$ npm install -g testacular@canary`
13+
1. Install **karma**
14+
`$ npm install -g karma`
1515
2. Install **bower**
1616
`$ npm install -g bower`
1717
4. Install components
@@ -21,7 +21,7 @@ This directive allows you to enhance your select elements with behaviour from th
2121

2222
## Testing
2323

24-
`$ testacular start test/test.conf.js --browsers=Chrome`
24+
`$ karma start test/test.conf.js --browsers=Chrome`
2525

2626
# Usage
2727

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "angular-ui-select2",
44
"keywords": ["angular", "angularui", "select2"],
55
"description": "AngularUI - The companion suite for AngularJS",
6-
"version": "0.1.0",
6+
"version": "0.0.2",
77
"homepage": "http://angular-ui.github.com",
88
"repository": {
99
"type": "git",
@@ -16,6 +16,6 @@
1616
"devDependencies": {
1717
"grunt-recess": "~0.1.3",
1818
"async": "0.1.x",
19-
"testacular": "~0.5.x"
19+
"karma": "~0"
2020
}
2121
}

src/select2.js

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,13 @@ angular.module('ui.select2', []).value('uiSelect2Config', {}).directive('uiSelec
8383
// Update valid and dirty statuses
8484
controller.$parsers.push(function (value) {
8585
var div = elm.prev()
86-
if (controller.$valid) {
87-
div.removeClass("ng-invalid").addClass("ng-valid");
88-
div.removeClass("ng-invalid-required").addClass("ng-valid-required");
89-
}
90-
if (!controller.$valid) {
91-
div.removeClass("ng-valid").addClass("ng-invalid");
92-
div.removeClass("ng-valid-required").addClass("ng-invalid-required");
93-
}
94-
if (controller.$pristine)
95-
div.removeClass("ng-dirty").addClass("ng-pristine");
96-
if (controller.$dirty)
97-
div.removeClass("ng-pristine").addClass("ng-dirty");
86+
div
87+
.toggleClass('ng-invalid', !controller.$valid)
88+
.toggleClass('ng-valid', controller.$valid)
89+
.toggleClass('ng-invalid-required', !controller.$valid)
90+
.toggleClass('ng-valid-required', controller.$valid)
91+
.toggleClass('ng-dirty', controller.$dirty)
92+
.toggleClass('ng-pristine', controller.$pristine);
9893
return value;
9994
});
10095

@@ -133,9 +128,6 @@ angular.module('ui.select2', []).value('uiSelect2Config', {}).directive('uiSelec
133128
});
134129
}
135130

136-
// Set initial value since Angular doesn't
137-
//elm.val(scope.$eval(attrs.ngModel));
138-
139131
// Initialize the plugin late so that the injected DOM does not disrupt the template compiler
140132
$timeout(function () {
141133
elm.select2(opts);

test/select2Spec.js

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -125,39 +125,38 @@ describe('uiSelect2', function () {
125125
var element = compile('<select ui-select2="{allowClear:true}" ng-model="foo"><option>First</option><option>Second</option></select>');
126126
expect(element.select2('val')).toBe('First');
127127
scope.$apply('foo = false');
128-
expect(element.select2('val')).toBe(scope.foo);
129-
expect(element.select2('val')).toBe(false);
128+
expect(element.select2('val')).toBe(null);
129+
scope.$apply('foo = "Second"');
130130
scope.$apply('foo = null');
131-
expect(element.select2('val')).toBe(scope.foo);
132131
expect(element.select2('val')).toBe(null);
132+
scope.$apply('foo = "Second"');
133133
scope.$apply('foo = undefined');
134-
expect(element.select2('val')).toBe(scope.foo);
135-
expect(element.select2('val')).toBe(undefined);
134+
expect(element.select2('val')).toBe(null);
136135
});
137136
});
138137
describe('for multiple select', function(){
139138
it('should set select2 to multiple value', function(){
140-
scope.foo = 'First';
139+
scope.foo = ['First'];
141140
var element = compile('<select ui-select2="{allowClear:true}" multiple ng-model="foo"><option>First</option><option>Second</option><option>Third</option></select>');
142141
expect(element.select2('val')).toEqual(['First']);
143142
scope.$apply('foo = ["Second"]');
144143
expect(element.select2('val')).toEqual(['Second']);
145144
scope.$apply('foo = ["Second","Third"]');
146145
expect(element.select2('val')).toEqual(['Second','Third']);
147146
});
148-
it('should set select2 to the value for multiples', function(){
149-
scope.foo = 'First';
150-
var element = compile('<select ui-select2 multiple ng-model="foo"><option>First</option><option>Second</option><option>Third</option></select>');
151-
expect(element.select2('val')).toEqual(['First']);
147+
it('should handle falsey values', function(){
148+
scope.foo = ['First'];
149+
var element = compile('<select ui-select2="{allowClear:true}" multiple ng-model="foo"><option>First</option><option>Second</option><option>Third</option></select>');
150+
expect(element.val()).toEqual(['First']);
151+
scope.$apply('foo = ["Second"]');
152152
scope.$apply('foo = false');
153-
expect(element.select2('val')).toBe(scope.foo);
154-
expect(element.select2('val')).toBe(false);
153+
expect(element.select2('val')).toEqual([]);
154+
scope.$apply('foo = ["Second"]');
155155
scope.$apply('foo = null');
156-
expect(element.select2('val')).toBe(scope.foo);
157-
expect(element.select2('val')).toBe(null);
156+
expect(element.select2('val')).toEqual([]);
157+
scope.$apply('foo = ["Second"]');
158158
scope.$apply('foo = undefined');
159-
expect(element.select2('val')).toBe(scope.foo);
160-
expect(element.select2('val')).toBe(undefined);
159+
expect(element.select2('val')).toEqual([]);
161160
});
162161
});
163162
});
@@ -182,8 +181,8 @@ describe('uiSelect2', function () {
182181
scope.items = ['first', 'second', 'third'];
183182
scope.foo = 'fourth';
184183
var element = compile('<select ui-select2 ng-model="foo"><option ng-repeat="item in items">{{item}}</option></select>');
185-
expect(element.select2('val')).toNotBe('fourth');
186-
scope.$apply('items=["fourth"]');
184+
expect(element.select2('val')).toBe(null);
185+
scope.$apply('foo="fourth";items=["fourth"]');
187186
$timeout.flush();
188187
expect(element.select2('val')).toBe('fourth');
189188
});

0 commit comments

Comments
 (0)