~ubuntu-branches/ubuntu/precise/whoopsie-daisy/precise-proposed

« back to all changes in this revision

Viewing changes to backend/stats/static/js/d3/test/core/selection-filter-test.js

  • Committer: Package Import Robot
  • Author(s): Evan Dandrea
  • Date: 2012-04-10 14:28:58 UTC
  • Revision ID: package-import@ubuntu.com-20120410142858-nk453o1z7t7py3bs
Tags: 0.1.26
* Take ownership of the NetworkManager state variant on setup and
  unref it, plugging a memory leak.
* Log the reason the server rejected the submitted crash report.
* Send the Whoopsie version with each crash submission.
* Delete both .upload and .uploaded files after 14 days. Thanks
  Marc Deslauriers (LP: #973687).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require("../env");
 
2
 
 
3
var vows = require("vows"),
 
4
    assert = require("assert");
 
5
 
 
6
var suite = vows.describe("selection.filter");
 
7
 
 
8
suite.addBatch({
 
9
  "selectAll(div)": {
 
10
    topic: function() {
 
11
      return d3.select("body").html("").selectAll("div")
 
12
          .data([0, 1])
 
13
        .enter().append("div")
 
14
        .selectAll("span")
 
15
          .data(function(d) { d <<= 1; return [d, d + 1]; })
 
16
        .enter().append("span");
 
17
    },
 
18
    "preserves matching elements": function(span) {
 
19
      var some = span.filter(function(d, i) { return i === 0; });
 
20
      assert.isTrue(some[0][0] === span[0][0]);
 
21
      assert.isTrue(some[1][0] === span[1][0]);
 
22
    },
 
23
    "removes non-matching elements": function(span) {
 
24
      var some = d3.merge(span.filter(function(d, i) { return d & 1; }));
 
25
      assert.equal(some.indexOf(span[0][0]), -1);
 
26
      assert.equal(some.indexOf(span[1][0]), -1);
 
27
    },
 
28
    "preserves data": function(span) {
 
29
      var some = span.filter(function(d, i) { return d & 1; });
 
30
      assert.equal(some[0][0].__data__, 1);
 
31
      assert.equal(some[1][0].__data__, 3);
 
32
    },
 
33
    "preserves grouping": function(span) {
 
34
      var some = span.filter(function(d, i) { return d & 1; });
 
35
      assert.equal(some.length, 2);
 
36
      assert.equal(some[0].length, 1);
 
37
      assert.equal(some[1].length, 1);
 
38
    },
 
39
    "preserves parent node": function(span) {
 
40
      var some = span.filter(function(d, i) { return d & 1; });
 
41
      assert.isTrue(some[0].parentNode === span[0].parentNode);
 
42
      assert.isTrue(some[1].parentNode === span[1].parentNode);
 
43
    },
 
44
    "does not preserve index": function(span) {
 
45
      var indexes = [];
 
46
      span.filter(function(d, i) { return d & 1; }).each(function(d, i) { indexes.push(i); });
 
47
      assert.deepEqual(indexes, [0, 0]);
 
48
    },
 
49
    "ignores null nodes": function() {
 
50
      var span = d3.selectAll("span");
 
51
      span[0][1] = null;
 
52
      var some = span.filter(function(d, i) { return d & 1; });
 
53
      assert.isTrue(some[0][0] === span[0][3]);
 
54
      assert.equal(some.length, 1);
 
55
    },
 
56
    "can be specified as a selector": function(span) {
 
57
      span.classed("foo", function(d, i) { return d & 1; });
 
58
      var some = span.filter(".foo");
 
59
      assert.equal(some.length, 2);
 
60
      assert.equal(some[0].length, 1);
 
61
      assert.equal(some[1].length, 1);
 
62
    },
 
63
    "returns a new selection": function(span) {
 
64
      assert.isFalse(span.filter(function() { return 1; }) === span);
 
65
    }
 
66
  }
 
67
});
 
68
 
 
69
suite.export(module);