8000 Clean data when addTraces is called by mdtusz · Pull Request #140 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

Clean data when addTraces is called #140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 23, 2015
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
8000
Diff view
Prev Previous commit
Update tests on addTraces
  • Loading branch information
mdtusz committed Dec 22, 2015
commit ca1b363b8b5a92483d616b3e5d0770cf96a5e126
61 changes: 19 additions & 42 deletions test/jasmine/tests/plot_api_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,7 @@ describe('Test graph_obj', function () {
var gd;

beforeEach(function () {
gd = {
data: [
{'name': 'a'},
{'name': 'b'}
]
};
gd = { data: [{'name': 'a'}, {'name': 'b'}] };
spyOn(Plotly, 'redraw');
spyOn(Plotly, 'moveTraces');
});
Expand All @@ -147,15 +142,15 @@ describe('Test graph_obj', function () {
var expected = JSON.parse(JSON.stringify(gd));
expect(function () {
Plotly.addTraces(gd, 1, 2);
}).toThrow(new Error('all values in traces array must be non-array objects'));
}).toThrowError(Error, 'all values in traces array must be non-array objects');

expect(function () {
Plotly.addTraces(gd, [{}, 4], 2);
}).toThrow(new Error('all values in traces array must be non-array objects'));
}).toThrowError(Error, 'all values in traces array must be non-array objects');

expect(function () {
Plotly.addTraces(gd, [{}, []], 2);
}).toThrow(new Error('all values in traces array must be non-array objects'));
}).toThrowError(Error, 'all values in traces array must be non-array objects');

// make sure we didn't muck with gd.data if things failed!
expect(gd).toEqual(expected);
Expand All @@ -166,7 +161,7 @@ describe('Test graph_obj', function () {

expect(function () {
Plotly.addTraces(gd, [{}, {}], 2);
}).toThrow(new Error('if indices is specified, traces.length must equal indices.length'));
}).toThrowError(Error, 'if indices is specified, traces.length must equal indices.length');

});

Expand All @@ -182,59 +177,41 @@ describe('Test graph_obj', function () {
});

it('should work when newIndices is undefined', function () {
var expectedData = [
{'name': 'a'},
{'name': 'b'},
{'name': 'c'},
{'name': 'd'}
];

Plotly.addTraces(gd, [{'name': 'c'}, {'name': 'd'}]);
expect(gd.data).toEqual(expectedData);
expect(gd.data[2].name).toBeDefined();
expect(gd.data[2].uid).toBeDefined();
expect(gd.data[3].name).toBeDefined();
expect(gd.data[3].uid).toBeDefined();
expect(Plotly.redraw).toHaveBeenCalled();
expect(Plotly.moveTraces).not.toHaveBeenCalled();

});

it('should work when newIndices is defined', function () {
var expectedData = [
{'name': 'a'},
{'name': 'b'},
{'name': 'c'},
{'name': 'd'}
];

Plotly.addTraces(gd, [{'name': 'c'}, {'name': 'd'}], [1, 3]);
expect(gd.data).toEqual(expectedData);
expect(gd.data[2].name).toBeDefined();
expect(gd.data[2].uid).toBeDefined();
expect(gd.data[3].name).toBeDefined();
expect(gd.data[3].uid).toBeDefined();
expect(Plotly.redraw).not.toHaveBeenCalled();
expect(Plotly.moveTraces).toHaveBeenCalledWith(gd, [-2, -1], [1, 3]);

});

it('should work when newIndices has negative indices', function () {
var expectedData = [
{'name': 'a'},
{'name': 'b'},
{'name': 'c'},
{'name': 'd'}
];

Plotly.addTraces(gd, [{'name': 'c'}, {'name': 'd'}], [-3, -1]);
expect(gd.data).toEqual(expectedData);
expect(gd.data[2].name).toBeDefined();
expect(gd.data[2].uid).toBeDefined();
expect(gd.data[3].name).toBeDefined();
expect(gd.data[3].uid).toBeDefined();
expect(Plotly.redraw).not.toHaveBeenCalled();
expect(Plotly.moveTraces).toHaveBeenCalledWith(gd, [-2, -1], [-3, -1]);

});

it('should work when newIndices is an integer', function () {
var expectedData = [
{'name': 'a'},
{'name': 'b'},
{'name': 'c'}
];

Plotly.addTraces(gd, {'name': 'c'}, 0);
expect(gd.data).toEqual(expectedData);
expect(gd.data[2].name).toBeDefined();
expect(gd.data[2].uid).toBeDefined();
expect(Plotly.redraw).not.toHaveBeenCalled();
expect(Plotly.moveTraces).toHaveBeenCalledWith(gd, [-1], [0]);

Expand Down
0