Skip to content

Commit 313976d

Browse files
committed
Legend: test defaults for horizontal legends
1 parent c1632d4 commit 313976d

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

test/jasmine/tests/legend_test.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var Plots = require('@src/plots/plots');
2+
var Lib = require('@src/lib');
23

34
var Legend = require('@src/components/legend');
45
var getLegendData = require('@src/components/legend/get_legend_data');
@@ -65,6 +66,46 @@ describe('Test legend:', function() {
6566
expect(layoutOut.legend.traceorder).toEqual('grouped+reversed');
6667
});
6768

69+
it('should default orientation to vertical', function() {
70+
supplyLayoutDefaults(layoutIn, layoutOut, []);
71+
expect(layoutOut.legend.orientation).toEqual('v');
72+
});
73+
74+
describe('for horizontal legends', function() {
75+
var layoutInForHorizontalLegends;
76+
77+
beforeEach(function() {
78+
layoutInForHorizontalLegends = Lib.extendDeep({
79+
legend: {
80+
orientation: 'h'
81+
},
82+
xaxis: {
83+
rangeslider: {
84+
visible: false
85+
}
86+
}
87+
}, layoutIn);
88+
});
89+
90+
it('should default position to bottom left', function() {
91+
supplyLayoutDefaults(layoutInForHorizontalLegends, layoutOut, []);
92+
expect(layoutOut.legend.x).toEqual(0);
93+
expect(layoutOut.legend.xanchor).toEqual('left');
94+
expect(layoutOut.legend.y).toEqual(-0.1);
95+
expect(layoutOut.legend.yanchor).toEqual('top');
96+
});
97+
98+
it('should default position to top left if a range slider present', function() {
99+
var mockLayoutIn = Lib.extendDeep({}, layoutInForHorizontalLegends);
100+
mockLayoutIn.xaxis.rangeslider.visible = true;
101+
102+
supplyLayoutDefaults(mockLayoutIn, layoutOut, []);
103+
expect(layoutOut.legend.x).toEqual(0);
104+
expect(layoutOut.legend.xanchor).toEqual('left');
105+
expect(layoutOut.legend.y).toEqual(1.1);
106+
expect(layoutOut.legend.yanchor).toEqual('bottom');
107+
});
108+
});
68109
});
69110

70111
describe('getLegendData', function() {

0 commit comments

Comments
 (0)