~smagoun/whoopsie/whoopsie-lp1017637

« back to all changes in this revision

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

  • Committer: Evan Dandrea
  • Date: 2012-05-09 05:53:45 UTC
  • Revision ID: evan.dandrea@canonical.com-20120509055345-z2j41tmcbf4as5uf
The backend now lives in lp:daisy and the website (errors.ubuntu.com) now lives in lp:errors.

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.datum");
7
 
 
8
 
suite.addBatch({
9
 
  "select(body)": {
10
 
    topic: function() {
11
 
      return d3.select("body").html("");
12
 
    },
13
 
    "updates the data according to the specified function": function(body) {
14
 
      body.data([42]).datum(function(d, i) { return d + i; });
15
 
      assert.equal(document.body.__data__, 42);
16
 
    },
17
 
    "updates the data to the specified constant": function(body) {
18
 
      body.datum(43);
19
 
      assert.equal(document.body.__data__, 43);
20
 
    },
21
 
    "deletes the data if the function returns null": function(body) {
22
 
      body.data([42]).datum(function() { return null; });
23
 
      assert.isFalse("__data__" in document.body);
24
 
    },
25
 
    "deletes the data if the constant is null": function(body) {
26
 
      body.data([42]).datum(null);
27
 
      assert.isFalse("__data__" in document.body);
28
 
    },
29
 
    "returns the current selection": function(body) {
30
 
      assert.isTrue(body.datum(function() { return 1; }) === body);
31
 
      assert.isTrue(body.datum(2) === body);
32
 
    },
33
 
    "with no arguments, returns the first node's datum": function(body) {
34
 
      body.data([42]);
35
 
      assert.equal(body.datum(), 42);
36
 
    }
37
 
  }
38
 
});
39
 
 
40
 
suite.addBatch({
41
 
  "selectAll(div)": {
42
 
    topic: function() {
43
 
      return d3.select("body").html("").selectAll("div").data(d3.range(2)).enter().append("div");
44
 
    },
45
 
    "updates the data according to the specified function": function(div) {
46
 
      div.data([42, 43]).datum(function(d, i) { return d + i; });
47
 
      assert.equal(div[0][0].__data__, 42);
48
 
      assert.equal(div[0][1].__data__, 44);
49
 
    },
50
 
    "updates the data to the specified constant": function(div) {
51
 
      div.datum(44);
52
 
      assert.equal(div[0][0].__data__, 44);
53
 
      assert.equal(div[0][1].__data__, 44);
54
 
    },
55
 
    "deletes the data if the function returns null": function(div) {
56
 
      div.datum(function() { return null; });
57
 
      assert.isFalse("__data__" in div[0][0]);
58
 
      assert.isFalse("__data__" in div[0][1]);
59
 
    },
60
 
    "deletes the data if the constant is null": function(div) {
61
 
      div.datum(null);
62
 
      assert.isFalse("__data__" in div[0][0]);
63
 
      assert.isFalse("__data__" in div[0][1]);
64
 
    },
65
 
    "returns the current selection": function(div) {
66
 
      assert.isTrue(div.datum(function() { return 1; }) === div);
67
 
      assert.isTrue(div.datum(2) === div);
68
 
    },
69
 
    "ignores null nodes": function(div) {
70
 
      var some = d3.selectAll("div").data([42, 43]);
71
 
      some[0][1] = null;
72
 
      some.datum(function() { return 1; });
73
 
      assert.equal(div[0][0].__data__, 1);
74
 
      assert.equal(div[0][1].__data__, 43);
75
 
      some.datum(2);
76
 
      assert.equal(div[0][0].__data__, 2);
77
 
      assert.equal(div[0][1].__data__, 43);
78
 
    }
79
 
  }
80
 
});
81
 
 
82
 
suite.export(module);