forked from eatvio/eatvio_app
chore(dependencies): add webview_flutter_platform_interface package to pubspec.yaml and clean up test files by removing unnecessary whitespace
This commit is contained in:
@@ -3,35 +3,113 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('ChosenDietsPaginationModel', () {
|
||||
test('создает ChosenDietsPaginationModel с правильными значениями', () {
|
||||
final chosenDiet = ChosenDietModel(
|
||||
chosenDietID: 1,
|
||||
chosenPlanId: 1,
|
||||
state: 'inited',
|
||||
startDate: DateTime(2024, 1, 1),
|
||||
dietId: 1,
|
||||
);
|
||||
test('creates ChosenDietsPaginationModel with empty list', () {
|
||||
final model = ChosenDietsPaginationModel(diets: []);
|
||||
|
||||
final pagination = ChosenDietsPaginationModel(diets: [chosenDiet]);
|
||||
expect(model.diets, isEmpty);
|
||||
});
|
||||
|
||||
expect(pagination.diets.length, 1);
|
||||
expect(pagination.diets.first.chosenDietID, 1);
|
||||
expect(pagination.diets.first.state, 'inited');
|
||||
test('creates ChosenDietsPaginationModel with diets', () {
|
||||
final diets = [
|
||||
ChosenDietModel(
|
||||
chosenDietID: 1,
|
||||
chosenPlanId: 10,
|
||||
state: 'active',
|
||||
startDate: DateTime(2023, 1, 1),
|
||||
dietId: 5,
|
||||
),
|
||||
ChosenDietModel(
|
||||
chosenDietID: 2,
|
||||
chosenPlanId: 11,
|
||||
state: 'completed',
|
||||
startDate: DateTime(2023, 2, 1),
|
||||
dietId: 6,
|
||||
),
|
||||
];
|
||||
|
||||
final model = ChosenDietsPaginationModel(diets: diets);
|
||||
|
||||
expect(model.diets.length, 2);
|
||||
expect(model.diets[0].chosenDietID, 1);
|
||||
expect(model.diets[0].state, 'active');
|
||||
expect(model.diets[1].chosenDietID, 2);
|
||||
expect(model.diets[1].state, 'completed');
|
||||
});
|
||||
|
||||
test('creates ChosenDietsPaginationModel with null dietId', () {
|
||||
final diets = [
|
||||
ChosenDietModel(
|
||||
chosenDietID: 1,
|
||||
chosenPlanId: 10,
|
||||
state: 'active',
|
||||
startDate: DateTime(2023, 1, 1),
|
||||
dietId: null,
|
||||
),
|
||||
];
|
||||
|
||||
final model = ChosenDietsPaginationModel(diets: diets);
|
||||
|
||||
expect(model.diets.length, 1);
|
||||
expect(model.diets[0].dietId, null);
|
||||
});
|
||||
|
||||
test('creates ChosenDietsPaginationModel from JSON', () {
|
||||
final json = {
|
||||
'data': [
|
||||
{
|
||||
'id': 1,
|
||||
'chosen_plan_id': 10,
|
||||
'state': 'active',
|
||||
'start_date': '2023-01-01T00:00:00Z',
|
||||
'diet': {'id': 5},
|
||||
},
|
||||
{
|
||||
'id': 2,
|
||||
'chosen_plan_id': 11,
|
||||
'state': 'completed',
|
||||
'start_date': '2023-02-01T00:00:00Z',
|
||||
'diet': null,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
final model = ChosenDietsPaginationModel.fromJson(json);
|
||||
|
||||
expect(model.diets.length, 2);
|
||||
expect(model.diets[0].chosenDietID, 1);
|
||||
expect(model.diets[0].dietId, 5);
|
||||
expect(model.diets[1].chosenDietID, 2);
|
||||
expect(model.diets[1].dietId, null);
|
||||
});
|
||||
});
|
||||
|
||||
group('ChosenDietModel', () {
|
||||
test('создает ChosenDietModel с null dietId', () {
|
||||
final chosenDiet = ChosenDietModel(
|
||||
test('creates ChosenDietModel with all parameters', () {
|
||||
final model = ChosenDietModel(
|
||||
chosenDietID: 1,
|
||||
chosenPlanId: 1,
|
||||
state: 'inited',
|
||||
startDate: DateTime(2024, 1, 1),
|
||||
chosenPlanId: 10,
|
||||
state: 'active',
|
||||
startDate: DateTime(2023, 1, 1),
|
||||
dietId: 5,
|
||||
);
|
||||
|
||||
expect(model.chosenDietID, 1);
|
||||
expect(model.chosenPlanId, 10);
|
||||
expect(model.state, 'active');
|
||||
expect(model.startDate, DateTime(2023, 1, 1));
|
||||
expect(model.dietId, 5);
|
||||
});
|
||||
|
||||
test('creates ChosenDietModel with null dietId', () {
|
||||
final model = ChosenDietModel(
|
||||
chosenDietID: 1,
|
||||
chosenPlanId: 10,
|
||||
state: 'active',
|
||||
startDate: DateTime(2023, 1, 1),
|
||||
dietId: null,
|
||||
);
|
||||
|
||||
expect(chosenDiet.dietId, isNull);
|
||||
expect(model.dietId, null);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -3,24 +3,57 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('PassKeyParams', () {
|
||||
test('создает PassKeyParams с правильными значениями', () {
|
||||
final model = PassKeyParams(
|
||||
routeName: '/profile',
|
||||
routeParams: {'id': 1},
|
||||
test('creates PassKeyParams with routeName and routeParams', () {
|
||||
final params = PassKeyParams(
|
||||
routeName: '/home',
|
||||
routeParams: {'id': '123', 'name': 'test'},
|
||||
);
|
||||
|
||||
expect(model.routeName, '/profile');
|
||||
expect(model.routeParams, {'id': 1});
|
||||
expect(params.routeName, '/home');
|
||||
expect(params.routeParams, {'id': '123', 'name': 'test'});
|
||||
});
|
||||
|
||||
test('создает PassKeyParams без routeParams', () {
|
||||
final model = PassKeyParams(
|
||||
test('creates PassKeyParams with null routeParams', () {
|
||||
final params = PassKeyParams(
|
||||
routeName: '/profile',
|
||||
routeParams: null,
|
||||
);
|
||||
|
||||
expect(model.routeParams, isNull);
|
||||
expect(params.routeName, '/profile');
|
||||
expect(params.routeParams, null);
|
||||
});
|
||||
|
||||
test('creates PassKeyParams from JSON with routeParams', () {
|
||||
final json = {
|
||||
'route_name': '/details',
|
||||
'route_params': {'id': '456', 'type': 'recipe'},
|
||||
};
|
||||
|
||||
final params = PassKeyParams.fromJson(json);
|
||||
|
||||
expect(params.routeName, '/details');
|
||||
expect(params.routeParams, {'id': '456', 'type': 'recipe'});
|
||||
});
|
||||
|
||||
test('creates PassKeyParams from JSON without routeParams', () {
|
||||
final json = {
|
||||
'route_name': '/settings',
|
||||
};
|
||||
|
||||
final params = PassKeyParams.fromJson(json);
|
||||
|
||||
expect(params.routeName, '/settings');
|
||||
expect(params.routeParams, null);
|
||||
});
|
||||
|
||||
test('creates PassKeyParams with empty routeParams', () {
|
||||
final params = PassKeyParams(
|
||||
routeName: '/empty',
|
||||
routeParams: {},
|
||||
);
|
||||
|
||||
expect(params.routeName, '/empty');
|
||||
expect(params.routeParams, {});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,62 +1,183 @@
|
||||
import 'package:eatvio_app/core/models/pagination_model.dart';
|
||||
import 'package:eatvio_app/features/profile/models/sub_model.dart';
|
||||
import 'package:eatvio_app/core/models/pagination_model.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('SubModel', () {
|
||||
test('создает SubModel с правильными значениями', () {
|
||||
final model = SubModel(
|
||||
slug: 'user-slug',
|
||||
name: 'User Name',
|
||||
city: 'Moscow',
|
||||
birthdate: DateTime(1990, 1, 1),
|
||||
isEntitySubscribedByMe: true,
|
||||
profilePhotoUrl: 'https://example.com/photo.jpg',
|
||||
roles: ['consultant'],
|
||||
group('SubPaginationModel', () {
|
||||
test('creates SubPaginationModel with empty list', () {
|
||||
const links = Links(
|
||||
first: 'http://example.com?page=1',
|
||||
last: 'http://example.com?page=1',
|
||||
prev: null,
|
||||
next: null,
|
||||
);
|
||||
|
||||
expect(model.slug, 'user-slug');
|
||||
expect(model.name, 'User Name');
|
||||
expect(model.city, 'Moscow');
|
||||
expect(model.isEntitySubscribedByMe, isTrue);
|
||||
expect(model.roles, ['consultant']);
|
||||
const meta = Meta(
|
||||
currentPage: 1,
|
||||
from: null,
|
||||
lastPage: 1,
|
||||
links: [],
|
||||
path: '/api/subs',
|
||||
perPage: 10,
|
||||
to: null,
|
||||
total: 0,
|
||||
);
|
||||
|
||||
const model = SubPaginationModel(
|
||||
data: [],
|
||||
links: links,
|
||||
meta: meta,
|
||||
);
|
||||
|
||||
expect(model.data, isEmpty);
|
||||
expect(model.meta.total, 0);
|
||||
});
|
||||
|
||||
test('creates SubPaginationModel with subs', () {
|
||||
final subs = [
|
||||
SubModel(
|
||||
slug: 'user1',
|
||||
name: 'User One',
|
||||
city: 'New York',
|
||||
birthdate: DateTime(1990, 1, 1),
|
||||
isEntitySubscribedByMe: true,
|
||||
profilePhotoUrl: 'photo1.jpg',
|
||||
roles: ['consultant'],
|
||||
),
|
||||
SubModel(
|
||||
slug: 'user2',
|
||||
name: 'User Two',
|
||||
city: 'London',
|
||||
birthdate: DateTime(1995, 5, 15),
|
||||
isEntitySubscribedByMe: false,
|
||||
profilePhotoUrl: 'photo2.jpg',
|
||||
roles: ['user'],
|
||||
),
|
||||
];
|
||||
|
||||
const links = Links(
|
||||
first: 'http://example.com?page=1',
|
||||
last: 'http://example.com?page=1',
|
||||
prev: null,
|
||||
next: null,
|
||||
);
|
||||
|
||||
const meta = Meta(
|
||||
currentPage: 1,
|
||||
from: 1,
|
||||
lastPage: 1,
|
||||
links: [],
|
||||
path: '/api/subs',
|
||||
perPage: 10,
|
||||
to: 2,
|
||||
total: 2,
|
||||
);
|
||||
|
||||
final model = SubPaginationModel(
|
||||
data: subs,
|
||||
links: links,
|
||||
meta: meta,
|
||||
);
|
||||
|
||||
expect(model.data.length, 2);
|
||||
expect(model.data[0].slug, 'user1');
|
||||
expect(model.data[0].name, 'User One');
|
||||
expect(model.data[1].slug, 'user2');
|
||||
expect(model.data[1].name, 'User Two');
|
||||
});
|
||||
|
||||
test('creates SubPaginationModel from JSON', () {
|
||||
final json = {
|
||||
'data': [
|
||||
{
|
||||
'slug': 'user1',
|
||||
'name': 'User One',
|
||||
'city': 'New York',
|
||||
'birthdate': '1990-01-01T00:00:00Z',
|
||||
'is_entity_subscribed_by_me': true,
|
||||
'profile_photo_url': 'photo1.jpg',
|
||||
'roles': ['consultant'],
|
||||
},
|
||||
],
|
||||
'links': {
|
||||
'first': 'http://example.com?page=1',
|
||||
'last': 'http://example.com?page=1',
|
||||
'prev': null,
|
||||
'next': null,
|
||||
},
|
||||
'meta': {
|
||||
'current_page': 1,
|
||||
'from': 1,
|
||||
'last_page': 1,
|
||||
'links': [],
|
||||
'path': '/api/subs',
|
||||
'per_page': 10,
|
||||
'to': 1,
|
||||
'total': 1,
|
||||
},
|
||||
};
|
||||
|
||||
final model = SubPaginationModel.fromJson(json);
|
||||
|
||||
expect(model.data.length, 1);
|
||||
expect(model.data[0].slug, 'user1');
|
||||
expect(model.data[0].name, 'User One');
|
||||
});
|
||||
});
|
||||
|
||||
group('SubPaginationModel', () {
|
||||
test('создает SubPaginationModel с правильными значениями', () {
|
||||
group('SubModel', () {
|
||||
test('creates SubModel with all parameters', () {
|
||||
final sub = SubModel(
|
||||
slug: 'user-slug',
|
||||
name: 'User Name',
|
||||
city: 'Moscow',
|
||||
slug: 'user1',
|
||||
name: 'User One',
|
||||
city: 'New York',
|
||||
birthdate: DateTime(1990, 1, 1),
|
||||
isEntitySubscribedByMe: true,
|
||||
profilePhotoUrl: 'https://example.com/photo.jpg',
|
||||
roles: ['consultant'],
|
||||
profilePhotoUrl: 'photo1.jpg',
|
||||
roles: ['consultant', 'nutritionist'],
|
||||
);
|
||||
|
||||
final pagination = SubPaginationModel(
|
||||
data: [sub],
|
||||
links: const Links(
|
||||
first: 'https://example.com?page=1',
|
||||
last: 'https://example.com?page=1',
|
||||
prev: null,
|
||||
next: null,
|
||||
),
|
||||
meta: const Meta(
|
||||
currentPage: 1,
|
||||
from: 1,
|
||||
lastPage: 1,
|
||||
links: [],
|
||||
perPage: 10,
|
||||
to: 1,
|
||||
total: 1,
|
||||
),
|
||||
expect(sub.slug, 'user1');
|
||||
expect(sub.name, 'User One');
|
||||
expect(sub.city, 'New York');
|
||||
expect(sub.birthdate, DateTime(1990, 1, 1));
|
||||
expect(sub.isEntitySubscribedByMe, true);
|
||||
expect(sub.profilePhotoUrl, 'photo1.jpg');
|
||||
expect(sub.roles.length, 2);
|
||||
expect(sub.roles, contains('consultant'));
|
||||
expect(sub.roles, contains('nutritionist'));
|
||||
});
|
||||
|
||||
test('creates SubModel with empty roles', () {
|
||||
final sub = SubModel(
|
||||
slug: 'user2',
|
||||
name: 'User Two',
|
||||
city: 'London',
|
||||
birthdate: DateTime(1995, 5, 15),
|
||||
isEntitySubscribedByMe: false,
|
||||
profilePhotoUrl: 'photo2.jpg',
|
||||
roles: [],
|
||||
);
|
||||
|
||||
expect(pagination.data.length, 1);
|
||||
expect(pagination.data.first.slug, 'user-slug');
|
||||
expect(sub.roles, isEmpty);
|
||||
});
|
||||
|
||||
test('creates SubModel from JSON', () {
|
||||
final json = {
|
||||
'slug': 'user1',
|
||||
'name': 'User One',
|
||||
'city': 'New York',
|
||||
'birthdate': '1990-01-01T00:00:00Z',
|
||||
'is_entity_subscribed_by_me': true,
|
||||
'profile_photo_url': 'photo1.jpg',
|
||||
'roles': ['consultant'],
|
||||
};
|
||||
|
||||
final sub = SubModel.fromJson(json);
|
||||
|
||||
expect(sub.slug, 'user1');
|
||||
expect(sub.name, 'User One');
|
||||
expect(sub.isEntitySubscribedByMe, true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user