feat(slideBox): add on-slide-start callback

This commit is contained in:
Andrew
2014-12-01 16:10:53 -07:00
parent 55b35b5409
commit cd5aaa5df2
7 changed files with 95 additions and 31 deletions

View File

@@ -37,6 +37,12 @@ describe('ionSlideBox', function() {
describe('directive', function() {
it('should error with nested ion-slides', function() {
expect(function() {
setup('', '<ion-slide> <ion-slide>Nested</ion-slide> </ion-slide>');
}).toThrow();
});
describe('selection', function() {
it('should select first slide automatically', inject(function($rootScope, $timeout) {
var el = setup('selected="$root.current"');
@@ -140,16 +146,28 @@ describe('ionSlideBox', function() {
it('should call when selected changes', inject(function($rootScope, $timeout) {
$rootScope.changed = jasmine.createSpy('changed');
var el = setup('selected="$root.current" on-slide-changed="changed($slideIndex)"');
expect($rootScope.changed).not.toHaveBeenCalled();
$timeout.flush();
expect($rootScope.changed).toHaveBeenCalledWith(0);
$rootScope.changed.reset();
$rootScope.$apply('current = 2');
expect($rootScope.changed).not.toHaveBeenCalled();
$timeout.flush();
expect($rootScope.changed).toHaveBeenCalledWith(2);
}));
});
describe('onSlideStart', function() {
it('should call when animation starts', inject(function($rootScope, $timeout) {
$rootScope.start = jasmine.createSpy('start');
$rootScope.current = 1;
var el = setup('selected="$root.current" on-slide-start="$root.start($slideIndex)">');
expect($rootScope.start).toHaveBeenCalledWith(1);
$timeout.flush();
}));
});
});
describe('delegate', function() {
@@ -324,27 +342,38 @@ describe('ionSlideBox', function() {
it('when queueing, should only publish after final slide', inject(function($timeout, $rootScope) {
$rootScope.changed = jasmine.createSpy('changed');
var el = setup('selected="$root.current" on-slide-changed="$root.changed($slideIndex)"');
$rootScope.start = jasmine.createSpy('start');
var el = setup('selected="$root.current" on-slide-changed="$root.changed($slideIndex)" on-slide-start="$root.start($slideIndex)"');
$timeout.flush();
$rootScope.changed.reset();
$rootScope.start.reset();
$del.select(1);
$del.select(2);
$del.select(1);
expect($rootScope.start).toHaveBeenCalledWith(1);
$rootScope.start.reset();
$timeout.flush();
// Scope data bindings not published
expect($rootScope.changed).not.toHaveBeenCalled();
expect($rootScope.current).toBe(0);
// Elements look different, though.
expect(slideDisplays(el)).toEqual(['previous', 'selected', 'next']);
expect($rootScope.start).toHaveBeenCalledWith(2);
$rootScope.start.reset();
$timeout.flush();
expect($rootScope.changed).not.toHaveBeenCalled();
expect($rootScope.current).toBe(0);
expect(slideDisplays(el)).toEqual(['', 'previous', 'selected']);
expect($rootScope.start).toHaveBeenCalledWith(1);
$rootScope.start.reset();
$timeout.flush();
expect($rootScope.changed).toHaveBeenCalledWith(1);
expect($rootScope.current).toBe(1);
expect(slideDisplays(el)).toEqual(['previous', 'selected', 'next']);

View File

@@ -59,7 +59,6 @@ describe('<ion-slide-pager> directive', function() {
var slideBoxCtrl = el.controller('ionSlideBox');
var pagers = el.find('.slider-pager-page');
expect(slideBoxCtrl.selected()).toBe(0);
pagers.eq(1).click();
expect(slideBoxCtrl.selected()).toBe(0);
expect($rootScope.click).toHaveBeenCalledWith(1);