Skip to content

Commit dd842bd

Browse files
committed
add relayout jasmine tests to modebar
1 parent 154431f commit dd842bd

File tree

1 file changed

+76
-1
lines changed

1 file changed

+76
-1
lines changed

test/jasmine/tests/modebar_test.js

+76-1
Original file line numberDiff line numberDiff line change
@@ -1435,7 +1435,7 @@ describe('ModeBar', function() {
14351435
});
14361436
});
14371437

1438-
describe('modebar styling', function() {
1438+
describe('modebar relayout', function() {
14391439
var gd;
14401440
var colors = ['rgba(128, 128, 128, 0.7)', 'rgba(255, 0, 128, 0.2)'];
14411441
var targetBtn = 'pan2d';
@@ -1559,6 +1559,81 @@ describe('ModeBar', function() {
15591559
})
15601560
.then(done, done.fail);
15611561
});
1562+
1563+
it('add and remove predefined shape drawing and hover buttons via layout.modebar.buttonstoadd', function(done) {
1564+
function countButtons() {
1565+
var modeBarEl = gd._fullLayout._modeBar.element;
1566+
return d3Select(modeBarEl).selectAll('a.modebar-btn').size();
1567+
}
1568+
1569+
var initial = 10;
1570+
Plotly.newPlot(gd, [{y: [1, 2]}], {})
1571+
.then(function() {
1572+
expect(countButtons()).toBe(initial);
1573+
1574+
return Plotly.relayout(gd, 'modebar.buttonstoadd', [
1575+
'drawline',
1576+
'drawopenpath',
1577+
'drawclosedpath',
1578+
'drawcircle',
1579+
'drawrect',
1580+
'eraseshape'
1581+
].join('+'));
1582+
})
1583+
.then(function() {
1584+
expect(countButtons()).toBe(initial + 6);
1585+
1586+
return Plotly.relayout(gd, 'modebar.buttonstoadd', '');
1587+
})
1588+
.then(function() {
1589+
expect(countButtons()).toBe(initial);
1590+
1591+
return Plotly.relayout(gd, 'modebar.buttonstoadd', [
1592+
'hovercompare',
1593+
'hoverclosest',
1594+
'togglespikelines'
1595+
].join('+'));
1596+
})
1597+
.then(function() {
1598+
expect(countButtons()).toBe(initial + 3);
1599+
1600+
return Plotly.relayout(gd, 'modebar.buttonstoadd', '');
1601+
})
1602+
.then(function() {
1603+
expect(countButtons()).toBe(initial);
1604+
1605+
return Plotly.relayout(gd, 'modebar.buttonstoadd', [
1606+
'v1hovermode',
1607+
'togglespikelines'
1608+
].join('+'));
1609+
})
1610+
.then(function() {
1611+
expect(countButtons()).toBe(initial + 3);
1612+
1613+
return Plotly.relayout(gd, 'modebar.buttonstoadd', [
1614+
'v1hovermode',
1615+
'togglespikelines',
1616+
'togglehover',
1617+
'hovercompare',
1618+
'hoverclosest',
1619+
'eraseshape',
1620+
'eraseshape',
1621+
'eraseshape'
1622+
].join('+'));
1623+
})
1624+
.then(function() {
1625+
expect(countButtons()).toBe(initial + 4, 'skip duplicates');
1626+
1627+
return Plotly.relayout(gd, 'modebar.buttonstoadd', [
1628+
'drawline',
1629+
'invalid'
1630+
].join('+'));
1631+
})
1632+
.then(function() {
1633+
expect(countButtons()).toBe(initial + 1, 'skip invalid');
1634+
})
1635+
.then(done, done.fail);
1636+
});
15621637
});
15631638

15641639
describe('modebar html', function() {

0 commit comments

Comments
 (0)