1
1
import { exportWithFormatterWhenDefined } from '../export-utilities' ;
2
2
import { Column , Formatter , SlickGrid } from '../../models/index' ;
3
3
4
+ const mockDataView = {
5
+ constructor : jest . fn ( ) ,
6
+ init : jest . fn ( ) ,
7
+ destroy : jest . fn ( ) ,
8
+ getItemMetadata : jest . fn ( ) ,
9
+ } ;
10
+
11
+ const gridStub = {
12
+ getData : ( ) => mockDataView ,
13
+ } ;
14
+
4
15
describe ( 'Export Utilities' , ( ) => {
5
- let mockItem ;
16
+ let mockItem : any ;
6
17
let mockColumn : Column ;
7
18
const myBoldHtmlFormatter : Formatter = ( _row , _cell , value ) => value !== null ? { text : value ? `<b>${ value } </b>` : '' } : null as any ;
8
19
const myUppercaseFormatter : Formatter = ( _row , _cell , value ) => value ? { text : value . toUpperCase ( ) } : null as any ;
@@ -14,65 +25,65 @@ describe('Export Utilities', () => {
14
25
15
26
describe ( 'exportWithFormatterWhenDefined method' , ( ) => {
16
27
it ( 'should NOT enable exportWithFormatter and expect the firstName to returned' , ( ) => {
17
- const output = exportWithFormatterWhenDefined ( 1 , 1 , mockItem , mockColumn , { } as SlickGrid , { exportWithFormatter : false } ) ;
28
+ const output = exportWithFormatterWhenDefined ( 1 , 1 , mockItem , mockColumn , gridStub as SlickGrid , { exportWithFormatter : false } ) ;
18
29
expect ( output ) . toBe ( 'John' ) ;
19
30
} ) ;
20
31
21
32
it ( 'should provide a column definition field defined with a dot (.) notation and expect a complex object result' , ( ) => {
22
- const output = exportWithFormatterWhenDefined ( 1 , 1 , mockItem , { ...mockColumn , field : 'address.zip' } , { } as SlickGrid , { } ) ;
33
+ const output = exportWithFormatterWhenDefined ( 1 , 1 , mockItem , { ...mockColumn , field : 'address.zip' } , gridStub as SlickGrid , { } ) ;
23
34
expect ( output ) . toEqual ( { zip : 12345 } ) ;
24
35
} ) ;
25
36
26
37
it ( 'should provide a column definition field defined with a dot (.) notation and expect an empty string when the complex result is an empty object' , ( ) => {
27
- const output = exportWithFormatterWhenDefined ( 1 , 1 , mockItem , { ...mockColumn , field : 'empty' } , { } as SlickGrid , { } ) ;
38
+ const output = exportWithFormatterWhenDefined ( 1 , 1 , mockItem , { ...mockColumn , field : 'empty' } , gridStub as SlickGrid , { } ) ;
28
39
expect ( output ) . toEqual ( '' ) ;
29
40
} ) ;
30
41
31
42
it ( 'should provide a column definition field defined with a dot (.) notation and expect an empty string when the complex result is an empty object' , ( ) => {
32
- const output = exportWithFormatterWhenDefined ( 1 , 1 , mockItem , { ...mockColumn , field : 'empty' } , { } as SlickGrid , { } ) ;
43
+ const output = exportWithFormatterWhenDefined ( 1 , 1 , mockItem , { ...mockColumn , field : 'empty' } , gridStub as SlickGrid , { } ) ;
33
44
expect ( output ) . toEqual ( '' ) ;
34
45
} ) ;
35
46
36
47
it ( 'should provide a exportCustomFormatter in the column definition and expect the output to be formatted' , ( ) => {
37
- const output = exportWithFormatterWhenDefined ( 1 , 1 , mockItem , { ...mockColumn , exportCustomFormatter : myBoldHtmlFormatter } , { } as SlickGrid , { exportWithFormatter : true } ) ;
48
+ const output = exportWithFormatterWhenDefined ( 1 , 1 , mockItem , { ...mockColumn , exportCustomFormatter : myBoldHtmlFormatter } , gridStub as SlickGrid , { exportWithFormatter : true } ) ;
38
49
expect ( output ) . toBe ( '<b>John</b>' ) ;
39
50
} ) ;
40
51
41
52
it ( 'should provide a exportCustomFormatter in the column definition and expect empty string when associated item property is null' , ( ) => {
42
- const output = exportWithFormatterWhenDefined ( 1 , 1 , { ...mockItem , firstName : null } , { ...mockColumn , exportCustomFormatter : myBoldHtmlFormatter } , { } as SlickGrid , { exportWithFormatter : true } ) ;
53
+ const output = exportWithFormatterWhenDefined ( 1 , 1 , { ...mockItem , firstName : null } , { ...mockColumn , exportCustomFormatter : myBoldHtmlFormatter } , gridStub as SlickGrid , { exportWithFormatter : true } ) ;
43
54
expect ( output ) . toBe ( '' ) ;
44
55
} ) ;
45
56
46
57
it ( 'should provide a exportCustomFormatter in the column definition and expect empty string when associated item property is undefined' , ( ) => {
47
- const output = exportWithFormatterWhenDefined ( 1 , 1 , { ...mockItem , firstName : undefined } , { ...mockColumn , exportCustomFormatter : myBoldHtmlFormatter } , { } as SlickGrid , { exportWithFormatter : true } ) ;
58
+ const output = exportWithFormatterWhenDefined ( 1 , 1 , { ...mockItem , firstName : undefined } , { ...mockColumn , exportCustomFormatter : myBoldHtmlFormatter } , gridStub as SlickGrid , { exportWithFormatter : true } ) ;
48
59
expect ( output ) . toBe ( '' ) ;
49
60
} ) ;
50
61
51
62
it ( 'should enable exportWithFormatter as an exportOption and expect the firstName to be formatted' , ( ) => {
52
- const output = exportWithFormatterWhenDefined ( 1 , 1 , mockItem , mockColumn , { } as SlickGrid , { exportWithFormatter : true } ) ;
63
+ const output = exportWithFormatterWhenDefined ( 1 , 1 , mockItem , mockColumn , gridStub as SlickGrid , { exportWithFormatter : true } ) ;
53
64
expect ( output ) . toBe ( 'JOHN' ) ;
54
65
} ) ;
55
66
56
67
it ( 'should enable exportWithFormatter as a grid option and expect the firstName to be formatted' , ( ) => {
57
68
mockColumn . exportWithFormatter = true ;
58
- const output = exportWithFormatterWhenDefined ( 1 , 1 , mockItem , mockColumn , { } as SlickGrid , { exportWithFormatter : true } ) ;
69
+ const output = exportWithFormatterWhenDefined ( 1 , 1 , mockItem , mockColumn , gridStub as SlickGrid , { exportWithFormatter : true } ) ;
59
70
expect ( output ) . toBe ( 'JOHN' ) ;
60
71
} ) ;
61
72
62
73
it ( 'should enable exportWithFormatter as a grid option and expect empty string when associated item property is null' , ( ) => {
63
74
mockColumn . exportWithFormatter = true ;
64
- const output = exportWithFormatterWhenDefined ( 1 , 1 , { ...mockItem , firstName : null } , mockColumn , { } as SlickGrid , { exportWithFormatter : true } ) ;
75
+ const output = exportWithFormatterWhenDefined ( 1 , 1 , { ...mockItem , firstName : null } , mockColumn , gridStub as SlickGrid , { exportWithFormatter : true } ) ;
65
76
expect ( output ) . toBe ( '' ) ;
66
77
} ) ;
67
78
68
79
it ( 'should enable exportWithFormatter as a grid option and expect empty string when associated item property is undefined' , ( ) => {
69
80
mockColumn . exportWithFormatter = true ;
70
- const output = exportWithFormatterWhenDefined ( 1 , 1 , { ...mockItem , firstName : undefined } , mockColumn , { } as SlickGrid , { exportWithFormatter : true } ) ;
81
+ const output = exportWithFormatterWhenDefined ( 1 , 1 , { ...mockItem , firstName : undefined } , mockColumn , gridStub as SlickGrid , { exportWithFormatter : true } ) ;
71
82
expect ( output ) . toBe ( '' ) ;
72
83
} ) ;
73
84
74
85
it ( 'should expect empty string when associated item property is undefined and has no formatter defined' , ( ) => {
75
- const output = exportWithFormatterWhenDefined ( 1 , 1 , { ...mockItem , firstName : undefined } , mockColumn , { } as SlickGrid , { } ) ;
86
+ const output = exportWithFormatterWhenDefined ( 1 , 1 , { ...mockItem , firstName : undefined } , mockColumn , gridStub as SlickGrid , { } ) ;
76
87
expect ( output ) . toBe ( '' ) ;
77
88
} ) ;
78
89
} ) ;
0 commit comments