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

@@ -3,40 +3,54 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
group('ViewModel', () {
test('создает ViewModel с правильными значениями', () {
final model = ViewModel(
type: 'blog_posts',
ids: [1, 2, 3],
slugs: null,
);
expect(model.type, 'blog_posts');
expect(model.ids, [1, 2, 3]);
expect(model.slugs, isNull);
});
test('создает ViewModel с slugs', () {
final model = ViewModel(
type: 'plans',
ids: null,
slugs: ['plan-1', 'plan-2'],
);
expect(model.type, 'plans');
expect(model.slugs, ['plan-1', 'plan-2']);
});
test('fromJson создает ViewModel из JSON', () {
test('fromJson parses all fields correctly', () {
final json = {
'type': 'diets',
'ids': [1, 2],
'type': 'diet',
'ids': [1, 2, 3],
'slugs': ['diet-1', 'diet-2'],
};
final model = ViewModel.fromJson(json);
expect(model.type, 'diets');
expect(model.ids, [1, 2]);
expect(model.type, 'diet');
expect(model.ids, [1, 2, 3]);
expect(model.slugs, ['diet-1', 'diet-2']);
});
test('fromJson handles null optional fields', () {
final json = {
'type': 'plan',
};
final model = ViewModel.fromJson(json);
expect(model.type, 'plan');
expect(model.ids, isNull);
expect(model.slugs, isNull);
});
test('toJson serializes all fields correctly', () {
final model = ViewModel(
type: 'recipe',
ids: [1, 2],
slugs: ['recipe-1'],
);
final json = model.toJson();
expect(json['type'], 'recipe');
expect(json['ids'], [1, 2]);
expect(json['slugs'], ['recipe-1']);
});
test('toJson omits null fields', () {
final model = ViewModel(type: 'diet');
final json = model.toJson();
expect(json['type'], 'diet');
expect(json.containsKey('ids'), isTrue);
expect(json.containsKey('slugs'), isTrue);
});
});
}