1
- import { transformMultDimArray , getMergeRanges , createHeadings , createWorksheet } from 'dash-table/components/Export/utils' ;
1
+ import { transformMultiDimArray , getMergeRanges , createHeadings , createWorksheet } from 'dash-table/components/Export/utils' ;
2
2
import * as R from 'ramda' ;
3
+ import { ExportHeaders } from 'dash-table/components/Table/props' ;
3
4
4
5
describe ( 'export' , ( ) => {
5
6
6
- describe ( 'transformMultDimArray ' , ( ) => {
7
+ describe ( 'transformMultiDimArray ' , ( ) => {
7
8
it ( 'array with only strings' , ( ) => {
8
9
const testedArray = [ ] ;
9
- const transformedArray = transformMultDimArray ( testedArray , 0 ) ;
10
+ const transformedArray = transformMultiDimArray ( testedArray , 0 ) ;
10
11
const expectedArray = [ ] ;
11
12
expect ( transformedArray ) . to . deep . equal ( expectedArray ) ;
12
13
} ) ;
13
14
it ( 'array with only strings' , ( ) => {
14
15
const testedArray = [ 'a' , 'b' , 'c' , 'd' ] ;
15
- const transformedArray = transformMultDimArray ( testedArray , 0 ) ;
16
+ const transformedArray = transformMultiDimArray ( testedArray , 0 ) ;
16
17
const expectedArray = [ [ 'a' ] , [ 'b' ] , [ 'c' ] , [ 'd' ] ] ;
17
18
expect ( transformedArray ) . to . deep . equal ( expectedArray ) ;
18
19
} ) ;
19
20
it ( 'array with strings and strings array with same length' , ( ) => {
20
21
const testedArray = [ 'a' , [ 'b' , 'c' ] , [ 'b' , 'd' ] ] ;
21
- const transformedArray = transformMultDimArray ( testedArray , 2 ) ;
22
+ const transformedArray = transformMultiDimArray ( testedArray , 2 ) ;
22
23
const expectedArray = [ [ 'a' , 'a' ] , [ 'b' , 'c' ] , [ 'b' , 'd' ] ] ;
23
24
expect ( transformedArray ) . to . deep . equal ( expectedArray ) ;
24
25
} ) ;
25
26
it ( '2D strings array' , ( ) => {
26
27
const testedArray = [ [ 'a' , 'b' , 'c' ] , [ 'b' , 'c' , 'd' ] , [ 'b' , 'd' , 'a' ] ] ;
27
- const transformedArray = transformMultDimArray ( testedArray , 3 ) ;
28
+ const transformedArray = transformMultiDimArray ( testedArray , 3 ) ;
28
29
const expectedArray = [ [ 'a' , 'b' , 'c' ] , [ 'b' , 'c' , 'd' ] , [ 'b' , 'd' , 'a' ] ] ;
29
30
expect ( transformedArray ) . to . deep . equal ( expectedArray ) ;
30
31
31
32
} ) ;
32
33
it ( 'multidimensional array' , ( ) => {
33
34
const testedArray = [ [ 'a' , 'b' ] , [ 'b' , 'c' , 'd' ] , [ 'a' , 'b' , 'd' , 'a' ] ] ;
34
- const transformedArray = transformMultDimArray ( testedArray , 4 ) ;
35
+ const transformedArray = transformMultiDimArray ( testedArray , 4 ) ;
35
36
const expectedArray = [ [ 'a' , 'b' , '' , '' ] , [ 'b' , 'c' , 'd' , '' ] , [ 'a' , 'b' , 'd' , 'a' ] ] ;
36
37
expect ( transformedArray ) . to . deep . equal ( expectedArray ) ;
37
38
38
39
} ) ;
39
40
it ( 'multidimensional array with strings' , ( ) => {
40
41
const testedArray = [ 'rows' , [ 'a' , 'b' ] , [ 'b' , 'c' , 'd' ] , [ 'a' , 'b' , 'd' , 'a' ] ] ;
41
- const transformedArray = transformMultDimArray ( testedArray , 4 ) ;
42
+ const transformedArray = transformMultiDimArray ( testedArray , 4 ) ;
42
43
const expectedArray = [ [ 'rows' , 'rows' , 'rows' , 'rows' ] , [ 'a' , 'b' , '' , '' ] , [ 'b' , 'c' , 'd' , '' ] , [ 'a' , 'b' , 'd' , 'a' ] ] ;
43
44
expect ( transformedArray ) . to . deep . equal ( expectedArray ) ;
44
45
} ) ;
@@ -210,20 +211,24 @@ describe('export', () => {
210
211
} ) ;
211
212
212
213
describe ( 'createWorksheet ' , ( ) => {
213
- const Headings = [ [ 'rows' , 'rows' , 'b' ] ,
214
- [ 'rows' , 'c' , 'c' ] ,
215
- [ 'rows' , 'e' , 'f' ] ,
216
- [ 'rows' , 'rows' , 'rows' ] ] ;
214
+ const Headings = [
215
+ [ 'rows' , 'rows' , 'b' ] ,
216
+ [ 'rows' , 'c' , 'c' ] ,
217
+ [ 'rows' , 'e' , 'f' ] ,
218
+ [ 'rows' , 'rows' , 'rows' ]
219
+ ] ;
220
+
217
221
const data = [
218
- { col1 : 1 , col2 : 2 , col3 : 3 } ,
219
- { col1 : 2 , col2 : 3 , col3 : 4 } ,
220
- { col1 : 1 , col2 : 2 , col3 : 3 }
222
+ { col1 : 1 , col2 : 2 , col3 : 'x' , col4 : 3 } ,
223
+ { col1 : 2 , col2 : 3 , col3 : 'x' , col4 : 4 } ,
224
+ { col1 : 1 , col2 : 2 , col3 : 'x' , col4 : 3 }
221
225
] ;
222
- const columnID = [ 'col1' , 'col2' , 'col3' ] ;
226
+
227
+ const columnID = [ 'col1' , 'col2' , 'col4' ] ;
223
228
it ( 'create sheet with column names as headers for name or display header mode' , ( ) => {
224
- const wsName = createWorksheet ( Headings , data , columnID , 'names' , true ) ;
225
- const wsDisplay = createWorksheet ( Headings , data , columnID , 'display' , true ) ;
226
- const wsDisplayNoMerge = createWorksheet ( Headings , data , columnID , 'display' , false ) ;
229
+ const wsName = createWorksheet ( Headings , data , columnID , ExportHeaders . Names , true ) ;
230
+ const wsDisplay = createWorksheet ( Headings , data , columnID , ExportHeaders . Display , true ) ;
231
+ const wsDisplayNoMerge = createWorksheet ( Headings , data , columnID , ExportHeaders . Display , false ) ;
227
232
const expectedWS = {
228
233
A1 : { t : 's' , v : 'rows' } ,
229
234
A2 : { t : 's' , v : 'rows' } ,
@@ -256,7 +261,7 @@ describe('export', () => {
256
261
expect ( wsDisplay ) . to . deep . equal ( expectedWSDisplay ) ;
257
262
} ) ;
258
263
it ( 'create sheet with column ids as headers' , ( ) => {
259
- const ws = createWorksheet ( Headings , data , columnID , 'ids' , true ) ;
264
+ const ws = createWorksheet ( Headings , data , columnID , ExportHeaders . Ids , true ) ;
260
265
const expectedWS = {
261
266
A1 : { t : 's' , v : 'col1' } ,
262
267
A2 : { t : 'n' , v : 1 } ,
@@ -266,15 +271,15 @@ describe('export', () => {
266
271
B2 : { t : 'n' , v : 2 } ,
267
272
B3 : { t : 'n' , v : 3 } ,
268
273
B4 : { t : 'n' , v : 2 } ,
269
- C1 : { t : 's' , v : 'col3 ' } ,
274
+ C1 : { t : 's' , v : 'col4 ' } ,
270
275
C2 : { t : 'n' , v : 3 } ,
271
276
C3 : { t : 'n' , v : 4 } ,
272
277
C4 : { t : 'n' , v : 3 } } ;
273
278
expectedWS [ '!ref' ] = 'A1:C4' ;
274
279
expect ( ws ) . to . deep . equal ( expectedWS ) ;
275
280
} ) ;
276
281
it ( 'create sheet with no headers' , ( ) => {
277
- const ws = createWorksheet ( [ ] , data , columnID , 'none' , true ) ;
282
+ const ws = createWorksheet ( [ ] , data , columnID , ExportHeaders . None , true ) ;
278
283
const expectedWS = {
279
284
A1 : { t : 'n' , v : 1 } ,
280
285
A2 : { t : 'n' , v : 2 } ,
@@ -290,11 +295,11 @@ describe('export', () => {
290
295
} ) ;
291
296
it ( 'create sheet with undefined column for clearable columns' , ( ) => {
292
297
const newData = [
293
- { col2 : 2 , col3 : 3 } ,
294
- { col2 : 3 , col3 : 4 } ,
295
- { col2 : 2 , col3 : 3 }
298
+ { col2 : 2 , col4 : 3 } ,
299
+ { col2 : 3 , col4 : 4 } ,
300
+ { col2 : 2 , col4 : 3 }
296
301
] ;
297
- const ws = createWorksheet ( Headings , newData , columnID , 'display' , false ) ;
302
+ const ws = createWorksheet ( Headings , newData , columnID , ExportHeaders . Display , false ) ;
298
303
const expectedWS = { A1 : { t : 's' , v : 'rows' } ,
299
304
A2 : { t : 's' , v : 'rows' } ,
300
305
A3 : { t : 's' , v : 'rows' } ,
0 commit comments