toolkit/javascript/d3/test/core/transition-test-remove.js
changeset 47 c0b4a8b5a012
equal deleted inserted replaced
46:efd9c589177a 47:c0b4a8b5a012
       
     1 require("../env");
       
     2 require("../../d3");
       
     3 
       
     4 var assert = require("assert");
       
     5 
       
     6 module.exports = {
       
     7   topic: function() {
       
     8     var cb = this.callback,
       
     9         t = d3.select("body").append("div").transition().remove();
       
    10     t.each("end", function() { cb(null, t); });
       
    11   },
       
    12   "removes the selected elements": function(transition) {
       
    13     assert.domEqual(transition[0][0].node.parentNode, null);
       
    14   },
       
    15 
       
    16   "when the element is already removed": {
       
    17     topic: function() {
       
    18       var cb = this.callback,
       
    19           t = d3.select("body").append("div").remove().transition().remove();
       
    20       t.each("end", function() { cb(null, t); });
       
    21     },
       
    22     "does nothing": function(transition) {
       
    23       assert.domEqual(transition[0][0].node.parentNode, null);
       
    24     }
       
    25   },
       
    26 
       
    27   // Since these tests are triggered inside the end event of the above topic,
       
    28   // transitions will inherit ids from the original transition. But we want to
       
    29   // test concurrent transitions, so we use timeouts to avoid inheritance. This
       
    30   // test also verifies that if multiple transitions are created at the same
       
    31   // time, the last transition becomes the owner.
       
    32 
       
    33   "when another transition is scheduled": {
       
    34     topic: function() {
       
    35       var cb = this.callback,
       
    36           s = d3.select("body").append("div");
       
    37       setTimeout(function() {
       
    38         s.transition().duration(150).remove().each("end", function() { cb(null, s); });
       
    39         s.transition().delay(250);
       
    40       }, 10);
       
    41     },
       
    42     "does nothing": function(selection) {
       
    43       assert.domEqual(selection[0][0].parentNode, document.body);
       
    44     }
       
    45   }
       
    46 };