diff --git a/packages/wyatt_authentication_bloc/test/sign_up/sign_up_cubit_test.dart b/packages/wyatt_authentication_bloc/test/sign_up/sign_up_cubit_test.dart index 0fe84d1a..3d54a978 100644 --- a/packages/wyatt_authentication_bloc/test/sign_up/sign_up_cubit_test.dart +++ b/packages/wyatt_authentication_bloc/test/sign_up/sign_up_cubit_test.dart @@ -481,5 +481,178 @@ void main() { ], ); }); + + group('update', () { + final inputsA = < + FormInput, + dynamic>>[ + FormInput(AuthFormField.email, const Email.pure()), + FormInput(AuthFormField.password, const Password.pure()) + ]; + + final inputsB = < + FormInput, + dynamic>>[ + FormInput('name', const Name.pure()), + FormInput('phone', const Phone.pure()), + ]; + + final inputsC = < + FormInput, + dynamic>>[ + FormInput(AuthFormField.email, const Email.pure()), + FormInput(AuthFormField.password, const Password.pure()), + FormInput('name', const Name.pure()), + FormInput('phone', const Phone.pure()), + ]; + + blocTest, SignUpState>( + 'emits no state when apply intersection with the same form', + build: () => SignUpCubit( + authenticationRepository: authenticationRepository, + ), + seed: () => SignUpState( + form: WyattFormImpl( + inputsA, + name: AuthFormName.signUpForm, + ), + ), + act: (cubit) => cubit.update( + WyattFormImpl(inputsA, name: 'otherSignUpForm'), + operation: SetOperation.intersection, + ), + expect: () => [], + ); + + blocTest, SignUpState>( + 'emits no state when apply intersection with a form that ' + 'contains every inputs of actual form', + build: () => SignUpCubit( + authenticationRepository: authenticationRepository, + ), + seed: () => SignUpState( + form: WyattFormImpl( + inputsA, + name: AuthFormName.signUpForm, + ), + ), + act: (cubit) => cubit.update( + WyattFormImpl(inputsC, name: 'otherSignUpForm'), + operation: SetOperation.intersection, + ), + expect: () => [], + ); + + blocTest, SignUpState>( + 'emits the form intersection when apply ' + 'intersection with a smaller form', + build: () => SignUpCubit( + authenticationRepository: authenticationRepository, + ), + seed: () => SignUpState( + form: WyattFormImpl( + inputsC, + name: AuthFormName.signUpForm, + ), + ), + act: (cubit) => cubit.update( + WyattFormImpl(inputsA, name: 'otherSignUpForm'), + operation: SetOperation.intersection, + ), + expect: () => [ + SignUpState( + form: WyattFormImpl( + inputsA, + name: AuthFormName.signUpForm, + ), + ), + ], + ); + + blocTest, SignUpState>( + 'emits no state when apply union with the same form', + build: () => SignUpCubit( + authenticationRepository: authenticationRepository, + ), + seed: () => SignUpState( + form: WyattFormImpl( + inputsA, + name: AuthFormName.signUpForm, + ), + ), + act: (cubit) => cubit.update( + WyattFormImpl(inputsA, name: 'otherSignUpForm'), + operation: SetOperation.union, + ), + expect: () => [], + ); + + blocTest, SignUpState>( + 'emits the form union when apply ' + 'union with an another form', + build: () => SignUpCubit( + authenticationRepository: authenticationRepository, + ), + seed: () => SignUpState( + form: WyattFormImpl( + inputsA, + name: AuthFormName.signUpForm, + ), + ), + act: (cubit) => cubit.update( + WyattFormImpl(inputsB, name: 'otherSignUpForm'), + operation: SetOperation.union, + ), + expect: () => [ + SignUpState( + form: WyattFormImpl( + inputsC, + name: AuthFormName.signUpForm, + ), + ), + ], + ); + + blocTest, SignUpState>( + 'emits no state when apply replace with the same form', + build: () => SignUpCubit( + authenticationRepository: authenticationRepository, + ), + seed: () => SignUpState( + form: WyattFormImpl( + inputsA, + name: AuthFormName.signUpForm, + ), + ), + act: (cubit) => cubit.update( + WyattFormImpl(inputsA, name: AuthFormName.signUpForm), + ), + expect: () => [], + ); + + blocTest, SignUpState>( + 'emits a state with a new form after the replacement', + build: () => SignUpCubit( + authenticationRepository: authenticationRepository, + ), + seed: () => SignUpState( + form: WyattFormImpl( + inputsA, + name: AuthFormName.signUpForm, + ), + ), + act: (cubit) => cubit.update( + WyattFormImpl(inputsC, name: AuthFormName.signUpForm), + ), + expect: () => [ + SignUpState( + form: WyattFormImpl( + inputsC, + name: AuthFormName.signUpForm, + ), + ), + ], + ); + }); }); }