11import { Action , createReducer } from '@ngrx/store' ;
22import { MarkAsDirtyAction , MarkAsTouchedAction , SetValueAction } from './actions' ;
3+ import { formArrayReducer } from './array/reducer' ;
4+ import { formControlReducer } from './control/reducer' ;
5+ import { formGroupReducer } from './group/reducer' ;
36import { createFormStateReducerWithUpdate , formStateReducer , onNgrxForms , onNgrxFormsAction , wrapReducerWithFormStateUpdate } from './reducer' ;
7+ import { FormArrayState , FormControlState , FormGroupState } from './state' ;
48import { FORM_CONTROL_ID , FORM_CONTROL_INNER5_ID , FORM_CONTROL_INNER_ID , FormGroupValue , INITIAL_STATE } from './update-function/test-util' ;
59import { updateGroup } from './update-function/update-group' ;
610
@@ -294,6 +298,20 @@ describe(wrapReducerWithFormStateUpdate.name, () => {
294298 expect ( resultState . control ) . not . toBe ( INITIAL_STATE . controls . inner ) ;
295299 } ) ;
296300
301+ it ( 'should update a non-nested control after the reducer' , ( ) => {
302+ const wrappedReducer = wrapReducerWithFormStateUpdate < FormControlState < string > , FormControlState < string > > (
303+ formControlReducer ,
304+ s => s ,
305+ s => {
306+ expect ( s ) . toBe ( INITIAL_STATE . controls . inner ) ;
307+ return ( { ...s } ) ;
308+ } ,
309+ ) ;
310+
311+ const resultState = wrappedReducer ( initialState . control , { type : '' } ) ;
312+ expect ( resultState ) . not . toBe ( INITIAL_STATE . controls . inner ) ;
313+ } ) ;
314+
297315 it ( 'should update a group after the reducer' , ( ) => {
298316 const wrappedReducer = wrapReducerWithFormStateUpdate ( reducer , s => s . group , s => {
299317 expect ( s ) . toBe ( INITIAL_STATE ) ;
@@ -304,6 +322,20 @@ describe(wrapReducerWithFormStateUpdate.name, () => {
304322 expect ( resultState . group ) . not . toBe ( INITIAL_STATE ) ;
305323 } ) ;
306324
325+ it ( 'should update a non-nested group after the reducer' , ( ) => {
326+ const wrappedReducer = wrapReducerWithFormStateUpdate < FormGroupState < FormGroupValue > , FormGroupState < FormGroupValue > > (
327+ formGroupReducer ,
328+ s => s ,
329+ s => {
330+ expect ( s ) . toBe ( INITIAL_STATE ) ;
331+ return ( { ...s } ) ;
332+ } ,
333+ ) ;
334+
335+ const resultState = wrappedReducer ( initialState . group , { type : '' } ) ;
336+ expect ( resultState ) . not . toBe ( INITIAL_STATE ) ;
337+ } ) ;
338+
307339 it ( 'should update an array after the reducer' , ( ) => {
308340 const wrappedReducer = wrapReducerWithFormStateUpdate ( reducer , s => s . array , s => {
309341 expect ( s ) . toBe ( INITIAL_STATE . controls . inner5 ) ;
@@ -314,6 +346,20 @@ describe(wrapReducerWithFormStateUpdate.name, () => {
314346 expect ( resultState . array ) . not . toBe ( INITIAL_STATE . controls . inner5 ) ;
315347 } ) ;
316348
349+ it ( 'should update a non-nested array after the reducer' , ( ) => {
350+ const wrappedReducer = wrapReducerWithFormStateUpdate < FormArrayState < string > , FormArrayState < string > > (
351+ formArrayReducer ,
352+ s => s ,
353+ s => {
354+ expect ( s ) . toBe ( INITIAL_STATE . controls . inner5 ) ;
355+ return ( { ...s } ) ;
356+ } ,
357+ ) ;
358+
359+ const resultState = wrappedReducer ( initialState . array , { type : '' } ) ;
360+ expect ( resultState ) . not . toBe ( INITIAL_STATE . controls . inner5 ) ;
361+ } ) ;
362+
317363 it ( 'should set the updated form state' , ( ) => {
318364 const updatedControl = { ...INITIAL_STATE . controls . inner } ;
319365 const wrappedReducer = wrapReducerWithFormStateUpdate ( reducer , s => s . control , ( ) => updatedControl ) ;
0 commit comments