@@ -10,12 +10,18 @@ const { testEpic, addTimeoutEpic, TEST_TIMEOUT } = require('./epicTestUtils');
1010
1111const {
1212 clearWidgetsOnLocationChange,
13- alignDependenciesToWidgets
13+ alignDependenciesToWidgets,
14+ toggleWidgetConnectFlow
1415} = require ( '../widgets' ) ;
1516const {
1617 CLEAR_WIDGETS ,
1718 insertWidget,
18- LOAD_DEPENDENCIES
19+ toggleConnection,
20+ selectWidget,
21+ EDITOR_CHANGE ,
22+ EDITOR_SETTING_CHANGE ,
23+ LOAD_DEPENDENCIES ,
24+ DEPENDENCY_SELECTOR_KEY
1925} = require ( '../../actions/widgets' ) ;
2026const {
2127 savingMap,
@@ -147,4 +153,123 @@ describe('widgets Epics', () => {
147153 { } ) ;
148154 } ) ;
149155
156+ it ( 'toggleWidgetConnectFlow with only map' , ( done ) => {
157+ const checkActions = actions => {
158+ expect ( actions . length ) . toBe ( 2 ) ;
159+ expect ( actions [ 0 ] . type ) . toBe ( EDITOR_CHANGE ) ;
160+ expect ( actions [ 0 ] . key ) . toBe ( "mapSync" ) ;
161+ expect ( actions [ 0 ] . value ) . toBe ( true ) ;
162+ const action = actions [ 1 ] ;
163+ expect ( action . type ) . toBe ( EDITOR_CHANGE ) ;
164+ expect ( action . key ) . toExist ( ) ;
165+ expect ( action . key ) . toBe ( "dependenciesMap" ) ;
166+ expect ( action . value . center ) . toBe ( "center" ) ;
167+ expect ( action . value . zoom ) . toBe ( "zoom" ) ;
168+ done ( ) ;
169+ } ;
170+ testEpic ( toggleWidgetConnectFlow ,
171+ 2 ,
172+ [ toggleConnection (
173+ true ,
174+ [ "map" ] ,
175+ { mappings : { zoom : "zoom" , center : "center" } }
176+ ) ] ,
177+ checkActions ,
178+ { } ) ;
179+ } ) ;
180+ it ( 'toggleWidgetConnectFlow for widgets' , ( done ) => {
181+ const checkActions = actions => {
182+ expect ( actions . length ) . toBe ( 2 ) ;
183+ expect ( actions [ 0 ] . type ) . toBe ( EDITOR_CHANGE ) ;
184+ expect ( actions [ 0 ] . key ) . toBe ( "mapSync" ) ;
185+ expect ( actions [ 0 ] . value ) . toBe ( true ) ;
186+ const action = actions [ 1 ] ;
187+ expect ( action . type ) . toBe ( EDITOR_CHANGE ) ;
188+ expect ( action . key ) . toExist ( ) ;
189+ expect ( action . key ) . toBe ( "dependenciesMap" ) ;
190+ expect ( action . value . center ) . toBe ( "widgets[a].map.center" ) ;
191+ expect ( action . value . zoom ) . toBe ( "widgets[a].map.zoom" ) ;
192+ done ( ) ;
193+ } ;
194+ testEpic ( toggleWidgetConnectFlow ,
195+ 2 ,
196+ [ toggleConnection (
197+ true ,
198+ [ "widgets[a].map" ] ,
199+ { mappings : { "center" : "center" , "zoom" : "zoom" } }
200+ ) ] ,
201+ checkActions ,
202+ { } ) ;
203+ } ) ;
204+ it ( 'toggleWidgetConnectFlow for multiple widgets' , ( done ) => {
205+ const checkActions = actions => {
206+ expect ( actions . length ) . toBe ( 4 ) ;
207+ expect ( actions [ 0 ] . type ) . toBe ( EDITOR_SETTING_CHANGE ) ;
208+ expect ( actions [ 0 ] . key ) . toBe ( DEPENDENCY_SELECTOR_KEY ) ;
209+ expect ( actions [ 0 ] . value . active ) . toBe ( true ) ;
210+ expect ( actions [ 0 ] . value . availableDependencies . length ) . toBe ( 2 ) ;
211+ expect ( actions [ 1 ] . type ) . toBe ( EDITOR_CHANGE ) ;
212+ expect ( actions [ 1 ] . key ) . toBe ( "mapSync" ) ;
213+ expect ( actions [ 1 ] . value ) . toBe ( true ) ;
214+ const action = actions [ 2 ] ;
215+ expect ( action . type ) . toBe ( EDITOR_CHANGE ) ;
216+ expect ( action . key ) . toExist ( ) ;
217+ expect ( action . key ) . toBe ( "dependenciesMap" ) ;
218+ expect ( action . value . center ) . toBe ( "widgets[w1].map.center" ) ;
219+ expect ( action . value . zoom ) . toBe ( "widgets[w1].map.zoom" ) ;
220+ expect ( actions [ 3 ] . type ) . toBe ( EDITOR_SETTING_CHANGE ) ;
221+ expect ( actions [ 3 ] . key ) . toBe ( DEPENDENCY_SELECTOR_KEY ) ;
222+ expect ( actions [ 3 ] . value . active ) . toBe ( false ) ;
223+ done ( ) ;
224+ } ;
225+ testEpic ( toggleWidgetConnectFlow ,
226+ 4 ,
227+ [ toggleConnection (
228+ true ,
229+ [ "w1" , "w2" ] ,
230+ { mappings : { "center" : "center" , "zoom" : "zoom" } }
231+ ) , selectWidget ( {
232+ id : "w1" ,
233+ widgetType : "map"
234+ } ) ] ,
235+ checkActions ,
236+ {
237+ widgets : {
238+ builder : {
239+ settings : {
240+ [ DEPENDENCY_SELECTOR_KEY ] : { active : true ,
241+ availableDependencies : [
242+ "map.zoom" ,
243+ "widgets[w1].map" ,
244+ "widgets[w2].map"
245+ ] }
246+ }
247+ }
248+ }
249+ } ) ;
250+ } ) ;
251+ it ( 'toggleWidgetConnectFlow deactivate widgets' , ( done ) => {
252+ const checkActions = actions => {
253+ expect ( actions . length ) . toBe ( 2 ) ;
254+ expect ( actions [ 0 ] . type ) . toBe ( EDITOR_CHANGE ) ;
255+ expect ( actions [ 0 ] . key ) . toBe ( "mapSync" ) ;
256+ expect ( actions [ 0 ] . value ) . toBe ( false ) ;
257+ const action = actions [ 1 ] ;
258+ expect ( action . type ) . toBe ( EDITOR_CHANGE ) ;
259+ expect ( action . key ) . toExist ( ) ;
260+ expect ( action . key ) . toBe ( "dependenciesMap" ) ;
261+ expect ( action . value . center ) . toNotExist ( ) ;
262+ expect ( action . value . zoom ) . toNotExist ( ) ;
263+ done ( ) ;
264+ } ;
265+ testEpic ( toggleWidgetConnectFlow ,
266+ 2 ,
267+ [ toggleConnection (
268+ false ,
269+ [ "map" ] ,
270+ { mappings : { "center" : "widgets[a].map.center" , "zoom" : "widgets[a].map.zoom" } }
271+ ) ] ,
272+ checkActions ,
273+ { } ) ;
274+ } ) ;
150275} ) ;
0 commit comments