cleanup element removale in tests

This commit is contained in:
Spencer Alger 2014-09-12 11:52:30 -07:00
parent af355dd71c
commit 47b475bcf0
5 changed files with 121 additions and 158 deletions

View file

@ -82,6 +82,7 @@ define(function (require) {
el = d3.select('body').append('div')
.attr('class', 'visualize-chart');
layout = new Layout(el[0][0], data, chartType);
});
});
@ -117,7 +118,7 @@ define(function (require) {
describe('layout Method', function () {
beforeEach(function () {
layout.layout({
parent: layout.el,
parent: el,
type: 'div',
class: 'chart',
datum: layout.data,
@ -159,7 +160,7 @@ define(function (require) {
expect(function () {
layout.layout({
parent: layout.el,
parent: el,
type: undefined,
class: 'chart'
});
@ -167,7 +168,7 @@ define(function (require) {
expect(function () {
layout.layout({
parent: layout.el,
parent: el,
type: xAxisSplit,
class: 'chart'
});
@ -178,7 +179,7 @@ define(function (require) {
describe('appendElem Method', function () {
beforeEach(function () {
layout.appendElem(layout.el, 'svg', 'column');
layout.appendElem(el, 'svg', 'column');
});
it('should append DOM element to el with a class name', function () {
@ -189,13 +190,13 @@ define(function (require) {
describe('removeAll Method', function () {
beforeEach(function () {
inject(function (d3) {
d3.select(layout.el).append('div').attr('class', 'visualize');
layout.removeAll(layout.el);
d3.select(el).append('div').attr('class', 'visualize');
layout.removeAll(el);
});
});
it('should remove all DOM elements from the el', function () {
expect(el.selectAll(this.childNodes)[0].length).to.be(0);
expect($(el).children().length).to.be(0);
});
});

View file

@ -170,7 +170,6 @@ define(function (require) {
afterEach(function () {
fixture.remove();
el.remove();
});
it('should append the correct number of divs', function () {
@ -196,16 +195,18 @@ define(function (require) {
newEl = d3.select('body').append('div')
.attr('class', 'series')
.datum({ series: []});
newEl.append('div').attr('class', 'x-axis-chart-title');
newEl.append('div').attr('class', 'y-axis-chart-title');
newEl.select('.x-axis-chart-title').call(chartTitleSplit);
newEl.select('.y-axis-chart-title').call(chartTitleSplit);
fixture = newEl.selectAll(this.childNodes)[0].length;
});
});
afterEach(function () {
el.remove();
fixture.remove();
newEl.remove();
});
@ -239,7 +240,7 @@ define(function (require) {
afterEach(function () {
fixture.remove();
el.remove();
divs.remove();
});
it('should append the correct number of divs', function () {
@ -256,14 +257,16 @@ define(function (require) {
fixture = d3.select('body').append('div')
.attr('class', 'rows')
.datum({ rows: [{}, {}] });
d3.select('.rows').call(yAxisSplit);
divs = d3.selectAll('.y-axis-div')[0];
});
});
afterEach(function () {
fixture.remove();
el.remove();
divs.remove();
});
it('should append the correct number of divs', function () {

View file

@ -7,64 +7,51 @@ define(function (require) {
describe('VisLib Vis Test Suite', function () {
var Vis;
var chart;
var vis;
var el;
var config;
var data = {
hits : 621,
label : '',
ordered : {
hits: 621,
label: '',
ordered: {
date: true,
interval: 30000,
max : 1408734982458,
min : 1408734082458
max: 1408734982458,
min: 1408734082458
},
series : [
{
values: [
{
x: 1408734060000,
y: 8
},
{
x: 1408734090000,
y: 23
},
{
x: 1408734120000,
y: 30
},
{
x: 1408734150000,
y: 28
},
{
x: 1408734180000,
y: 36
},
{
x: 1408734210000,
y: 30
},
{
x: 1408734240000,
y: 26
},
{
x: 1408734270000,
y: 22
},
{
x: 1408734300000,
y: 29
},
{
x: 1408734330000,
y: 24
}
]
}
],
series: [{
values: [{
x: 1408734060000,
y: 8
}, {
x: 1408734090000,
y: 23
}, {
x: 1408734120000,
y: 30
}, {
x: 1408734150000,
y: 28
}, {
x: 1408734180000,
y: 36
}, {
x: 1408734210000,
y: 30
}, {
x: 1408734240000,
y: 26
}, {
x: 1408734270000,
y: 22
}, {
x: 1408734300000,
y: 29
}, {
x: 1408734330000,
y: 24
}]
}],
tooltipFormatter: function (datapoint) {
return datapoint;
},
@ -93,111 +80,81 @@ define(function (require) {
addTooltip: true,
addLegend: true
};
chart = new Vis(el[0][0], config);
vis = new Vis(el[0][0], config);
});
});
afterEach(function () {
el.remove();
// chart.destroy();
vis.destroy();
});
// describe('render Method', function () {
// beforeEach(function () {
// chart.render(data);
// });
describe('render Method', function () {
beforeEach(function () {
vis.render(data);
});
// it('should bind data to this object', function () {
// expect(_.isObject(chart.data)).to.be(true);
// });
//
// it('should instantiate a handler object', function () {
// expect(_.isObject(chart.handler)).to.be(true);
// });
//
// it('should append a chart', function () {
// expect($('.chart').length).to.be(1);
// });
//
// it('should call the checkSize function', function () {});
// });
it('should bind data to this object', function () {
expect(_.isObject(vis.data)).to.be(true);
});
describe('checkSize Method', function () {
// beforeEach(function () {
// chart.render(data);
// $('.chart').width(500);
// });
//
// it('should set prevSize on the object', function () {
// expect(!!chart.prevSize).to.be(true);
// });
//
// it('should return nothing when an argument is passed', function () {
// console.log(chart.checkSize);
// expect(chart.checkSize(false)).to.be(true);
// });
it('should instantiate a handler object', function () {
expect(_.isObject(vis.handler)).to.be(true);
});
it('should append a chart', function () {
expect($('.chart').length).to.be(1);
});
});
// describe('resize Method', function () {
// beforeEach(function () {
// chart.render(data);
// $('.visualize').width(500);
// chart.resize();
// chart.destroy();
// });
//
// it('should resize the chart', function () {
// expect($('.chart').width()).to.be.lessThan(500);
// });
//
//// it('should throw an error when no valid data provided', function () {
//// expect(function () {
//// chart.resize();
//// }).to.throwError();
//// });
// });
//
// describe('destroy Method', function () {
// beforeEach(function () {
// chart.destroy();
// });
//
//// it('should set the destroyFlag to true', function () {
//// expect(chart._attr.destroyFlag).to.be(true);
//// });
//
// it('should remove all DOM elements from el', function () {
// expect($('.vis-wrapper').length).to.be(0);
// });
//
// it('should turn off events', function () {});
// });
describe('resize Method', function () {
beforeEach(function () {
vis.render(data);
$('.visualize').width(500);
vis.resize();
});
// describe('set Method', function () {
// beforeEach(function () {
// chart.render(data);
// chart.set('addLegend', false);
// chart.set('offset', 'wiggle');
// });
//
// it('should set an attribute', function () {
// expect(chart.get('addLegend')).to.be(false);
// expect(chart.get('offset')).to.be('wiggle');
// });
// });
//
// describe('get Method', function () {
// beforeEach(function () {
//// chart.render(data);
// });
//
// it('should get attribue values', function () {
// expect(chart.get('addLegend')).to.be(true);
// expect(chart.get('addTooltip')).to.be(true);
// expect(chart.get('type')).to.be('histogram');
// });
// });
//
it('should resize the chart', function () {
expect($('.chart').width()).to.be.lessThan(500);
});
});
describe('destroy Method', function () {
beforeEach(function () {
vis.destroy();
});
it('should remove all DOM elements from el', function () {
expect($('.vis-wrapper').length).to.be(0);
});
it('should turn off events', function () {});
});
describe('set Method', function () {
beforeEach(function () {
vis.render(data);
vis.set('addLegend', false);
vis.set('offset', 'wiggle');
});
it('should set an attribute', function () {
expect(vis.get('addLegend')).to.be(false);
expect(vis.get('offset')).to.be('wiggle');
});
});
describe('get Method', function () {
beforeEach(function () {
vis.render(data);
});
it('should get attribue values', function () {
expect(vis.get('addLegend')).to.be(true);
expect(vis.get('addTooltip')).to.be(true);
expect(vis.get('type')).to.be('histogram');
});
});
});
});
});

View file

@ -92,7 +92,7 @@ define(function (require) {
dataObj = new Data(data, {});
xAxis = new XAxis({
el: $('x-axis-div')[0],
el: $('.x-axis-div')[0],
xValues: dataObj.xValues(),
ordered: dataObj.get('ordered'),
xAxisFormatter: dataObj.get('xAxisFormatter'),
@ -104,6 +104,7 @@ define(function (require) {
});
afterEach(function () {
fixture.destroy();
el.remove();
});

View file

@ -145,6 +145,7 @@ define(function (require) {
afterEach(function () {
el.remove();
yAxisDiv.remove();
});
describe('render Method', function () {