<commit_before>var expect = chai.expect;

d3.select("body").append("link")
  .attr("rel", "stylesheet")
  .attr("href", "/base/test/bundle-test.css");

describe("dagreD3", function() {
  var svg,
      g;

  beforeEach(function() {
    svg = d3.select("body").append("svg");
    g = new dagreD3.graphlib.Graph()
      .setGraph({})
      .setDefaultNodeLabel(function() { return {}; })
      .setDefaultEdgeLabel(function() { return {}; });
  });

  afterEach(function() {
    svg.remove();
  });

  describe("exports", function() {
    _.each(["graphlib", "dagre", "intersect", "util"], function(lib) {
      it(lib, function() {
        expect(dagreD3[lib]).to.be.an("object");
      });
    });

    it("render", function() {
      expect(dagreD3.render).to.be.a("function");
    });

    it("version", function() {
      expect(dagreD3.version).to.be.a("string");
    });
  });

  describe("DOM elements", function() {
    it("are created for each node", function() {
      g.setNode("a", { id: "a" });
      g.setNode("b", { id: "b" });
      dagreD3.render()(svg, g);

      expect(d3.select("#a").datum()).to.equal("a");
      expect(d3.select("#b").datum()).to.equal("b");
    });

    it("are created for each node label", function() {
      g.setNode("a", { labelId: "a-lab" });
      g.setNode("b", { labelId: "b-lab" });
      dagreD3.render()(svg, g);

      expect(d3.select("#a-lab").datum()).to.equal("a");
      expect(d3.select("#b-lab").datum()).to.equal("b");
    });

    it("are created for each edge", function() {
      g.setNode("a", {});
      g.setNode("b", {});
      g.setEdge("a", "b", { id: "ab" });
      dagreD3.render()(svg, g);

      expect(d3.select("#ab").datum()).eqls({ v: "a", w: "b" });
    });
<commit_msg>Add test to ensure DOM element is bound to node object<commit_after>var expect = chai.expect;

d3.select("body").append("link")
  .attr("rel", "stylesheet")
  .attr("href", "/base/test/bundle-test.css");

describe("dagreD3", function() {
  var svg,
      g;

  beforeEach(function() {
    svg = d3.select("body").append("svg");
    g = new dagreD3.graphlib.Graph()
      .setGraph({})
      .setDefaultNodeLabel(function() { return {}; })
      .setDefaultEdgeLabel(function() { return {}; });
  });

  afterEach(function() {
    svg.remove();
  });

  describe("exports", function() {
    _.each(["graphlib", "dagre", "intersect", "util"], function(lib) {
      it(lib, function() {
        expect(dagreD3[lib]).to.be.an("object");
      });
    });

    it("render", function() {
      expect(dagreD3.render).to.be.a("function");
    });

    it("version", function() {
      expect(dagreD3.version).to.be.a("string");
    });
  });

  describe("DOM elements", function() {
    it("are created for each node", function() {
      g.setNode("a", { id: "a" });
      g.setNode("b", { id: "b" });
      dagreD3.render()(svg, g);

      expect(d3.select("#a").datum()).to.equal("a");
      expect(d3.select("#b").datum()).to.equal("b");

      // We should also be able to get to the element from the node object.
      expect(g.node("a").elem).to.equal(d3.select("#a").node());
      expect(g.node("b").elem).to.equal(d3.select("#b").node());
    });

    it("are created for each node label", function() {
      g.setNode("a", { labelId: "a-lab" });
      g.setNode("b", { labelId: "b-lab" });
      dagreD3.render()(svg, g);

      expect(d3.select("#a-lab").datum()).to.equal("a");
      expect(d3.select("#b-lab").datum()).to.equal("b");
    });

    it("are created for each edge", function() {
      g.setNode("a", {});
      g.setNode("b", {});
      g.setEdge("a", "b", { id: "ab" });
      dagreD3.render()(svg, g);

      expect(d3.select("#ab").datum()).eqls({ v: "a", w: "b" });
    });

{'fraction_non_alphanumeric': 0.24799786438868127, 'fraction_numerical': 0.008542445274959957, 'mean_word_length': 2.9525316455696204, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5789720', 'n_tokens_mistral': 1368, 'n_tokens_neox': 1338, 'n_words': 220}