Files
ionic-framework/js/ext/angular/test/directive/ionicRefresher.unit.js
Andy Joslin dbe4e3901d feat(ionic): remove all delegates
BREAKING CHANGE: $ionicScrollDelegate, $ionicSlideBoxDelegate, and
$ionicSideMenuDelegate have been removed.

  - $ionicScrollDelegate has been changed to $ionicScrollController.
    Documentation:
    [ionContent](
    http://ajoslin.github.io/docs/nightly/api/directive/ionContent),
    [ionScroll](
    http://ajoslin.github.io/docs/nightly/api/directive/ionScroll)

    Change your code from this:

    ```html
    <ion-content ng-controller="MyCtrl">
      <button ng-click="scrollBottom()">Scroll to bottom!</button>
    </ion-content>
    ```
    ```js
    function MyCtrl($scope, $ionicScrollDelegate) {
      $scope.scrollBottom = function() {
        $ionicScrollDelegate.scrollBottom();
      };
    }
    ```

    To this:

    ```html
    <!-- optional attr controller-bind, see docs -->
    <ion-content ng-controller="MyCtrl">
      <button ng-click="scrollBottom()">Scroll to bottom!</button>
    </ion-content>
    ```
    ```js
    function MyCtrl($scope) {
      $scope.scrollBottom = function() {
        $scope.$ionicScrollController.scrollBottom();
      };
    }
    ```

  - $ionicSideMenuDelegate has been changed to
    $ionicSideMenusController. Documentation:
    [ionSideMenus](http://ajoslin.github.io/docs/nightly/api/directive/ionSideMenus)

    Change your code from this:

    ```html
    <ion-side-menus>
      <ion-side-menu side="left">Side Menu Left</ion-side-menu>
      <ion-pane ion-side-menu-content ng-controller="MyCtrl">
        <button ng-click="toggleLeftMenu()">
          Toggle Left Menu!
        </button>
      </ion-pane>
    </ion-side-menus>
    ```
    ```js
    function MyCtrl($scope, $ionicSideMenuDelegate) {
      $scope.toggleLeftMenu = function() {
        $ionicSideMenuDelegate.toggleLeft();
      };
    }
    ```

    To this:

    ```html
    <!-- optional attr controller-bind, see documentation -->
    <ion-side-menus>
      <ion-side-menu side="left">Side Menu Left</ion-side-menu>
      <ion-pane ion-side-menu-content ng-controller="MyCtrl">
        <button ng-click="toggleLeftMenu()">
          Toggle Left Menu!
        </button>
      </ion-pane>
    </ion-side-menus>
    ```
    ```js
    function MyCtrl($scope) {
      $scope.toggleLeftMenu = function() {
        $scope.$ionicSideMenuController.toggleLeft();
      };
    }
    ```

  - $ionicSlideBoxDelegate has been removed and upgraded to
    $ionicSlideBoxController. It had only one method that
    was unneeded.  [Documentation](
    http://ajoslin.github.io/docs/nightly/api/directive/ionSlideBox)
2014-03-19 11:51:07 -06:00

103 lines
3.5 KiB
JavaScript

describe('ionRefresher directive', function() {
beforeEach(module('ionic'));
function setup(attrs, scopeProps) {
var el;
inject(function($compile, $rootScope) {
var scope = $rootScope.$new();
var ionicScrollCtrl = {
_setRefresher: jasmine.createSpy('setRefresher'),
scrollView: {
finishPullToRefresh: jasmine.createSpy('finishPullToRefresh')
}
};
angular.extend(scope, scopeProps || {});
el = angular.element('<ion-refresher '+(attrs||'')+'></ion-refresher>');
el.data('$$ionicScrollController', ionicScrollCtrl);
$compile(el)(scope);
$rootScope.$apply();
});
return el;
}
it('should error without ionicScroll', inject(function($compile, $rootScope) {
expect(function() {
$compile('<ion-refresher>')($rootScope);
}).toThrow();
}));
it('should bind $onRefresh', function() {
var refreshSpy = jasmine.createSpy('onRefresh');
var el = setup('on-refresh="refreshSpy()"', {
refreshSpy: refreshSpy
});
expect(refreshSpy).not.toHaveBeenCalled();
el.scope().$onRefresh();
expect(refreshSpy).toHaveBeenCalled();
});
it('should bind $onRefreshOpening', function() {
var spyMe = jasmine.createSpy('onRefreshOpening');
var el = setup('on-pulling="spyMe()"', {
spyMe: spyMe
});
expect(spyMe).not.toHaveBeenCalled();
el.scope().$onPulling();
expect(spyMe).toHaveBeenCalled();
});
it('should setRefresher on scrollCtrl', function() {
var el = setup();
expect(el.controller('$ionicScroll')._setRefresher.callCount).toBe(1);
expect(el.controller('$ionicScroll')._setRefresher).toHaveBeenCalledWith(
el.scope(), el[0]
)
});
it('should listen for scroll.refreshComplete', function() {
var el = setup();
el.addClass('active');
var ctrl = el.controller('$ionicScroll');
expect(ctrl.scrollView.finishPullToRefresh).not.toHaveBeenCalled();
el.scope().$broadcast('scroll.refreshComplete');
expect(el.hasClass('active')).toBe(false);
expect(ctrl.scrollView.finishPullToRefresh).toHaveBeenCalled();
});
it('should have default pullingIcon', function() {
var el = setup();
expect(el[0].querySelector('.icon.icon-pulling.ion-arrow-down-c')).toBeTruthy();
});
it('should allow custom pullingIcon', function() {
var el = setup('pulling-icon="super-icon"');
expect(el[0].querySelector('.icon.icon-pulling.ion-arrow-down-c')).toBeFalsy();
expect(el[0].querySelector('.icon.icon-pulling.super-icon')).toBeTruthy();
});
it('should have default refreshingIcon', function() {
var el = setup();
expect(el[0].querySelector('.icon.icon-refreshing.ion-loading-d')).toBeTruthy();
});
it('should allow custom refreshingIcon', function() {
var el = setup('refreshing-icon="monkey-icon"');
expect(el[0].querySelector('.icon.icon-refreshing.ion-arrow-down-c')).toBeFalsy();
expect(el[0].querySelector('.icon.icon-refreshing.monkey-icon')).toBeTruthy();
});
it('should have no text by default', function() {
var el = setup();
expect(el.text().trim()).toBe('');
});
it('should allow pullingText', function() {
var el = setup('pulling-text="{{2+2}} <b>some</b> text"');
expect(el[0].querySelector('span.icon-pulling').innerHTML).toBe('4 <b>some</b> text');
});
it('should allow refreshingText', function() {
var el = setup('refreshing-text="{{3+2}} <b>text</b>"');
expect(el[0].querySelector('span.icon-refreshing').innerHTML).toBe('5 <b>text</b>');
});
});