Skip to content

Commit

Permalink
test specifying a d3 selection as parent of chart
Browse files Browse the repository at this point in the history
for #1006
  • Loading branch information
gordonwoodhull committed Sep 14, 2015
1 parent 584c551 commit ec00ee6
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion spec/base-mixin-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ describe('dc.baseMixin', function () {
id = 'chart-id';
});

describe('using a d3 node', function () {
describe('using a d3-created dom element', function () {
var anchorDiv;

beforeEach(function () {
Expand Down Expand Up @@ -294,6 +294,45 @@ describe('dc.baseMixin', function () {
});
});

describe('using a d3 selection', function () {
var anchorDiv;

beforeEach(function () {
anchorDiv = d3.select('body').append('div').attr('id', id);
chart.anchor(anchorDiv);
});

it('should register the chart', function () {
expect(dc.hasChart(chart)).toBeTruthy();
});

it('should return the node, when anchor is called', function () {
expect(chart.anchor()).toEqual(anchorDiv.node());
});

it('should return the id, when anchorName is called', function () {
expect(chart.anchorName()).toEqual(id);
});

describe('without an id', function () {
beforeEach(function () {
d3.select('#' + id).remove();
anchorDiv = d3.select('body').append('div').attr('class', 'no-id').node();
chart.anchor(anchorDiv);
});

it('should return the node, when anchor is called', function () {
expect(chart.anchor()).toEqual(anchorDiv);
});

it('should return a valid, selectable id', function () {
// see http://stackoverflow.com/questions/70579/what-are-valid-values-for-the-id-attribute-in-html
expect(chart.anchorName()).toMatch(/^[a-zA-Z][a-zA-Z0-9_:.-]*$/);
});

});
});

describe('using an id selector', function () {
beforeEach(function () {
d3.select('body').append('div').attr('id', id);
Expand Down

0 comments on commit ec00ee6

Please sign in to comment.