1- import { fromJS } from 'immutable' ;
1+ import { fromJS , List } from 'immutable' ;
22
33import { QueryColumn } from '../../../../public/QueryColumn' ;
44import { QueryInfo } from '../../../../public/QueryInfo' ;
@@ -26,47 +26,55 @@ const COLUMN_FILE_INPUT = new QueryColumn({
2626 inputType : 'file' ,
2727 jsonType : 'string' ,
2828} ) ;
29+ const COLUMN_ARRAY_INPUT = new QueryColumn ( {
30+ fieldKey : 'arrInput' ,
31+ name : 'arrInput' ,
32+ fieldKeyArray : [ 'arrInput' ] ,
33+ inputType : 'text' ,
34+ jsonType : 'array' ,
35+ } ) ;
2936const QUERY_INFO = QueryInfo . fromJsonForTests ( {
3037 name : 'test' ,
3138 schemaName : 'schema' ,
3239 columns : {
33- strInput : COLUMN_STRING_INPUT ,
40+ arrInput : COLUMN_ARRAY_INPUT ,
3441 dtInput : COLUMN_DATE_INPUT ,
3542 fileInput : COLUMN_FILE_INPUT ,
43+ strInput : COLUMN_STRING_INPUT ,
3644 } ,
3745} ) ;
3846
3947describe ( 'extractChanges' , ( ) => {
4048 test ( 'file input' , ( ) => {
4149 const FILE = new File ( [ ] , 'file' ) ;
4250 const currentData = fromJS ( { fileInput : { value : FILE } } ) ;
43- expect ( extractChanges ( QUERY_INFO , currentData , { } ) . fileInput ) . toBe ( undefined ) ;
51+ expect ( extractChanges ( QUERY_INFO , currentData , { } ) . fileInput ) . toBeUndefined ( ) ;
4452 expect ( extractChanges ( QUERY_INFO , currentData , { fileInput : undefined } ) . fileInput ) . toBeUndefined ( ) ;
4553 expect ( extractChanges ( QUERY_INFO , currentData , { fileInput : FILE } ) . fileInput ) . toBeUndefined ( ) ;
46- expect ( extractChanges ( QUERY_INFO , currentData , { fileInput : null } ) . fileInput ) . toBe ( null ) ;
54+ expect ( extractChanges ( QUERY_INFO , currentData , { fileInput : null } ) . fileInput ) . toBeNull ( ) ;
4755 expect (
4856 extractChanges ( QUERY_INFO , currentData , { fileInput : new File ( [ ] , 'fileEdit' ) } ) . fileInput
4957 ) . toBeDefined ( ) ;
5058 } ) ;
5159
5260 test ( 'string input' , ( ) => {
5361 const currentData = fromJS ( { strInput : { value : 'abc' } } ) ;
54- expect ( extractChanges ( QUERY_INFO , currentData , { } ) . strInput ) . toBe ( undefined ) ;
55- expect ( extractChanges ( QUERY_INFO , currentData , { strInput : undefined } ) . strInput ) . toBe ( null ) ;
56- expect ( extractChanges ( QUERY_INFO , currentData , { strInput : null } ) . strInput ) . toBe ( null ) ;
62+ expect ( extractChanges ( QUERY_INFO , currentData , { } ) . strInput ) . toBeUndefined ( ) ;
63+ expect ( extractChanges ( QUERY_INFO , currentData , { strInput : undefined } ) . strInput ) . toBeNull ( ) ;
64+ expect ( extractChanges ( QUERY_INFO , currentData , { strInput : null } ) . strInput ) . toBeNull ( ) ;
5765 expect ( extractChanges ( QUERY_INFO , currentData , { strInput : '' } ) . strInput ) . toBe ( '' ) ;
5866 expect ( extractChanges ( QUERY_INFO , currentData , { strInput : [ ] } ) . strInput ) . toStrictEqual ( [ ] ) ;
59- expect ( extractChanges ( QUERY_INFO , currentData , { strInput : 'abc' } ) . strInput ) . toBe ( undefined ) ;
60- expect ( extractChanges ( QUERY_INFO , currentData , { strInput : ' abc ' } ) . strInput ) . toBe ( undefined ) ;
67+ expect ( extractChanges ( QUERY_INFO , currentData , { strInput : 'abc' } ) . strInput ) . toBeUndefined ( ) ;
68+ expect ( extractChanges ( QUERY_INFO , currentData , { strInput : ' abc ' } ) . strInput ) . toBeUndefined ( ) ;
6169 expect ( extractChanges ( QUERY_INFO , currentData , { strInput : ' abcd ' } ) . strInput ) . toBe ( 'abcd' ) ;
6270 } ) ;
6371
6472 test ( 'date input' , ( ) => {
6573 let currentData = fromJS ( { dtInput : { value : '2022-08-30 01:02:03' } } ) ;
66- expect ( extractChanges ( QUERY_INFO , currentData , { } ) . dtInput ) . toBe ( undefined ) ;
67- expect ( extractChanges ( QUERY_INFO , currentData , { dtInput : undefined } ) . dtInput ) . toBe ( null ) ;
68- expect ( extractChanges ( QUERY_INFO , currentData , { dtInput : null } ) . dtInput ) . toBe ( null ) ;
69- expect ( extractChanges ( QUERY_INFO , currentData , { dtInput : '2022-08-30 01:02:03' } ) . dtInput ) . toBe ( undefined ) ;
74+ expect ( extractChanges ( QUERY_INFO , currentData , { } ) . dtInput ) . toBeUndefined ( ) ;
75+ expect ( extractChanges ( QUERY_INFO , currentData , { dtInput : undefined } ) . dtInput ) . toBeNull ( ) ;
76+ expect ( extractChanges ( QUERY_INFO , currentData , { dtInput : null } ) . dtInput ) . toBeNull ( ) ;
77+ expect ( extractChanges ( QUERY_INFO , currentData , { dtInput : '2022-08-30 01:02:03' } ) . dtInput ) . toBeUndefined ( ) ;
7078 expect ( extractChanges ( QUERY_INFO , currentData , { dtInput : '2022-08-30 01:02:04' } ) . dtInput ) . toBe (
7179 '2022-08-30 01:02:04'
7280 ) ; // Issue 40139, 52536: date comparison only down to minute precision
@@ -81,10 +89,27 @@ describe('extractChanges', () => {
8189 ) ;
8290
8391 currentData = fromJS ( { dtInput : { value : '2022-08-30' } } ) ;
84- expect ( extractChanges ( QUERY_INFO , currentData , { dtInput : '2022-08-30' } ) . dtInput ) . toBe ( undefined ) ;
92+ expect ( extractChanges ( QUERY_INFO , currentData , { dtInput : '2022-08-30' } ) . dtInput ) . toBeUndefined ( ) ;
8593 expect ( extractChanges ( QUERY_INFO , currentData , { dtInput : '2022-08-31' } ) . dtInput ) . toBe ( '2022-08-31' ) ;
8694 expect ( extractChanges ( QUERY_INFO , currentData , { dtInput : '2022-08-30 01:02:03' } ) . dtInput ) . toBe (
8795 '2022-08-30 01:02:03'
8896 ) ;
8997 } ) ;
98+
99+ test ( 'array input' , ( ) => {
100+ // The existing value is an Immutable List
101+ const currentDataList = fromJS ( { arrInput : { value : List ( [ 1 , 2 , 3 ] ) } } ) ;
102+ expect ( extractChanges ( QUERY_INFO , currentDataList , { arrInput : [ 1 , 2 , 3 ] } ) . arrInput ) . toBeUndefined ( ) ;
103+ expect ( extractChanges ( QUERY_INFO , currentDataList , { arrInput : [ 1 , 2 , 4 ] } ) . arrInput ) . toEqual ( [ 1 , 2 , 4 ] ) ;
104+ expect ( extractChanges ( QUERY_INFO , currentDataList , { arrInput : [ 1 , 2 ] } ) . arrInput ) . toEqual ( [ 1 , 2 ] ) ;
105+
106+ // Existing value is a raw JavaScript array
107+ const currentDataRaw = fromJS ( { arrInput : { value : [ 10 , 20 ] } } ) ;
108+ expect ( extractChanges ( QUERY_INFO , currentDataRaw , { arrInput : [ 10 , 20 ] } ) . arrInput ) . toBeUndefined ( ) ;
109+ expect ( extractChanges ( QUERY_INFO , currentDataRaw , { arrInput : [ 10 , 20 , 30 ] } ) . arrInput ) . toEqual ( [ 10 , 20 , 30 ] ) ;
110+
111+ // Nulls and Undefined
112+ expect ( extractChanges ( QUERY_INFO , currentDataList , { arrInput : null } ) . arrInput ) . toBeNull ( ) ;
113+ expect ( extractChanges ( QUERY_INFO , currentDataList , { arrInput : undefined } ) . arrInput ) . toBeNull ( ) ;
114+ } ) ;
90115} ) ;
0 commit comments