1
- import React from 'react' ;
2
- import { expect } from 'chai' ;
3
- import sinon from 'sinon' ;
4
- import { configure , mount } from 'enzyme' ;
5
- import Adapter from 'enzyme-adapter-react-16' ;
6
- import toJson from 'enzyme-to-json' ;
7
- import { Plot } from 'sigplot' ;
8
- import { ArrayLayer } from '../src/index.js' ;
9
-
10
- configure ( { adapter : new Adapter ( ) } )
11
-
12
- window . alert = ( msg ) => { console . log ( msg ) } ;
13
-
14
- describe ( '<ArrayLayer />' , ( ) => {
1
+ import React from "react" ;
2
+ import { expect } from "chai" ;
3
+ import sinon from "sinon" ;
4
+ import { configure , mount } from "enzyme" ;
5
+ import Adapter from "enzyme-adapter-react-16" ;
6
+ import toJson from "enzyme-to-json" ;
7
+ import { Plot } from "sigplot" ;
8
+ import { ArrayLayer } from "../src/index.js" ;
9
+
10
+ configure ( { adapter : new Adapter ( ) } ) ;
11
+
12
+ window . alert = ( msg ) => {
13
+ console . log ( msg ) ;
14
+ } ;
15
+
16
+ describe ( "<ArrayLayer />" , ( ) => {
15
17
beforeEach ( ( ) => {
16
- sinon . spy ( Plot . prototype , ' overlay_array' ) ;
17
- sinon . spy ( Plot . prototype , ' reload' ) ;
18
- sinon . spy ( Plot . prototype , ' headermod' ) ;
18
+ sinon . spy ( Plot . prototype , " overlay_array" ) ;
19
+ sinon . spy ( Plot . prototype , " reload" ) ;
20
+ sinon . spy ( Plot . prototype , " headermod" ) ;
19
21
} ) ;
20
22
21
23
afterEach ( ( ) => {
@@ -24,58 +26,67 @@ describe('<ArrayLayer />', () => {
24
26
Plot . prototype . headermod . restore ( ) ;
25
27
} ) ;
26
28
27
- it ( ' reloads plot on data prop change' , ( ) => {
29
+ it ( " reloads plot on data prop change" , ( ) => {
28
30
const options = { } ;
29
31
const element = global . document . createElement ( "div" ) ;
30
32
const context = { plot : new Plot ( element , options ) } ;
31
33
32
34
let random = [ ] ;
33
35
for ( let i = 0 ; i <= 1000 ; i += 1 ) {
34
- random . push ( i * 10 ) ;
36
+ random . push ( i * 10 ) ;
35
37
}
36
38
const oneDimensionalData = random ;
37
39
38
- const component = mount (
39
- < ArrayLayer data = { oneDimensionalData } /> ,
40
- { context }
41
- ) ;
40
+ const component = mount ( < ArrayLayer data = { oneDimensionalData } /> , {
41
+ context,
42
+ } ) ;
42
43
43
44
expect ( component . props ( ) . data ) . to . equal ( oneDimensionalData ) ;
44
45
expect ( component . instance ( ) . plot ) . to . not . be . undefined ;
45
46
expect ( component . instance ( ) . plot . _Gx . all ) . to . equal ( false ) ;
46
47
expect ( component . instance ( ) . plot . _Gx . expand ) . to . equal ( false ) ;
47
48
expect ( component . instance ( ) . plot . _Gx . autol ) . to . equal ( - 1 ) ;
48
49
expect ( component . instance ( ) . plot . _Gx . lyr ) . to . have . lengthOf ( 1 ) ;
49
- expect ( component . instance ( ) . plot . _Gx . lyr [ 0 ] . options ) . to . be . an ( 'object' ) . that . is . empty ;
50
- expect ( component . instance ( ) . plot . _Gx . lyr [ 0 ] . ypoint ) . to . have . lengthOf ( oneDimensionalData . length ) ;
51
- expect ( component . instance ( ) . plot . _Gx . lyr [ 0 ] . ypoint ) . to . eql ( new Float64Array ( oneDimensionalData ) ) ;
50
+ expect ( component . instance ( ) . plot . _Gx . lyr [ 0 ] . options ) . to . be . an ( "object" ) . that
51
+ . is . empty ;
52
+ expect ( component . instance ( ) . plot . _Gx . lyr [ 0 ] . ypoint ) . to . have . lengthOf (
53
+ oneDimensionalData . length
54
+ ) ;
55
+ expect ( component . instance ( ) . plot . _Gx . lyr [ 0 ] . ypoint ) . to . eql (
56
+ new Float64Array ( oneDimensionalData )
57
+ ) ;
52
58
53
59
let random2 = [ ] ;
54
60
for ( let i = 0 ; i <= 1000 ; i += 1 ) {
55
- random2 . push ( i * 10 ) ;
61
+ random2 . push ( i * 10 ) ;
56
62
}
57
63
const oneDimensionalData2 = random2 ;
58
64
59
- component . setProps ( { data : random2 } ) ;
65
+ component . setProps ( { data : random2 } ) ;
60
66
expect ( component . props ( ) . data ) . to . equal ( oneDimensionalData2 ) ;
61
67
expect ( component . instance ( ) . plot ) . to . not . be . undefined ;
62
68
expect ( component . instance ( ) . plot . _Gx . all ) . to . equal ( false ) ;
63
69
expect ( component . instance ( ) . plot . _Gx . expand ) . to . equal ( false ) ;
64
70
expect ( component . instance ( ) . plot . _Gx . autol ) . to . equal ( - 1 ) ;
65
71
expect ( component . instance ( ) . plot . _Gx . lyr ) . to . have . lengthOf ( 1 ) ;
66
- expect ( component . instance ( ) . plot . _Gx . lyr [ 0 ] . options ) . to . be . an ( 'object' ) . that . is . empty ;
67
- expect ( component . instance ( ) . plot . _Gx . lyr [ 0 ] . ypoint ) . to . have . lengthOf ( oneDimensionalData2 . length ) ;
68
- expect ( component . instance ( ) . plot . _Gx . lyr [ 0 ] . ypoint ) . to . eql ( new Float64Array ( oneDimensionalData2 ) ) ;
72
+ expect ( component . instance ( ) . plot . _Gx . lyr [ 0 ] . options ) . to . be . an ( "object" ) . that
73
+ . is . empty ;
74
+ expect ( component . instance ( ) . plot . _Gx . lyr [ 0 ] . ypoint ) . to . have . lengthOf (
75
+ oneDimensionalData2 . length
76
+ ) ;
77
+ expect ( component . instance ( ) . plot . _Gx . lyr [ 0 ] . ypoint ) . to . eql (
78
+ new Float64Array ( oneDimensionalData2 )
79
+ ) ;
69
80
} ) ;
70
81
71
- it ( ' doesn\ 't do anything when props change but remain the same' , ( ) => {
72
- const options = { framesize : 1000 } ;
82
+ it ( " doesn't do anything when props change but remain the same" , ( ) => {
83
+ const options = { framesize : 1000 } ;
73
84
const element = global . document . createElement ( "div" ) ;
74
85
const context = { plot : new Plot ( element , options ) } ;
75
86
76
87
let random = [ ] ;
77
88
for ( let i = 0 ; i <= 1000 ; i += 1 ) {
78
- random . push ( i * 10 ) ;
89
+ random . push ( i * 10 ) ;
79
90
}
80
91
const oneDimensionalData = random ;
81
92
@@ -90,19 +101,19 @@ describe('<ArrayLayer />', () => {
90
101
expect ( component . instance ( ) . plot . _Gx . lyr ) . to . have . lengthOf ( 1 ) ;
91
102
expect ( component . instance ( ) . plot . _Gx . lyr [ 0 ] . size ) . to . equal ( 1000 ) ;
92
103
93
- component . setProps ( { layerOptions : options } ) ;
104
+ component . setProps ( { layerOptions : options } ) ;
94
105
expect ( component . props ( ) . layerOptions ) . to . equal ( options ) ;
95
106
expect ( component . instance ( ) . plot . _Gx . lyr [ 0 ] . size ) . to . equal ( 1000 ) ;
96
107
} ) ;
97
108
98
- it ( ' changes layer settings on layerOptions prop change' , ( ) => {
99
- const options = { framesize : 1000 } ;
109
+ it ( " changes layer settings on layerOptions prop change" , ( ) => {
110
+ const options = { framesize : 1000 } ;
100
111
const element = global . document . createElement ( "div" ) ;
101
112
const context = { plot : new Plot ( element , options ) } ;
102
113
103
114
let random = [ ] ;
104
115
for ( let i = 0 ; i <= 1000 ; i += 1 ) {
105
- random . push ( i * 10 ) ;
116
+ random . push ( i * 10 ) ;
106
117
}
107
118
const oneDimensionalData = random ;
108
119
@@ -117,21 +128,21 @@ describe('<ArrayLayer />', () => {
117
128
expect ( component . instance ( ) . plot . _Gx . lyr ) . to . have . lengthOf ( 1 ) ;
118
129
expect ( component . instance ( ) . plot . _Gx . lyr [ 0 ] . size ) . to . equal ( 1000 ) ;
119
130
120
- const newOptions = { framesize : 50 } ;
131
+ const newOptions = { framesize : 50 } ;
121
132
122
- component . setProps ( { layerOptions : newOptions } ) ;
133
+ component . setProps ( { layerOptions : newOptions } ) ;
123
134
expect ( component . props ( ) . layerOptions ) . to . equal ( newOptions ) ;
124
135
expect ( component . instance ( ) . plot . _Gx . lyr [ 0 ] . size ) . to . equal ( 50 ) ;
125
136
} ) ;
126
137
127
- it ( ' headermods plot on options prop change' , ( ) => {
138
+ it ( " headermods plot on options prop change" , ( ) => {
128
139
const options = { } ;
129
140
const element = global . document . createElement ( "div" ) ;
130
141
const context = { plot : new Plot ( element , options ) } ;
131
142
132
143
let random = [ ] ;
133
144
for ( let i = 0 ; i <= 1000 ; i += 1 ) {
134
- random . push ( i * 10 ) ;
145
+ random . push ( i * 10 ) ;
135
146
}
136
147
const oneDimensionalData = random ;
137
148
@@ -146,21 +157,25 @@ describe('<ArrayLayer />', () => {
146
157
expect ( component . instance ( ) . plot . _Gx . expand ) . to . equal ( false ) ;
147
158
expect ( component . instance ( ) . plot . _Gx . autol ) . to . equal ( - 1 ) ;
148
159
expect ( component . instance ( ) . plot . _Gx . lyr ) . to . have . lengthOf ( 1 ) ;
149
- expect ( component . instance ( ) . plot . _Gx . lyr [ 0 ] . options ) . to . be . an ( 'object' ) . that . is . empty ;
150
- expect ( component . instance ( ) . plot . _Gx . lyr [ 0 ] . ypoint ) . to . have . lengthOf ( oneDimensionalData . length ) ;
151
- expect ( component . instance ( ) . plot . _Gx . lyr [ 0 ] . ypoint ) . to . eql ( new Float64Array ( oneDimensionalData ) ) ;
152
- expect ( Plot . prototype . overlay_array ) . to . have . property ( 'callCount' , 1 ) ;
153
- expect ( Plot . prototype . reload ) . to . have . property ( 'callCount' , 0 ) ;
154
- expect ( Plot . prototype . headermod ) . to . have . property ( 'callCount' , 0 ) ;
160
+ expect ( component . instance ( ) . plot . _Gx . lyr [ 0 ] . options ) . to . be . an ( "object" ) . that
161
+ . is . empty ;
162
+ expect ( component . instance ( ) . plot . _Gx . lyr [ 0 ] . ypoint ) . to . have . lengthOf (
163
+ oneDimensionalData . length
164
+ ) ;
165
+ expect ( component . instance ( ) . plot . _Gx . lyr [ 0 ] . ypoint ) . to . eql (
166
+ new Float64Array ( oneDimensionalData )
167
+ ) ;
168
+ expect ( Plot . prototype . overlay_array ) . to . have . property ( "callCount" , 1 ) ;
169
+ expect ( Plot . prototype . reload ) . to . have . property ( "callCount" , 0 ) ;
170
+ expect ( Plot . prototype . headermod ) . to . have . property ( "callCount" , 0 ) ;
155
171
156
- const newOptions = { ' subsize' : 100 } ;
172
+ const newOptions = { subsize : 100 } ;
157
173
158
- component . setProps ( { options : newOptions } ) ;
174
+ component . setProps ( { options : newOptions } ) ;
159
175
expect ( component . props ( ) . options . subsize ) . to . equal ( 100 ) ;
160
176
expect ( component . instance ( ) . plot . _Gx . lyr [ 0 ] . hcb . subsize ) . to . equal ( 100 ) ;
161
- expect ( Plot . prototype . overlay_array ) . to . have . property ( ' callCount' , 1 ) ;
162
- expect ( Plot . prototype . reload ) . to . have . property ( ' callCount' , 0 ) ;
163
- expect ( Plot . prototype . headermod ) . to . have . property ( ' callCount' , 1 ) ;
177
+ expect ( Plot . prototype . overlay_array ) . to . have . property ( " callCount" , 1 ) ;
178
+ expect ( Plot . prototype . reload ) . to . have . property ( " callCount" , 0 ) ;
179
+ expect ( Plot . prototype . headermod ) . to . have . property ( " callCount" , 1 ) ;
164
180
} ) ;
165
-
166
181
} ) ;
0 commit comments