import { DisableAction } from '../../actions' ; import { createFormControlState } from '../../state' ; import { disableReducer } from './disable' ; describe ( 'form control disableReducer' , ( ) => { const FORM_CONTROL_ID = 'test ID' ; const INITIAL_FORM_CONTROL_VALUE = '' ; const INITIAL_STATE = createFormControlState < string > ( FORM_CONTROL_ID , INITIAL_FORM_CONTROL_VALUE ) ; it ( 'should skip any actionof the wrong type' , ( ) => expect ( disableReducer ( INITIAL_STATE , { type : '' } as any ) ) . toBe ( INITIAL_STATE ) ) ; it ( 'should update state if enabled' , ( ) => { const resultState = disableReducer ( INITIAL_STATE , new DisableAction ( FORM_CONTROL_ID ) ) ; expect ( resultState . isEnabled ) . toEqual ( false ) ; expect ( resultState . isDisabled ) . toEqual ( true ) ; } ) ; it ( 'should not update state if disabled' , ( ) => { const state = { ... INITIAL_STATE , isEnabled : false , isDisabled : true } ; const resultState = disableReducer ( state , new DisableAction ( FORM_CONTROL_ID ) ) ; expect ( resultState ) . toBe ( state ) ; } ) ; it ( 'should mark the state as valid and clear all errors' , ( ) => { const errors = { required : true } ; const state = { ... INITIAL_STATE , isValid : false , isInvalid : true , errors } ; const resultState = disableReducer ( state , new DisableAction ( FORM_CONTROL_ID ) ) ; expect ( resultState . isValid ) . toEqual ( true ) ; expect ( resultState . isInvalid ) . toEqual ( false ) ; expect ( resultState . errors ) . toEqual ( { } ) ; } ) ; it ( 'should clear all pending validations' , ( ) => { const state = { ... INITIAL_STATE , pendingValidations : [ 'required' ] , isValidationPending : true } ; const resultState = disableReducer ( state , new DisableAction ( FORM_CONTROL_ID ) ) ; expect ( resultState . pendingValidations ) . toEqual ( [ ] ) ; expect ( resultState . isValidationPending ) . toBe ( false ) ; } ) ; } ) ;