Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions test/jasmine/tests/colorbar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,5 +524,44 @@ describe('Test colorbar:', function() {
.catch(failTest)
.then(done);
});

it('creates the same colorbars attributes in newPlot and react', function(done) {
var z = [[1, 10], [100, 1000]];

var expectedAttrs = [];
var actualAttrs = [];

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test looks great.
Non-blocking, but maybe you could add a getter function to avoid duplication:
Something like:

function pushItemsTo(a) {
    var colorbars = d3.select(gd).selectAll('.colorbar');
    colorbars.selectAll('.cbfill').each(function() {
        var attrsForElem = {};
        for(var i = 0; i < this.attributes.length; i++) {
            var attr = this.attributes.item(i);
            attrsForElem[attr.name] = attr.value;
        }
        a.push(attrsForElem);
    });
}

Plotly.newPlot(gd, [{type: 'contour', z: z}])
.then(function() {
    pushItemsTo(expectedAttrs);

    return Plotly.newPlot(gd, [{type: 'heatmap', z: z}])
    .then(function() {
        return Plotly.react(gd, [{type: 'contour', z: z}]);
    });
})
.then(function() {
    pushItemsTo(actualAttrs);

    expect(actualAttrs).toEqual(expectedAttrs);
})

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 🙂

Plotly.newPlot(gd, [{type: 'contour', z: z}])
.then(function() {
var colorbars = d3.select(gd).selectAll('.colorbar');
colorbars.selectAll('.cbfill').each(function() {
var attrsForElem = {};
for(var i = 0; i < this.attributes.length; i++) {
var attr = this.attributes.item(i);
attrsForElem[attr.name] = attr.value;
}
expectedAttrs.push(attrsForElem);
});

return Plotly.newPlot(gd, [{type: 'heatmap', z: z}])
.then(function() {
return Plotly.react(gd, [{type: 'contour', z: z}]);
});
})
.then(function() {
var colorbars = d3.select(gd).selectAll('.colorbar');
colorbars.selectAll('.cbfill').each(function() {
var attrsForElem = {};
for(var i = 0; i < this.attributes.length; i++) {
var attr = this.attributes.item(i);
attrsForElem[attr.name] = attr.value;
}
actualAttrs.push(attrsForElem);
});
expect(actualAttrs).toEqual(expectedAttrs);
})
.catch(failTest)
.then(done);
});
});
});