3
var assert = require("assert");
8
var cb = this.callback,
9
div = d3.select("body").html("").selectAll().data(["foo", "bar"]).enter().append("div").attr("class", String),
10
transition = div.transition().delay(150),
20
// A callback to verify that multiple callbacks are allowed.
21
transition.each("start.other", function() {
25
// A callback which captures arguments and context.
26
transition.each("start", function(d, i) {
31
delay.push(Date.now() - then);
32
if (n >= 4) cb(null, {
44
"invokes the listener after the specified delay": function(result) {
45
assert.inDelta(result.delay, [150, 150], 20);
47
"invokes each listener exactly once, in order": function(result) {
48
assert.deepEqual(result.count, [2, 4]);
51
// For the same node, listeners will be called back in order, according to
52
// the implementation of d3.dispatch. However, the order of callbacks across
53
// nodes is not guaranteed; currently, callbacks are in reverse order if
54
// they share the same delay, because of the timer queue. I suppose it'd be
55
// slightly better if the callbacks were invoked in node order (consistent
56
// with selections), but since these callbacks happen asynchronously I don't
57
// think the API needs to guarantee the order of callbacks.
59
"uses the node as the context": function(result) {
60
assert.domEqual(result.context[1], result.selection[0][0]);
61
assert.domEqual(result.context[0], result.selection[0][1]);
63
"passes the data and index to the function": function(result) {
64
assert.deepEqual(result.data, ["bar", "foo"], "expected data, got {actual}");
65
assert.deepEqual(result.index, [1, 0], "expected index, got {actual}");
68
"sets an exclusive lock on transitioning nodes": function(result) {
70
assert.isTrue(id > 0);
71
assert.equal(result.selection[0][0].__transition__.count, 1);
72
assert.equal(result.selection[0][1].__transition__.count, 1);
73
assert.equal(result.selection[0][0].__transition__.active, id);
74
assert.equal(result.selection[0][1].__transition__.active, id);
80
var cb = this.callback,
81
div = d3.select("body").html("").selectAll().data(["foo", "bar"]).enter().append("div").attr("class", String),
82
transition = div.transition().duration(150),
92
// A callback to verify that multiple callbacks are allowed.
93
transition.each("end.other", function() {
97
// A callback which captures arguments and context.
98
transition.each("end", function(d, i) {
103
delay.push(Date.now() - then);
104
if (n >= 4) cb(null, {
116
"invokes the listener after the specified delay": function(result) {
117
assert.inDelta(result.delay, [150, 150], 20);
119
"invokes each listener exactly once, in order": function(result) {
120
assert.deepEqual(result.count, [2, 4]);
123
// For the same node, listeners will be called back in order, according to
124
// the implementation of d3.dispatch. However, the order of callbacks across
125
// nodes is not guaranteed; currently, callbacks are in reverse order if
126
// they share the same delay, because of the timer queue. I suppose it'd be
127
// slightly better if the callbacks were invoked in node order (consistent
128
// with selections), but since these callbacks happen asynchronously I don't
129
// think the API needs to guarantee the order of callbacks.
131
"uses the node as the context": function(result) {
132
assert.domEqual(result.context[1], result.selection[0][0]);
133
assert.domEqual(result.context[0], result.selection[0][1]);
135
"passes the data and index to the function": function(result) {
136
assert.deepEqual(result.data, ["bar", "foo"], "expected data, got {actual}");
137
assert.deepEqual(result.index, [1, 0], "expected index, got {actual}");
140
"deletes the transition lock after end": function(result) {
141
assert.isFalse("__transition__" in result.selection[0][0]);
142
assert.isFalse("__transition__" in result.selection[0][1]);
145
// I'd like to test d3.timer.flush here, but unfortunately there's a bug in
146
// Vows where it really doesn't like to receive multiple callbacks from
147
// different tests at the same time!
150
topic: function(result) {
151
var cb = this.callback,
152
node = result.selection[0][0],
154
d3.select(node).transition().delay(150).each("start", function() {
155
cb(null, {id: id, node: this});
158
"inherits the same transition id": function(result) {
159
assert.isTrue(result.id > 0);
160
assert.equal(result.node.__transition__.count, 1);
161
assert.equal(result.node.__transition__.active, result.id);