55 syncQuery2Conditions ,
66 isEquivalent ,
77 deepClone ,
8+ typeOf ,
89} from '../src/core/utils/common'
910
1011describe ( 'utils: isEquivalent' , ( ) => {
@@ -27,6 +28,37 @@ describe('utils: isEquivalent', () => {
2728 } )
2829} )
2930
31+ describe ( 'utils: typeof' , ( ) => {
32+ it ( `Is array` , ( ) => {
33+ expect ( typeOf ( [ ] ) ) . toEqual ( 'array' )
34+ } )
35+ it ( `Is date` , ( ) => {
36+ expect ( typeOf ( new Date ( ) ) ) . toEqual ( 'date' )
37+ } )
38+ it ( `Is object` , ( ) => {
39+ expect ( typeOf ( { } ) ) . toEqual ( 'object' )
40+ } )
41+ it ( `Is number` , ( ) => {
42+ expect ( typeOf ( 1 ) ) . toEqual ( 'number' )
43+ } )
44+ it ( `Is string` , ( ) => {
45+ expect ( typeOf ( 'hi' ) ) . toEqual ( 'string' )
46+ } )
47+ it ( `Is null` , ( ) => {
48+ expect ( typeOf ( null ) ) . toEqual ( 'null' )
49+ } )
50+ it ( `Is undefined` , ( ) => {
51+ expect ( typeOf ( undefined ) ) . toEqual ( 'undefined' )
52+ } )
53+ it ( `Is function` , ( ) => {
54+ expect (
55+ typeOf ( ( ) => {
56+ //
57+ } )
58+ ) . toEqual ( 'function' )
59+ } )
60+ } )
61+
3062describe ( 'utils: deepClone' , ( ) => {
3163 it ( `Check Object deepClone` , ( ) => {
3264 const current = {
@@ -102,7 +134,7 @@ describe('utils: syncQuery2Conditions', () => {
102134 age : 20 ,
103135 tags : [ 'react' , 'vue' ] ,
104136 }
105- syncQuery2Conditions ( conditions , query )
137+ syncQuery2Conditions ( conditions , query , conditions )
106138 expect ( conditions ) . toMatchObject ( {
107139 age : 50 ,
108140 tags : [ 'react' , 'vue' ] ,
@@ -116,22 +148,51 @@ describe('utils: syncQuery2Conditions', () => {
116148 const conditions = {
117149 date : new Date ( ) ,
118150 }
119- syncQuery2Conditions ( conditions , query )
151+ syncQuery2Conditions ( conditions , query , conditions )
120152 expect ( Object . prototype . toString . call ( conditions . date ) === '[object Date]' ) . toBeTruthy ( )
121153 } )
122154
155+ it ( 'should sync query object to conditions with Array<string>' , ( ) => {
156+ const query = {
157+ daterange : [ '2020-01-02' , '2020-01-03' ] ,
158+ }
159+ const conditions = {
160+ daterange : [ ] ,
161+ }
162+ syncQuery2Conditions ( conditions , query , conditions )
163+ expect ( conditions . daterange ) . toMatchObject ( [ '2020-01-02' , '2020-01-03' ] )
164+ } )
165+
166+ it ( 'should sync query object to conditions with Array<number>' , ( ) => {
167+ const query = {
168+ daterange : [ 1 , 2 ] ,
169+ }
170+ const conditions = {
171+ daterange : [ ] ,
172+ }
173+ syncQuery2Conditions ( conditions , query , conditions )
174+ expect ( conditions . daterange ) . toMatchObject ( [ 1 , 2 ] )
175+ } )
176+
123177 it ( 'if query is empty conditions should set init value' , ( ) => {
124178 const query = { }
125179 const conditions = {
126180 date : new Date ( ) ,
127- name : 'runkids' ,
128- tags : [ 'react' ] ,
181+ string : 'runkids' ,
182+ array : [ 'react' , 'vue' ] ,
183+ boolean : false ,
184+ undefined : undefined ,
185+ null : null ,
129186 }
130- syncQuery2Conditions ( conditions , query )
187+ syncQuery2Conditions ( conditions , query , conditions )
188+
131189 expect ( conditions ) . toMatchObject ( {
132- date : null ,
133- name : '' ,
134- tags : [ ] ,
190+ date : '' ,
191+ string : '' ,
192+ array : [ ] ,
193+ boolean : '' ,
194+ undefined : '' ,
195+ null : '' ,
135196 } )
136197 } )
137198} )
0 commit comments