feat(tests): updated tests coverage to 66.5%

This commit is contained in:
misha
2026-01-14 18:47:11 +03:00
parent 497ff19cfa
commit 13ccf56df0
102 changed files with 10146 additions and 379 deletions

View File

@@ -0,0 +1,84 @@
import 'package:eatvio_app/features/registration_v2/cubit/registration_state.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('RegistrationStateV2', () {
test('creates instance with default values', () {
const state = RegistrationStateV2();
expect(state.firstName, '');
expect(state.lastName, '');
expect(state.email, '');
expect(state.phone, '');
expect(state.gender, '');
expect(state.password, '');
expect(state.weight, 0);
expect(state.height, 0);
expect(state.activityCoefficient, 1.2);
expect(state.birthday, isNull);
expect(state.isFirstNameValid, isTrue);
expect(state.isLastNameValid, isTrue);
expect(state.isEmailValid, isTrue);
expect(state.isPhoneValid, isTrue);
expect(state.isGenderValid, isTrue);
expect(state.isWeightValid, isTrue);
expect(state.isHeightValid, isTrue);
expect(state.isActivityCoefficientValid, isTrue);
expect(state.isBirthdayValid, isTrue);
expect(state.step, 0);
expect(state.emailDisplayError, '');
expect(state.phoneDisplayError, '');
expect(state.dateOfBirthDisplayError, '');
expect(state.registrationError, isNull);
});
test('creates instance with custom values', () {
final birthday = DateTime(1990, 1, 1);
final state = RegistrationStateV2(
firstName: 'John',
lastName: 'Doe',
email: 'john@example.com',
phone: '+1234567890',
gender: 'male',
password: 'password123',
weight: 70,
height: 175,
activityCoefficient: 1.5,
birthday: birthday,
isFirstNameValid: false,
step: 2,
registrationError: 'Error occurred',
);
expect(state.firstName, 'John');
expect(state.lastName, 'Doe');
expect(state.email, 'john@example.com');
expect(state.phone, '+1234567890');
expect(state.gender, 'male');
expect(state.password, 'password123');
expect(state.weight, 70);
expect(state.height, 175);
expect(state.activityCoefficient, 1.5);
expect(state.birthday, birthday);
expect(state.isFirstNameValid, isFalse);
expect(state.step, 2);
expect(state.registrationError, 'Error occurred');
});
test('copyWith creates new instance with updated values', () {
const original = RegistrationStateV2();
final updated = original.copyWith(
firstName: 'Jane',
email: 'jane@example.com',
step: 1,
);
expect(updated.firstName, 'Jane');
expect(updated.email, 'jane@example.com');
expect(updated.step, 1);
expect(updated.lastName, original.lastName);
expect(updated.phone, original.phone);
});
});
}

View File

@@ -80,5 +80,35 @@ void main() {
expect(model.weight, 80);
expect(model.height, 175);
});
test('toJson serializes RegistrationModel correctly', () {
final model = RegistrationModel(
firstName: 'John',
lastName: 'Doe',
email: 'john.doe@example.com',
phone: '+1234567890',
gender: 'male',
password: 'password123',
confirmPassword: 'password123',
weight: 75,
height: 180,
activityCoefficient: 1.5,
birthday: '1990-01-01',
);
final json = model.toJson();
expect(json['first_name'], 'John');
expect(json['last_name'], 'Doe');
expect(json['email'], 'john.doe@example.com');
expect(json['phone'], '+1234567890');
expect(json['gender'], 'male');
expect(json['password'], 'password123');
expect(json['password_confirmation'], 'password123');
expect(json['weight'], 75);
expect(json['height'], 180);
expect(json['activity_coefficient'], 1.5);
expect(json['birthdate'], '1990-01-01');
});
});
}