forked from LGSInnovations/react-sigplot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPipeLayer.test.js
172 lines (151 loc) · 6.67 KB
/
PipeLayer.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import React from 'react';
import { expect } from 'chai';
import sinon from 'sinon';
import { configure, mount } from 'enzyme';
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
import { Plot } from 'sigplot';
import { PipeLayer } from '../src/index';
configure({ adapter: new Adapter() });
window.alert = (msg) => {
console.log(msg);
};
describe('<PipeLayer />', () => {
beforeEach(() => {
sinon.spy(Plot.prototype, 'push');
sinon.spy(Plot.prototype, 'headermod');
sinon.spy(Plot.prototype, 'change_settings');
});
afterEach(() => {
Plot.prototype.push.restore();
Plot.prototype.headermod.restore();
Plot.prototype.change_settings.restore();
});
it('modifies the header on options prop change', () => {
const element = global.document.createElement('div');
const context = { plot: new Plot(element, {}) };
const options = { framesize: 1000, type: 2000, subsize: 1000 };
const component = mount(<PipeLayer data={[]} options={options} />, {
context,
});
expect(component.props().options).to.equal(options);
expect(Plot.prototype.push).to.have.property('callCount', 0);
expect(Plot.prototype.headermod).to.have.property('callCount', 0);
expect(Plot.prototype.change_settings).to.have.property('callCount', 1);
const newOptions = {
framesize: 2000,
};
component.setProps({ options: newOptions });
expect(component.props().options).to.equal(newOptions);
expect(Plot.prototype.push).to.have.property('callCount', 1);
expect(Plot.prototype.headermod).to.have.property('callCount', 1);
expect(Plot.prototype.change_settings).to.have.property('callCount', 2);
});
it('modifies settings on layerOptions prop change', () => {
const element = global.document.createElement('div');
const context = { plot: new Plot(element, {}) };
const layerOptions = { drawmode: 'scrolling' };
const options = { framesize: 1000, type: 2000, subsize: 1000 };
const component = mount(
<PipeLayer data={[]} options={options} layerOptions={layerOptions} />,
{ context }
);
expect(component.props().layerOptions).to.equal(layerOptions);
expect(Plot.prototype.push).to.have.property('callCount', 0);
expect(Plot.prototype.headermod).to.have.property('callCount', 0);
expect(Plot.prototype.change_settings).to.have.property('callCount', 1);
expect(component.instance().plot._Gx.lyr).to.have.lengthOf(1);
expect(component.instance().plot._Gx.lyr[0].drawmode).to.equal(
layerOptions.drawmode
);
const newLayerOptions = { drawmode: 'righttoleft' };
component.setProps({ layerOptions: newLayerOptions });
expect(component.props().layerOptions).to.equal(newLayerOptions);
expect(Plot.prototype.push).to.have.property('callCount', 0);
expect(Plot.prototype.headermod).to.have.property('callCount', 0);
expect(Plot.prototype.change_settings).to.have.property('callCount', 1);
expect(component.instance().plot._Gx.lyr).to.have.lengthOf(1);
expect(component.instance().plot._Gx.lyr[0].drawmode).to.equal(
newLayerOptions.drawmode
);
});
it('pushes new data to plot on data prop change', () => {
const element = global.document.createElement('div');
const context = { plot: new Plot(element, {}) };
const twoDimensionalData = [];
const options = { framesize: 1000, type: 2000, subsize: 1000 };
const component = mount(
<PipeLayer data={twoDimensionalData} options={options} />,
{ context }
);
expect(component.props().data).to.equal(twoDimensionalData);
expect(component.instance().plot._Gx.all).to.equal(false);
expect(component.instance().plot._Gx.expand).to.equal(false);
expect(component.instance().plot._Gx.autol).to.equal(-1);
expect(component.instance().plot._Gx.lyr).to.have.lengthOf(1);
expect(component.instance().plot._Gx.lyr[0].hcb.subsize).to.equal(1000);
expect(component.instance().plot._Gx.lyr[0].hcb.type).to.equal(2000);
const tmp = new Float64Array(1000);
for (let i = 0; i < 1000; i++) {
expect(component.instance().plot._Gx.lyr[0].hcb.dview[i]).to.equal(
tmp[i]
);
}
let random = [];
for (let i = 0; i <= 1000; i += 1) {
random.push(i * 10);
}
component.setProps({ data: random });
expect(component.props().data).to.equal(random);
expect(component.instance().plot._Gx.all).to.equal(false);
expect(component.instance().plot._Gx.expand).to.equal(false);
expect(component.instance().plot._Gx.autol).to.equal(-1);
expect(component.instance().plot._Gx.lyr).to.have.lengthOf(1);
expect(component.instance().plot._Gx.lyr[0].hcb.subsize).to.equal(1000);
expect(component.instance().plot._Gx.lyr[0].hcb.type).to.equal(2000);
const tmp2 = new Float64Array(random);
for (let i = 0; i < 1000; i++) {
expect(component.instance().plot._Gx.lyr[0].hcb.dview[i]).to.equal(
tmp2[i]
);
}
});
it("doesn't replot the same data on data prop change", () => {
const element = global.document.createElement('div');
const context = { plot: new Plot(element, {}) };
let random = [];
for (let i = 0; i <= 1000; i += 1) {
random.push(i * 10);
}
const options = { framesize: 1000, type: 2000, subsize: 1000 };
const component = mount(<PipeLayer data={random} options={options} />, {
context,
});
expect(component.props().data).to.equal(random);
expect(component.instance().plot._Gx.all).to.equal(false);
expect(component.instance().plot._Gx.expand).to.equal(false);
expect(component.instance().plot._Gx.autol).to.equal(-1);
expect(component.instance().plot._Gx.lyr).to.have.lengthOf(1);
expect(component.instance().plot._Gx.lyr[0].hcb.subsize).to.equal(1000);
expect(component.instance().plot._Gx.lyr[0].hcb.type).to.equal(2000);
expect(Plot.prototype.push).to.have.property('callCount', 1);
for (let i = 0; i < 1000; i++) {
expect(component.instance().plot._Gx.lyr[0].hcb.dview[i]).to.equal(
random[i]
);
}
component.setProps({ data: random });
expect(component.props().data).to.equal(random);
expect(component.instance().plot._Gx.all).to.equal(false);
expect(component.instance().plot._Gx.expand).to.equal(false);
expect(component.instance().plot._Gx.autol).to.equal(-1);
expect(component.instance().plot._Gx.lyr).to.have.lengthOf(1);
expect(component.instance().plot._Gx.lyr[0].hcb.subsize).to.equal(1000);
expect(component.instance().plot._Gx.lyr[0].hcb.type).to.equal(2000);
expect(Plot.prototype.push).to.have.property('callCount', 1);
for (let i = 0; i < 1000; i++) {
expect(component.instance().plot._Gx.lyr[0].hcb.dview[i]).to.equal(
random[i]
);
}
});
});