summaryrefslogtreecommitdiffstats
path: root/tests/unit/sortable/sortable_tickets.js
blob: 3edc8c04cfba18568fc114ef384104fc18375b10 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
 * sortable_tickets.js
 */
(function($) {

var el, offsetBefore, offsetAfter, dragged;

var drag = function(handle, dx, dy) {
	offsetBefore = $(handle).offset();
	$(handle).simulate("drag", {
		dx: dx || 0,
		dy: dy || 0
	});
	dragged = { dx: dx, dy: dy };
	offsetAfter = $(handle).offset();
}

var sort = function(handle, dx, dy, index, msg) {
	drag(handle, dx, dy);
	equals($(handle).parent().children().index(handle), index, msg);
}

module("sortable: tickets");

test("#3019: Stop fires too early", function() {

	var helper = null;
	el = $("#sortable").sortable({
		stop: function(event, ui) {
			helper = ui.helper;
		}
	});

	sort($("li", el)[0], 0, 40, 2, 'Dragging the sortable');
	equals(helper, null, "helper should be false");

});

test('#4752: link event firing on sortable with connect list', function () {
    var fired = {},
        hasFired = function (type) { return (type in fired) && (true === fired[type]); };

    $('#sortable').clone().attr('id', 'sortable2').insertAfter('#sortable');

    $('#main ul').sortable({
        connectWith: '#main ul',
        change: function (e, ui) {
            fired.change = true;
        },
        receive: function (e, ui) {
            fired.receive = true;
        },
        remove: function (e, ui) {
            fired.remove = true;
        }
    });

    $('#main ul li').live('click.ui-sortable-test', function () {
        fired.click = true;
    });

    $('#sortable li:eq(0)').simulate('click');
    ok(!hasFired('change'), 'Click only, change event should not have fired');
    ok(hasFired('click'), 'Click event should have fired');

    // Drag an item within the first list
    fired = {};
    $('#sortable li:eq(0)').simulate('drag', { dx: 0, dy: 40 });
    ok(hasFired('change'), '40px drag, change event should have fired');
    ok(!hasFired('receive'), 'Receive event should not have fired');
    ok(!hasFired('remove'), 'Remove event should not have fired');
    ok(!hasFired('click'), 'Click event should not have fired');

    // Drag an item from the first list to the second, connected list
    fired = {};
    $('#sortable li:eq(0)').simulate('drag', { dx: 0, dy: 150 });
    ok(hasFired('change'), '150px drag, change event should have fired');
    ok(hasFired('receive'), 'Receive event should have fired');
    ok(hasFired('remove'), 'Remove event should have fired');
    ok(!hasFired('click'), 'Click event should not have fired');
});

})(jQuery);