summaryrefslogtreecommitdiffstats
path: root/js/vendor/angular-ui/modules/directives/sortable/test/sortableSpec.js
blob: 04a46a072b05b411524b6c9cf243b79aac5afce7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
describe('uiSortable', function() {

  // Ensure the sortable angular module is loaded
  beforeEach(module('ui.directives'));

  describe('simple use', function() {

    it('should have a ui-sortable class', function() {
      inject(function($compile, $rootScope) {
        var element;
        element = $compile("<ul ui-sortable></ul>")($rootScope);
        expect(element.hasClass("ui-sortable")).toBeTruthy();
      });
    });

    it('should update model when order changes', function() {
      inject(function($compile, $rootScope) {
        var element;
        element = $compile('<ul ui-sortable ng-model="items"><li ng-repeat="item in items" id="s-{{$index}}">{{ item }}</li></ul>')($rootScope);
        $rootScope.$apply(function() {
          return $rootScope.items = ["One", "Two", "Three"];
        });

        element.find('li:eq(1)').insertAfter(element.find('li:eq(2)'));

        // None of this work, one way is to use .bind("sortupdate")
        // and then use .trigger("sortupdate", e, ui) but I have no idea how to
        // construct ui object
        
        // element.sortable('refresh')
        // element.sortable('refreshPositions')
        // element.trigger('sortupdate')

        // expect($rootScope.items).toEqual(["One", "Three", "Two"])
      });
    });

  });

});