Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fixup legend test:
- make sure to extend the mock before each test case
- fix typo (addTrace -> addTraces)
  • Loading branch information
etpinard committed Mar 30, 2016
commit 927af3b0d889bccc170af2905b461e0c5460a253
26 changes: 17 additions & 9 deletions test/jasmine/tests/legend_scroll_test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var Plotly = require('@lib/index');
var Lib = require('@src/lib');

var createGraph = require('../assets/create_graph_div');
var destroyGraph = require('../assets/destroy_graph_div');
var getBBox = require('../assets/get_bbox');
Expand Down Expand Up @@ -26,10 +28,15 @@ describe('The legend', function() {


describe('when plotted with many traces', function() {
beforeEach(function() {
beforeEach(function(done) {
gd = createGraph();
Plotly.plot(gd, mock.data, mock.layout);
legend = document.getElementsByClassName('legend')[0];

var mockCopy = Lib.extendDeep({}, mock);

Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(function() {
legend = document.getElementsByClassName('legend')[0];
done();
});
});

afterEach(destroyGraph);
Expand Down Expand Up @@ -96,7 +103,7 @@ describe('The legend', function() {
it('should resize when relayout\'ed with new height', function(done) {
var origLegendHeight = getBBox(legend).height;

Plotly.relayout(gd, {'height': gd._fullLayout.height/2}).then(function() {
Plotly.relayout(gd, 'height', gd._fullLayout.height / 2).then(function() {
var legendHeight = getBBox(legend).height;

//legend still exists and not duplicated
Expand All @@ -114,7 +121,7 @@ describe('The legend', function() {


describe('when plotted with few traces', function() {
var gd, legend;
var gd;

beforeEach(function() {
gd = createGraph();
Expand Down Expand Up @@ -147,14 +154,15 @@ describe('The legend', function() {
});

it('should resize when traces added', function(done) {
legend = document.getElementsByClassName('legend')[0];
var origLegendHeight = getBBox(legend).height;
var origLegend = document.getElementsByClassName('legend')[0];
var origLegendHeight = getBBox(origLegend).height;

Plotly.addTrace(gd, { x: [1,2,3], y: [4,3,2], name: 'Test2' }).then(function() {
Plotly.addTraces(gd, { x: [1,2,3], y: [4,3,2], name: 'Test2' }).then(function() {
var legend = document.getElementsByClassName('legend')[0];
var legendHeight = getBBox(legend).height;

// clippath resized to show new trace
expect(+legendHeight).toBeCloseTo(+origLegendHeight+18, 0);
expect(+legendHeight).toBeCloseTo(+origLegendHeight + 19, 0);

done();
});
Expand Down