Skip to content

Commit 2d7d3da

Browse files
committed
test clicking shape legends
1 parent 786d9e6 commit 2d7d3da

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

test/jasmine/tests/legend_test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,6 +1740,13 @@ describe('legend interaction', function() {
17401740
};
17411741
}
17421742

1743+
function assertVisibleShapes(expectation) {
1744+
return function() {
1745+
var actual = extractVisibilities(gd._fullLayout.shapes);
1746+
expect(actual).toEqual(expectation);
1747+
};
1748+
}
1749+
17431750
describe('for regular traces', function() {
17441751
beforeEach(function(done) {
17451752
Plotly.newPlot(gd, [
@@ -1782,6 +1789,34 @@ describe('legend interaction', function() {
17821789
});
17831790
});
17841791

1792+
describe('click shape legends', function() {
1793+
beforeEach(function(done) {
1794+
Plotly.newPlot(gd, [], {
1795+
shapes: [
1796+
{showlegend: true, type: 'line', xref: 'paper', yref: 'paper', x0: 0.1, y0: 0.2, x1: 0.2, y1: 0.1, visible: false},
1797+
{showlegend: true, type: 'line', xref: 'paper', yref: 'paper', x0: 0.3, y0: 0.4, x1: 0.4, y1: 0.3, visible: 'legendonly'},
1798+
{showlegend: true, type: 'line', xref: 'paper', yref: 'paper', x0: 0.5, y0: 0.6, x1: 0.6, y1: 0.5}
1799+
]
1800+
}).then(done);
1801+
});
1802+
1803+
it('clicking once toggles legendonly -> true', function(done) {
1804+
Promise.resolve()
1805+
.then(assertVisibleShapes([false, 'legendonly', true]))
1806+
.then(click(0))
1807+
.then(assertVisibleShapes([false, true, true]))
1808+
.then(done, done.fail);
1809+
});
1810+
1811+
it('clicking once toggles true -> legendonly', function(done) {
1812+
Promise.resolve()
1813+
.then(assertVisibleShapes([false, 'legendonly', true]))
1814+
.then(click(1))
1815+
.then(assertVisibleShapes([false, 'legendonly', 'legendonly']))
1816+
.then(done, done.fail);
1817+
});
1818+
});
1819+
17851820
describe('legendgroup visibility', function() {
17861821
beforeEach(function(done) {
17871822
Plotly.newPlot(gd, [{

0 commit comments

Comments
 (0)