@@ -2,7 +2,7 @@ import { Column } from '../../models';
22import { complexObjectFormatter } from '../complexObjectFormatter' ;
33
44describe ( 'the ComplexObject Formatter' , ( ) => {
5- const allRoles = [ { roleId : 0 , name : 'Administrator' } , { roleId : 1 , name : 'Regular User' } ] ;
5+ const allRoles = [ { roleId : 0 , name : 'Administrator' } , { roleId : 1 , name : 'Regular User' , empty : { } } ] ;
66
77 const dataset = [
88 { id :
0 , firstName :
'John' , lastName :
'Smith' , email :
'[email protected] ' , role :
allRoles [ 0 ] } , @@ -11,54 +11,60 @@ describe('the ComplexObject Formatter', () => {
1111 ] ;
1212
1313 it ( 'should throw an error when omitting to pass "complexFieldLabel" to "params"' , ( ) => {
14- expect ( ( ) => complexObjectFormatter ( 0 , 0 , 'anything' , { } as Column , { } , { } ) )
14+ expect ( ( ) => complexObjectFormatter ( 0 , 0 , 'anything' , { } as Column , { } , { } as any ) )
1515 . toThrowError ( 'For the Formatters.complexObject to work properly' ) ;
1616 } ) ;
1717
1818 it ( 'should return empty string when no column definition is provided' , ( ) => {
19- const result = complexObjectFormatter ( 0 , 0 , 'anything' , null as Column , { } , { } ) ;
19+ const result = complexObjectFormatter ( 0 , 0 , 'anything' , null as Column , { } , { } as any ) ;
2020 expect ( result ) . toBe ( '' ) ;
2121 } ) ;
2222
2323 it ( 'should return original input value when the "field" property does not include a not ".", neither "complexFieldLabel"' , ( ) => {
24- const result = complexObjectFormatter ( 0 , 0 , 'anything' , { field : 'role' } as Column , { } , { } ) ;
24+ const result = complexObjectFormatter ( 0 , 0 , 'anything' , { field : 'role' } as Column , { } , { } as any ) ;
2525 expect ( result ) . toBe ( 'anything' ) ;
2626 } ) ;
2727
28- it ( 'should return original input value when the "field" property was not found in the data context object' , ( ) => {
29- const result = complexObjectFormatter ( 0 , 0 , 'anything' , { field : 'invalid.object' } as Column , dataset [ 2 ] , { } ) ;
30- expect ( result ) . toBe ( 'anything ' ) ;
28+ it ( 'should return empty string when the "field" property was not found in the data context object' , ( ) => {
29+ const result = complexObjectFormatter ( 0 , 0 , 'anything' , { field : 'invalid.object' } as Column , dataset [ 2 ] , { } as any ) ;
30+ expect ( result ) . toBe ( '' ) ;
3131 } ) ;
3232
3333 it ( 'should return original input value when the "complexFieldLabel" does not include a not "." within its string' , ( ) => {
3434 const params = { complexFieldLabel : 'name' } ;
35- const result = complexObjectFormatter ( 0 , 0 , 'anything' , { field : 'role' , params } as Column , { } , { } ) ;
35+ const result = complexObjectFormatter ( 0 , 0 , 'anything' , { field : 'role' , params } as Column , { } , { } as any ) ;
3636 expect ( result ) . toBe ( 'anything' ) ;
3737 } ) ;
3838
3939 it ( 'should return original input value when the "complexFieldLabel" was not found in the data context object' , ( ) => {
4040 const params = { complexFieldLabel : 'invalid.object' } ;
41- const result = complexObjectFormatter ( 0 , 0 , 'anything' , { field : 'role' , params } as Column , dataset [ 2 ] , { } ) ;
42- expect ( result ) . toBe ( 'anything ' ) ;
41+ const result = complexObjectFormatter ( 0 , 0 , 'anything' , { field : 'role' , params } as Column , dataset [ 2 ] , { } as any ) ;
42+ expect ( result ) . toBe ( '' ) ;
4343 } ) ;
4444
4545 it ( 'should return the value from the complex object when "field" property with dot notation was found in the data context object' , ( ) => {
4646 const expectedOutput = 'Administrator' ;
47- const result = complexObjectFormatter ( 0 , 0 , 'anything' , { field : 'role.name' } as Column , dataset [ 0 ] , { } ) ;
47+ const result = complexObjectFormatter ( 0 , 0 , 'anything' , { field : 'role.name' } as Column , dataset [ 0 ] , { } as any ) ;
48+ expect ( result ) . toBe ( expectedOutput ) ;
49+ } ) ;
50+
51+ it ( 'should return an empty string when the value from the complex object when "field" has dot notation and the empty returned from it is an empty object' , ( ) => {
52+ const expectedOutput = '' ;
53+ const result = complexObjectFormatter ( 0 , 0 , 'anything' , { field : 'role.empty' } as Column , dataset [ 1 ] , { } as any ) ;
4854 expect ( result ) . toBe ( expectedOutput ) ;
4955 } ) ;
5056
5157 it ( 'should return the value from the complex object when "complexFieldLabel" property with dot notation was found in the data context object' , ( ) => {
5258 const params = { complexFieldLabel : 'role.name' } ;
5359 const expectedOutput = 'Administrator' ;
54- const result = complexObjectFormatter ( 0 , 0 , 'anything' , { field : 'role' , params } as Column , dataset [ 0 ] , { } ) ;
60+ const result = complexObjectFormatter ( 0 , 0 , 'anything' , { field : 'role' , params } as Column , dataset [ 0 ] , { } as any ) ;
5561 expect ( result ) . toBe ( expectedOutput ) ;
5662 } ) ;
5763
5864 it ( 'should return the value from the complex object when "complexFieldLabel" is not dot notation but has a "labelKey" was found in the data context object' , ( ) => {
5965 const params = { complexFieldLabel : 'role' } ;
6066 const expectedOutput = 'Administrator' ;
61- const result = complexObjectFormatter ( 0 , 0 , 'anything' , { field : 'role' , labelKey : 'name' , params } as Column , dataset [ 0 ] , { } ) ;
67+ const result = complexObjectFormatter ( 0 , 0 , 'anything' , { field : 'role' , labelKey : 'name' , params } as Column , dataset [ 0 ] , { } as any ) ;
6268 expect ( result ) . toBe ( expectedOutput ) ;
6369 } ) ;
6470} ) ;
0 commit comments