forked from eatvio/eatvio_app
feat(diary): tests
This commit is contained in:
221
test/features/registration_v2/cubit/registration_cubit_test.dart
Normal file
221
test/features/registration_v2/cubit/registration_cubit_test.dart
Normal file
@@ -0,0 +1,221 @@
|
||||
import 'package:eatvio_app/features/registration_v2/cubit/registration_cubit.dart';
|
||||
import 'package:eatvio_app/features/registration_v2/cubit/registration_state.dart';
|
||||
import 'package:eatvio_app/features/registration_v2/repositories/registration_repository_v2.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<RegistrationRepositoryV2>()])
|
||||
import 'registration_cubit_test.mocks.dart';
|
||||
|
||||
void main() {
|
||||
late RegistrationCubitV2 cubit;
|
||||
late MockRegistrationRepositoryV2 mockRepo;
|
||||
|
||||
setUp(() {
|
||||
mockRepo = MockRegistrationRepositoryV2();
|
||||
cubit = RegistrationCubitV2(registrationRepository: mockRepo);
|
||||
});
|
||||
|
||||
tearDown(() => cubit.close());
|
||||
|
||||
group('RegistrationCubitV2', () {
|
||||
test('initial state', () {
|
||||
expect(cubit.state, const RegistrationStateV2());
|
||||
});
|
||||
|
||||
group('setters', () {
|
||||
test('setFirstName updates firstName', () {
|
||||
cubit.setFirstName('Иван');
|
||||
expect(cubit.state.firstName, 'Иван');
|
||||
});
|
||||
|
||||
test('setLastName updates lastName', () {
|
||||
cubit.setLastName('Иванов');
|
||||
expect(cubit.state.lastName, 'Иванов');
|
||||
});
|
||||
|
||||
test('setEmail updates email', () {
|
||||
cubit.setEmail('test@test.com');
|
||||
expect(cubit.state.email, 'test@test.com');
|
||||
});
|
||||
|
||||
test('setPhone updates phone', () {
|
||||
cubit.setPhone('+79001234567');
|
||||
expect(cubit.state.phone, '+79001234567');
|
||||
});
|
||||
|
||||
test('setBirthday updates birthday', () {
|
||||
final date = DateTime(1990, 1, 1);
|
||||
cubit.setBirthday(date);
|
||||
expect(cubit.state.birthday, date);
|
||||
});
|
||||
|
||||
test('setGender updates gender', () {
|
||||
cubit.setGender('male');
|
||||
expect(cubit.state.gender, 'male');
|
||||
});
|
||||
|
||||
test('setWeight updates weight', () {
|
||||
cubit.setWeight(70);
|
||||
expect(cubit.state.weight, 70);
|
||||
});
|
||||
|
||||
test('setHeight updates height', () {
|
||||
cubit.setHeight(175);
|
||||
expect(cubit.state.height, 175);
|
||||
});
|
||||
|
||||
test('setActivityCoefficient updates activityCoefficient', () {
|
||||
cubit.setActivityCoefficient(1.2);
|
||||
expect(cubit.state.activityCoefficient, 1.2);
|
||||
});
|
||||
|
||||
test('setPassword updates password', () {
|
||||
cubit.setPassword('secret123');
|
||||
expect(cubit.state.password, 'secret123');
|
||||
});
|
||||
});
|
||||
|
||||
group('validators', () {
|
||||
test('validateFirstName returns false for empty', () {
|
||||
expect(cubit.validateFirstName(), false);
|
||||
expect(cubit.state.isFirstNameValid, false);
|
||||
});
|
||||
|
||||
test('validateFirstName returns true for non-empty', () {
|
||||
cubit.setFirstName('Иван');
|
||||
expect(cubit.validateFirstName(), true);
|
||||
expect(cubit.state.isFirstNameValid, true);
|
||||
});
|
||||
|
||||
test('validateLastName returns false for empty', () {
|
||||
expect(cubit.validateLastName(), false);
|
||||
expect(cubit.state.isLastNameValid, false);
|
||||
});
|
||||
|
||||
test('validateLastName returns true for non-empty', () {
|
||||
cubit.setLastName('Иванов');
|
||||
expect(cubit.validateLastName(), true);
|
||||
expect(cubit.state.isLastNameValid, true);
|
||||
});
|
||||
|
||||
test('validateEmail returns false for empty', () {
|
||||
expect(cubit.validateEmail(), false);
|
||||
expect(cubit.state.isEmailValid, false);
|
||||
});
|
||||
|
||||
test('validateEmail returns true for non-empty', () {
|
||||
cubit.setEmail('test@test.com');
|
||||
expect(cubit.validateEmail(), true);
|
||||
expect(cubit.state.isEmailValid, true);
|
||||
});
|
||||
|
||||
test('validatePhone returns false for empty', () {
|
||||
expect(cubit.validatePhone(), false);
|
||||
expect(cubit.state.isPhoneValid, false);
|
||||
});
|
||||
|
||||
test('validatePhone returns true for non-empty', () {
|
||||
cubit.setPhone('+79001234567');
|
||||
expect(cubit.validatePhone(), true);
|
||||
expect(cubit.state.isPhoneValid, true);
|
||||
});
|
||||
|
||||
test('validateGender returns false for empty', () {
|
||||
expect(cubit.validateGender(), false);
|
||||
expect(cubit.state.isGenderValid, false);
|
||||
});
|
||||
|
||||
test('validateGender returns true for non-empty', () {
|
||||
cubit.setGender('male');
|
||||
expect(cubit.validateGender(), true);
|
||||
expect(cubit.state.isGenderValid, true);
|
||||
});
|
||||
|
||||
test('validateWeight returns false for 0', () {
|
||||
expect(cubit.validateWeight(), false);
|
||||
expect(cubit.state.isWeightValid, false);
|
||||
});
|
||||
|
||||
test('validateWeight returns true for non-zero', () {
|
||||
cubit.setWeight(70);
|
||||
expect(cubit.validateWeight(), true);
|
||||
expect(cubit.state.isWeightValid, true);
|
||||
});
|
||||
|
||||
test('validateHeight returns false for 0', () {
|
||||
expect(cubit.validateHeight(), false);
|
||||
expect(cubit.state.isHeightValid, false);
|
||||
});
|
||||
|
||||
test('validateHeight returns true for non-zero', () {
|
||||
cubit.setHeight(175);
|
||||
expect(cubit.validateHeight(), true);
|
||||
expect(cubit.state.isHeightValid, true);
|
||||
});
|
||||
|
||||
test('validateActivityCoefficient returns false for 0', () {
|
||||
// Set to 0 explicitly since default is 1.2
|
||||
cubit.setActivityCoefficient(0);
|
||||
expect(cubit.validateActivityCoefficient(), false);
|
||||
expect(cubit.state.isActivityCoefficientValid, false);
|
||||
});
|
||||
|
||||
test('validateActivityCoefficient returns true for non-zero', () {
|
||||
cubit.setActivityCoefficient(1.5);
|
||||
expect(cubit.validateActivityCoefficient(), true);
|
||||
expect(cubit.state.isActivityCoefficientValid, true);
|
||||
});
|
||||
|
||||
test('validateBirthday returns false for null', () {
|
||||
expect(cubit.validateBirthday(), false);
|
||||
expect(cubit.state.isBirthdayValid, false);
|
||||
});
|
||||
|
||||
test('validateBirthday returns true for non-null', () {
|
||||
cubit.setBirthday(DateTime(1990, 1, 1));
|
||||
expect(cubit.validateBirthday(), true);
|
||||
expect(cubit.state.isBirthdayValid, true);
|
||||
});
|
||||
});
|
||||
|
||||
group('navigation', () {
|
||||
test('nextStep sets step to 1', () {
|
||||
cubit.nextStep();
|
||||
expect(cubit.state.step, 1);
|
||||
});
|
||||
|
||||
test('prevStep sets step to 0', () {
|
||||
cubit.nextStep();
|
||||
cubit.prevStep();
|
||||
expect(cubit.state.step, 0);
|
||||
});
|
||||
});
|
||||
|
||||
group('validateAllFields', () {
|
||||
test('returns false when firstName empty', () {
|
||||
expect(cubit.validateAllFields(), false);
|
||||
});
|
||||
|
||||
test('returns true when all fields valid', () {
|
||||
cubit.setFirstName('Иван');
|
||||
cubit.setLastName('Иванов');
|
||||
cubit.setEmail('test@test.com');
|
||||
cubit.setPhone('+79001234567');
|
||||
cubit.setGender('male');
|
||||
cubit.setWeight(70);
|
||||
cubit.setHeight(175);
|
||||
cubit.setActivityCoefficient(1.2);
|
||||
cubit.setBirthday(DateTime(1990, 1, 1));
|
||||
expect(cubit.validateAllFields(), true);
|
||||
});
|
||||
});
|
||||
|
||||
group('register', () {
|
||||
test('returns (false, true) when validation fails', () async {
|
||||
final result = await cubit.register();
|
||||
expect(result, (false, true));
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user