~bcsaller/juju-gui/charmFind

« back to all changes in this revision

Viewing changes to lib/d3/test/core/selection-text-test.js

  • Committer: kapil.foss at gmail
  • Date: 2012-07-13 18:45:59 UTC
  • Revision ID: kapil.foss@gmail.com-20120713184559-2xl7be17egsrz0c9
reshape

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.text");
7
 
 
8
 
suite.addBatch({
9
 
  "select(body)": {
10
 
    topic: function() {
11
 
      return d3.select("body").html("");
12
 
    },
13
 
    "sets the text content as a string": function(body) {
14
 
      body.text("Hello, world!");
15
 
      assert.equal(document.body.textContent, "Hello, world!");
16
 
    },
17
 
    "sets the text content as a number": function(body) {
18
 
      body.text(42);
19
 
      assert.equal(document.body.textContent, "42");
20
 
    },
21
 
    "sets the text content as a function": function(body) {
22
 
      body.data(["Subject"]).text(function(d, i) { return "Hello, " + d + " " + i + "!"; });
23
 
      assert.equal(document.body.textContent, "Hello, Subject 0!");
24
 
    },
25
 
    "escapes html content to text": function(body) {
26
 
      body.text("<h1>Hello, world!</h1>");
27
 
      assert.equal(document.body.textContent, "<h1>Hello, world!</h1>");
28
 
      assert.equal(document.body.firstChild.nodeType, document.TEXT_NODE);
29
 
    },
30
 
    "clears the text content as null": function(body) {
31
 
      body.text(null);
32
 
      assert.equal(document.body.textContent, "");
33
 
    },
34
 
    "clears the text content as undefined": function(body) {
35
 
      body.text(undefined);
36
 
      assert.equal(document.body.textContent, "");
37
 
    },
38
 
    "clears the text content as a function returning null": function(body) {
39
 
      body.text(function() { return null; });
40
 
      assert.equal(document.body.textContent, "");
41
 
    },
42
 
    "clears the text content as a function returning undefined": function(body) {
43
 
      body.text(function() { return undefined; });
44
 
      assert.equal(document.body.textContent, "");
45
 
    },
46
 
    "ignores null nodes": function() {
47
 
      var body = d3.select("body");
48
 
      body[0][0] = null;
49
 
      document.body.textContent = "foo";
50
 
      body.text("bar");
51
 
      assert.equal(document.body.textContent, "foo");
52
 
    },
53
 
    "returns the current selection": function(body) {
54
 
      assert.isTrue(body.text("hello") === body);
55
 
    }
56
 
  }
57
 
});
58
 
 
59
 
suite.addBatch({
60
 
  "selectAll(div)": {
61
 
    topic: function() {
62
 
      return d3.select("body").html("").selectAll("div").data(d3.range(2)).enter().append("div");
63
 
    },
64
 
    "sets the text content as a string": function(div) {
65
 
      div.text("Hello, world!");
66
 
      assert.equal(div[0][0].textContent, "Hello, world!");
67
 
      assert.equal(div[0][1].textContent, "Hello, world!");
68
 
    },
69
 
    "sets the text content as a number": function(div) {
70
 
      div.text(42);
71
 
      assert.equal(div[0][0].textContent, "42");
72
 
      assert.equal(div[0][1].textContent, "42");
73
 
    },
74
 
    "sets the text content as a function": function(div) {
75
 
      div.data(["foo", "bar"]).text(function(d, i) { return "Hello, " + d + " " + i + "!"; });
76
 
      assert.equal(div[0][0].textContent, "Hello, foo 0!");
77
 
      assert.equal(div[0][1].textContent, "Hello, bar 1!");
78
 
    },
79
 
    "escapes html content to text": function(div) {
80
 
      div.text("<h1>Hello, world!</h1>");
81
 
      assert.equal(div[0][0].textContent, "<h1>Hello, world!</h1>");
82
 
      assert.equal(div[0][1].textContent, "<h1>Hello, world!</h1>");
83
 
      assert.equal(div[0][0].firstChild.nodeType, document.TEXT_NODE);
84
 
      assert.equal(div[0][1].firstChild.nodeType, document.TEXT_NODE);
85
 
    },
86
 
    /*
87
 
    https://github.com/tmpvar/jsdom/issues/276
88
 
    "clears the text content as null": function(div) {
89
 
      div.text(null);
90
 
      assert.equal(div[0][0].textContent, "");
91
 
      assert.equal(div[0][1].textContent, "");
92
 
    },
93
 
    "clears the text content as a function": function(div) {
94
 
      div.text(function() { return null; });
95
 
      assert.equal(dv[0][0].textContent, "");
96
 
      assert.equal(dv[0][1].textContent, "");
97
 
    },
98
 
    */
99
 
    "ignores null nodes": function(div) {
100
 
      div[0][0].textContent = "foo";
101
 
      var some = d3.selectAll("div");
102
 
      some[0][0] = null;
103
 
      some.text("bar");
104
 
      assert.equal(div[0][0].textContent, "foo");
105
 
      assert.equal(div[0][1].textContent, "bar");
106
 
    },
107
 
    "returns the current selection": function(div) {
108
 
      assert.isTrue(div.text("hello") === div);
109
 
    }
110
 
  }
111
 
});
112
 
 
113
 
suite.export(module);