Files
ionic-framework/test/unit/angular/directive/toggle.unit.js
Andrew 537b29d0bb fix(toggle): fix ngChange being reported before model changes
Closes #1349, #1741

BREAKING CHANGE:

ion-toggle no longer has an isolate scope.
This will break your toggle only if you were relying upon the toggle
having an isolate scope: if you were referencing `$parent.value` as
the ng-disabled attribute, for example.

Change your code from this:

<ion-toggle ng-disabled="{{$parent.isDisabled}}"></ion-toggle>

To this:

<ion-toggle ng-disabled="{{isDisabled}}"></ion-toggle>
2014-07-10 23:51:55 -06:00

73 lines
2.1 KiB
JavaScript

describe('Ionic Toggle', function() {
var el, rootScope, compile;
beforeEach(module('ionic'));
beforeEach(inject(function($compile, $rootScope) {
compile = $compile;
rootScope = $rootScope;
el = $compile('<ion-toggle ng-model="data.name"></ion-toggle>')($rootScope);
}));
it('Should load', function() {
var toggleView = el.scope().toggle;
expect(toggleView).not.toEqual(null);
expect(toggleView.checkbox).not.toEqual(null);
expect(toggleView.handle).not.toEqual(null);
});
it('Should destroy', function() {
var toggleView = el.scope().toggle;
spyOn(toggleView, 'destroy');
el.scope().$destroy();
expect(toggleView.destroy).toHaveBeenCalled();
});
it('Should disable and enable', function() {
// Init with not disabled
rootScope.data = { isDisabled: false };
el = compile('<ion-toggle ng-model="data.name" ng-disabled="data.isDisabled"></ion-toggle>')(rootScope);
// Grab fields
var label = el[0].querySelector('label');
var toggle = el.scope().toggle;
var input = el[0].querySelector('input');
// Not disabled, we can toggle
expect(toggle.val()).toBe(false);
ionic.trigger('click', {target: label});
expect(toggle.val()).toBe(true);
// Disable it
rootScope.data.isDisabled = true;
rootScope.$apply();
expect(input.getAttribute('disabled')).toBe('disabled');
// We shouldn't be able to toggle it now
ionic.trigger('click', {target: label});
expect(toggle.val()).toBe(true);
// Re-enable it
rootScope.data.isDisabled = false;
rootScope.$apply();
// Should be able to toggle it now
ionic.trigger('click', {target: label});
expect(toggle.val()).toBe(false);
expect(input.getAttribute('disabled')).not.toBe('disabled');
});
it('Should toggle', function() {
var toggle = el.scope().toggle;
var label = el[0].querySelector('label');
expect(toggle.val()).toBe(false);
ionic.trigger('click', {target: label});
expect(toggle.val()).toBe(true);
ionic.trigger('click', {target: label});
expect(toggle.val()).toBe(false);
});
});