Compare commits

..

3 Commits

3 changed files with 180 additions and 1 deletions

View File

@ -23,7 +23,8 @@ import 'package:wyatt_type_utils/wyatt_type_utils.dart';
class AuthenticationMockDataSourceImpl extends AuthenticationRemoteDataSource { class AuthenticationMockDataSourceImpl extends AuthenticationRemoteDataSource {
Pair<Account, String>? _connectedMock; Pair<Account, String>? _connectedMock;
Pair<Account, String>? _registeredMock; Pair<Account, String>? _registeredMock;
final StreamController<Account?> _streamAccount = StreamController(); final StreamController<Account?> _streamAccount = StreamController()
..add(null);
final List<Pair<Account, String>>? registeredAccounts; final List<Pair<Account, String>>? registeredAccounts;
final String idToken; final String idToken;

View File

@ -481,5 +481,178 @@ void main() {
], ],
); );
}); });
group('update', () {
final inputsA = <
FormInput<dynamic, FormInputValidator<dynamic, ValidationError>,
dynamic>>[
FormInput(AuthFormField.email, const Email.pure()),
FormInput(AuthFormField.password, const Password.pure())
];
final inputsB = <
FormInput<dynamic, FormInputValidator<dynamic, ValidationError>,
dynamic>>[
FormInput('name', const Name.pure()),
FormInput('phone', const Phone.pure()),
];
final inputsC = <
FormInput<dynamic, FormInputValidator<dynamic, ValidationError>,
dynamic>>[
FormInput(AuthFormField.email, const Email.pure()),
FormInput(AuthFormField.password, const Password.pure()),
FormInput('name', const Name.pure()),
FormInput('phone', const Phone.pure()),
];
blocTest<SignUpCubit<int>, 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: () => <SignUpState>[],
);
blocTest<SignUpCubit<int>, 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: () => <SignUpState>[],
);
blocTest<SignUpCubit<int>, 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>[
SignUpState(
form: WyattFormImpl(
inputsA,
name: AuthFormName.signUpForm,
),
),
],
);
blocTest<SignUpCubit<int>, 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: () => <SignUpState>[],
);
blocTest<SignUpCubit<int>, 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>[
SignUpState(
form: WyattFormImpl(
inputsC,
name: AuthFormName.signUpForm,
),
),
],
);
blocTest<SignUpCubit<int>, 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: () => <SignUpState>[],
);
blocTest<SignUpCubit<int>, 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>[
SignUpState(
form: WyattFormImpl(
inputsC,
name: AuthFormName.signUpForm,
),
),
],
);
});
}); });
} }

View File

@ -59,6 +59,11 @@ void main() {
final result = const FormReplace().call(formA, formB); final result = const FormReplace().call(formA, formB);
expect(result, formB); expect(result, formB);
}); });
test('returns A when called on (A,A)', () {
final result = const FormReplace().call(formA, formA);
expect(result, formA);
});
}); });
group('FormUnion', () { group('FormUnion', () {