Skip to content

Commit 15986b8

Browse files
committed
jasmine tests for editable shape legends
1 parent 5c0168c commit 15986b8

File tree

1 file changed

+63
-2
lines changed

1 file changed

+63
-2
lines changed

test/jasmine/tests/legend_test.js

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,6 +1674,67 @@ describe('legend interaction', function() {
16741674
});
16751675
});
16761676

1677+
describe('editable mode interactions for shape legends', function() {
1678+
var gd;
1679+
1680+
var mock = {
1681+
data: [],
1682+
layout: {
1683+
shapes: [
1684+
{showlegend: true, type: 'line', xref: 'paper', yref: 'paper', x0: 0.1, y0: 0.2, x1: 0.2, y1: 0.1},
1685+
{showlegend: true, type: 'line', xref: 'paper', yref: 'paper', x0: 0.3, y0: 0.4, x1: 0.4, y1: 0.3},
1686+
{showlegend: true, type: 'line', xref: 'paper', yref: 'paper', x0: 0.5, y0: 0.6, x1: 0.6, y1: 0.5},
1687+
{showlegend: true, type: 'line', xref: 'paper', yref: 'paper', x0: 0.7, y0: 0.8, x1: 0.8, y1: 0.7},
1688+
{showlegend: true, type: 'line', xref: 'paper', yref: 'paper', x0: 0.9, y0: 1.0, x1: 1.0, y1: 0.9}
1689+
]
1690+
},
1691+
config: {editable: true}
1692+
};
1693+
1694+
beforeEach(function(done) {
1695+
gd = createGraphDiv();
1696+
Plotly.newPlot(gd, Lib.extendDeep({}, mock)).then(done);
1697+
});
1698+
1699+
afterEach(destroyGraphDiv);
1700+
1701+
function _setValue(index, str) {
1702+
var item = d3SelectAll('text.legendtext')[0][index || 0];
1703+
item.dispatchEvent(new MouseEvent('click'));
1704+
return delay(20)().then(function() {
1705+
var input = d3Select('.plugin-editable.editable');
1706+
input.text(str);
1707+
input.node().dispatchEvent(new KeyboardEvent('blur'));
1708+
}).then(delay(20));
1709+
}
1710+
1711+
function assertLabels(expected) {
1712+
var labels = [];
1713+
d3SelectAll('text.legendtext').each(function() {
1714+
labels.push(this.textContent);
1715+
});
1716+
expect(labels).toEqual(expected);
1717+
}
1718+
1719+
it('sets and unsets shape group names', function(done) {
1720+
assertLabels(['shape 0', 'shape 1', 'shape 2', 'shape 3', 'shape 4']);
1721+
// Set the name of the first shape:
1722+
_setValue(0, 'foo').then(function() {
1723+
expect(gd.layout.shapes[0].name).toEqual('foo');
1724+
// labels shorter than half the longest get padded with spaces to match the longest length
1725+
assertLabels(['foo ', 'shape 1', 'shape 2', 'shape 3', 'shape 4']);
1726+
1727+
// Set the name of the third legend item:
1728+
return _setValue(3, 'barbar');
1729+
}).then(function() {
1730+
expect(gd.layout.shapes[3].name).toEqual('barbar');
1731+
assertLabels(['foo ', 'shape 1', 'shape 2', 'barbar', 'shape 4']);
1732+
1733+
return _setValue(2, 'asdf');
1734+
}).then(done, done.fail);
1735+
});
1736+
});
1737+
16771738
describe('staticPlot', function() {
16781739
var gd;
16791740

@@ -1953,7 +2014,7 @@ describe('legend interaction', function() {
19532014
.then(done, done.fail);
19542015
});
19552016

1956-
it('double-clicking isolates a visible trace ', function(done) {
2017+
it('double-clicking isolates a visible shape', function(done) {
19572018
Promise.resolve()
19582019
.then(click(0))
19592020
.then(assertVisibleShapes([false, true, true]))
@@ -1962,7 +2023,7 @@ describe('legend interaction', function() {
19622023
.then(done, done.fail);
19632024
});
19642025

1965-
it('double-clicking an isolated trace shows all non-hidden traces', function(done) {
2026+
it('double-clicking an isolated trace shows all non-hidden shapes', function(done) {
19662027
Promise.resolve()
19672028
.then(click(0, 2))
19682029
.then(assertVisibleShapes([false, true, true]))

0 commit comments

Comments
 (0)