Skip to content

Commit 42d76e0

Browse files
committed
Add test for editing legend
1 parent c0089ea commit 42d76e0

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

test/jasmine/tests/legend_test.js

+66
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ var helpers = require('@src/components/legend/helpers');
99
var anchorUtils = require('@src/components/legend/anchor_utils');
1010

1111
var d3 = require('d3');
12+
var fail = require('../assets/fail_test');
13+
var delay = require('../assets/delay');
1214
var createGraphDiv = require('../assets/create_graph_div');
1315
var destroyGraphDiv = require('../assets/destroy_graph_div');
1416
var customMatchers = require('../assets/custom_matchers');
@@ -882,4 +884,68 @@ describe('legend interaction', function() {
882884
.then(done);
883885
});
884886
});
887+
888+
describe('editable mode interactions', function() {
889+
var gd;
890+
var mock = {
891+
data: [{
892+
x: [1, 2, 3],
893+
y: [5, 4, 3]
894+
}, {
895+
x: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],
896+
y: [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9],
897+
transforms: [{
898+
type: 'groupby',
899+
groups: [1, 2, 1, 2, 3, 4, 3, 4, 5, 6, 5, 6, 7, 8]
900+
}]
901+
}],
902+
config: {editable: true}
903+
};
904+
905+
beforeEach(function(done) {
906+
gd = createGraphDiv();
907+
Plotly.plot(gd, Lib.extendDeep({}, mock)).then(done);
908+
});
909+
910+
afterEach(destroyGraphDiv);
911+
912+
function _setValue(index, str) {
913+
var item = d3.selectAll('text.legendtext')[0][index || 0];
914+
item.dispatchEvent(new MouseEvent('click'));
915+
return delay(20)().then(function() {
916+
var input = d3.select('.plugin-editable.editable');
917+
input.text(str);
918+
input.node().dispatchEvent(new KeyboardEvent('blur'));
919+
}).then(delay(20));
920+
}
921+
922+
it('sets and unsets trace group names', function(done) {
923+
// Set the name of the first trace:
924+
_setValue(0, 'foo').then(function() {
925+
expect(gd.data[0].name).toEqual('foo');
926+
}).then(function() {
927+
// Set the name of the third legend item:
928+
return _setValue(3, 'bar');
929+
}).then(function() {
930+
expect(gd.data[1].transforms[0].groupnames).toEqual([
931+
{name: 'bar', group: 3}
932+
]);
933+
}).then(function() {
934+
return _setValue(4, 'asdf');
935+
}).then(function() {
936+
expect(gd.data[1].transforms[0].groupnames).toEqual([
937+
{name: 'bar', group: 3},
938+
{name: 'asdf', group: 4}
939+
]);
940+
}).then(function() {
941+
// Unset the group names:
942+
return _setValue(3, '');
943+
}).then(function() {
944+
return _setValue(4, '');
945+
}).then(function() {
946+
// Verify the group names have been cleaned up:
947+
expect(gd.data[1].transforms[0].groupnames).toEqual([]);
948+
}).catch(fail).then(done);
949+
});
950+
});
885951
});

0 commit comments

Comments
 (0)