11import  {  exportWithFormatterWhenDefined  }  from  '../export-utilities' ; 
22import  {  Column ,  Formatter ,  SlickGrid  }  from  '../../models/index' ; 
33
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+ 
415describe ( 'Export Utilities' ,  ( )  =>  { 
5-   let  mockItem ; 
16+   let  mockItem :  any ; 
617  let  mockColumn : Column ; 
718  const  myBoldHtmlFormatter : Formatter  =  ( _row ,  _cell ,  value )  =>  value  !==  null  ? {  text : value  ? `<b>${ value }  </b>`  : ''  }  : null  as  any ; 
819  const  myUppercaseFormatter : Formatter  =  ( _row ,  _cell ,  value )  =>  value  ? {  text : value . toUpperCase ( )  }  : null  as  any ; 
@@ -14,65 +25,65 @@ describe('Export Utilities', () => {
1425
1526  describe ( 'exportWithFormatterWhenDefined method' ,  ( )  =>  { 
1627    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  } ) ; 
1829      expect ( output ) . toBe ( 'John' ) ; 
1930    } ) ; 
2031
2132    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 ,  { } ) ; 
2334      expect ( output ) . toEqual ( {  zip : 12345  } ) ; 
2435    } ) ; 
2536
2637    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 ,  { } ) ; 
2839      expect ( output ) . toEqual ( '' ) ; 
2940    } ) ; 
3041
3142    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 ,  { } ) ; 
3344      expect ( output ) . toEqual ( '' ) ; 
3445    } ) ; 
3546
3647    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  } ) ; 
3849      expect ( output ) . toBe ( '<b>John</b>' ) ; 
3950    } ) ; 
4051
4152    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  } ) ; 
4354      expect ( output ) . toBe ( '' ) ; 
4455    } ) ; 
4556
4657    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  } ) ; 
4859      expect ( output ) . toBe ( '' ) ; 
4960    } ) ; 
5061
5162    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  } ) ; 
5364      expect ( output ) . toBe ( 'JOHN' ) ; 
5465    } ) ; 
5566
5667    it ( 'should enable exportWithFormatter as a grid option and expect the firstName to be formatted' ,  ( )  =>  { 
5768      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  } ) ; 
5970      expect ( output ) . toBe ( 'JOHN' ) ; 
6071    } ) ; 
6172
6273    it ( 'should enable exportWithFormatter as a grid option and expect empty string when associated item property is null' ,  ( )  =>  { 
6374      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  } ) ; 
6576      expect ( output ) . toBe ( '' ) ; 
6677    } ) ; 
6778
6879    it ( 'should enable exportWithFormatter as a grid option and expect empty string when associated item property is undefined' ,  ( )  =>  { 
6980      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  } ) ; 
7182      expect ( output ) . toBe ( '' ) ; 
7283    } ) ; 
7384
7485    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 ,  { } ) ; 
7687      expect ( output ) . toBe ( '' ) ; 
7788    } ) ; 
7889  } ) ; 
0 commit comments