-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(toggle): Added dragging support to toggle switches
Merge pull request #706 from driftyco/wip-draggable-toggle
- Loading branch information
Showing
7 changed files
with
205 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,71 @@ | ||
describe('Ionic Toggle', function() { | ||
var el, rootScope, compile; | ||
|
||
beforeEach(module('ionic.ui.toggle')); | ||
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.isolateScope().toggle; | ||
expect(toggleView).not.toEqual(null); | ||
expect(toggleView.checkbox).not.toEqual(null); | ||
expect(toggleView.handle).not.toEqual(null); | ||
}); | ||
|
||
it('Should toggle', function() { | ||
var toggle = el.isolateScope().toggle; | ||
expect(toggle.val()).toBe(false); | ||
el.click(); | ||
expect(toggle.val()).toBe(true); | ||
el.click(); | ||
expect(toggle.val()).toBe(false); | ||
it('Should destroy', function() { | ||
var toggleView = el.isolateScope().toggle; | ||
spyOn(toggleView, 'destroy'); | ||
el.isolateScope().$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.isolateScope().toggle; | ||
var input = el[0].querySelector('input'); | ||
|
||
// Not disabled, we can toggle | ||
expect(toggle.val()).toBe(false); | ||
el.click(); | ||
ionic.trigger('click', {target: label}) | ||
expect(toggle.val()).toBe(true); | ||
|
||
// Disable it | ||
rootScope.data.isDisabled = true; | ||
rootScope.$apply(); | ||
expect(toggle.el.getAttribute('disabled')).toBe('disabled'); | ||
el.click(); | ||
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(); | ||
el.click(); | ||
expect(toggle.el.getAttribute('disabled')).not.toBe('disabled'); | ||
|
||
// 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.isolateScope().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); | ||
}); | ||
*/ | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
describe('Toggle view', function() { | ||
var element, toggle; | ||
|
||
beforeEach(function() { | ||
element = $('<div class="item item-toggle disable-pointer-events">' + | ||
'<div>Cats</div>' + | ||
'<label class="toggle enable-pointer-events">' + | ||
'<input type="checkbox">' + | ||
'<div class="track disable-pointer-events">' + | ||
'<div class="handle"></div>' + | ||
'</div>' + | ||
'</label>' + | ||
'</div>'); | ||
|
||
el = element[0].getElementsByTagName('label')[0]; | ||
checkbox = el.children[0]; | ||
track = el.children[1]; | ||
handle = track.children[0]; | ||
toggle = new ionic.views.Toggle({ | ||
el: el, | ||
checkbox: checkbox, | ||
track: track, | ||
handle: handle | ||
}); | ||
}); | ||
|
||
it('Should init', function() { | ||
expect(toggle.el).not.toBe(undefined); | ||
}); | ||
}); |