mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
BREAKING CHANGE: $ionicActionSheet now returns a method to hide the
action sheet.
Previously, it returned an object that had a `show` and `hide` method.
This was undocumented, but if you used it, here is how to migrate your
code:
Change your code from this:
```js
var sheet = $ionicActionSheet.show({...});
sheet.hide();
```
To this:
```js
var hideSheet = $ionicActionSheet.show({...});
hideSheet();
```
82 lines
2.6 KiB
JavaScript
82 lines
2.6 KiB
JavaScript
describe('Ionic ActionSheet Service', function() {
|
|
|
|
var sheet, timeout, ionicPlatform;
|
|
|
|
beforeEach(module('ionic', function($provide) {
|
|
// For the sake of this test, we don't want ionActionSheet to
|
|
// actually compile as a directive.
|
|
// We are only testing the service.
|
|
$provide.value('ionActionSheetDirective', []);
|
|
}));
|
|
|
|
function setup(options) {
|
|
var scope;
|
|
inject(function($ionicActionSheet, $ionicPlatform, $timeout) {
|
|
var hide = $ionicActionSheet.show(options || {});
|
|
$timeout.flush();
|
|
scope = hide.$scope;
|
|
});
|
|
return scope;
|
|
}
|
|
|
|
it('should add classes on showing', inject(function($document) {
|
|
var scope = setup();
|
|
expect($document[0].body.classList.contains('action-sheet-open')).toBe(true);
|
|
expect(scope.element.hasClass('active')).toBe(true);
|
|
}));
|
|
|
|
it('removeSheet should remove classes, remove element and destroy scope', inject(function($document, $timeout) {
|
|
var scope = setup();
|
|
spyOn(scope, '$destroy');
|
|
spyOn(scope.element, 'remove');
|
|
scope.removeSheet();
|
|
expect($document[0].body.classList.contains('action-sheet-open')).toBe(false);
|
|
expect(scope.element.hasClass('active')).toBe(false);
|
|
$timeout.flush();
|
|
expect(scope.$destroy).toHaveBeenCalled();
|
|
expect(scope.element.remove).toHaveBeenCalled();
|
|
}));
|
|
|
|
it('destructiveButtonClicked should removeSheet if returning true', function() {
|
|
var destructiveReturnValue = false;
|
|
var scope = setup({
|
|
destructiveButtonClicked: function() {
|
|
return destructiveReturnValue;
|
|
}
|
|
});
|
|
spyOn(scope, 'removeSheet');
|
|
scope.destructiveButtonClicked();
|
|
expect(scope.removeSheet).not.toHaveBeenCalled();
|
|
destructiveReturnValue = true;
|
|
scope.destructiveButtonClicked();
|
|
expect(scope.removeSheet).toHaveBeenCalled();
|
|
});
|
|
|
|
it('buttonClicked should removeSheet if returning true for index', function() {
|
|
var scope = setup({
|
|
buttons: [{}, {}],
|
|
buttonClicked: function(index) {
|
|
return index === 0 ? false : true;
|
|
}
|
|
});
|
|
spyOn(scope, 'removeSheet');
|
|
scope.buttonClicked(0);
|
|
expect(scope.removeSheet).not.toHaveBeenCalled();
|
|
scope.buttonClicked(1);
|
|
expect(scope.removeSheet).toHaveBeenCalled();
|
|
});
|
|
|
|
it('cancel should removeSheet and call opts.cancel', inject(function($timeout) {
|
|
var cancelSpy = jasmine.createSpy('opts.cancel');
|
|
var scope = setup({
|
|
cancel: cancelSpy
|
|
});
|
|
spyOn(scope, 'removeSheet').andCallThrough();
|
|
scope.cancel();
|
|
expect(scope.removeSheet).toHaveBeenCalled();
|
|
$timeout.flush();
|
|
expect(cancelSpy).toHaveBeenCalled();
|
|
}));
|
|
|
|
});
|