forked from eatvio/eatvio_app
95 lines
2.8 KiB
Dart
95 lines
2.8 KiB
Dart
import 'package:eatvio_app/core/models/pagination_model.dart';
|
||
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
|
||
import 'package:flutter_test/flutter_test.dart';
|
||
|
||
void main() {
|
||
group('DietsPagination', () {
|
||
test('создает DietsPagination с правильными значениями', () {
|
||
const diet = Diet(
|
||
id: 1,
|
||
slug: 'test-diet',
|
||
name: 'Test Diet',
|
||
image: 'https://example.com/image.jpg',
|
||
duration: 7,
|
||
state: DietState.active,
|
||
type: DietType(veg: true, light: false, carb: false, meat: false),
|
||
details: 'Test details',
|
||
dailySchedule: {},
|
||
author: Author(
|
||
authorSlug: 'author',
|
||
authorName: 'Author Name',
|
||
authorProfileIcon: 'https://example.com/icon.jpg',
|
||
authorIsMe: false,
|
||
isEntitySubscribedByMe: null,
|
||
authorPlaceInRating: null,
|
||
),
|
||
totalLikes: 10,
|
||
totalViews: 100,
|
||
totalComments: 5,
|
||
wasLikedByMe: false,
|
||
isFavorite: false,
|
||
dailyNutrition: [],
|
||
);
|
||
|
||
const pagination = DietsPagination(
|
||
data: [diet],
|
||
links: Links(
|
||
first: 'https://example.com?page=1',
|
||
last: 'https://example.com?page=1',
|
||
prev: null,
|
||
next: null,
|
||
),
|
||
meta: Meta(
|
||
currentPage: 1,
|
||
from: 1,
|
||
lastPage: 1,
|
||
links: [],
|
||
perPage: 10,
|
||
to: 1,
|
||
total: 1,
|
||
),
|
||
);
|
||
|
||
expect(pagination.data.length, 1);
|
||
expect(pagination.data.first.id, 1);
|
||
expect(pagination.data.first.name, 'Test Diet');
|
||
});
|
||
});
|
||
|
||
group('Author', () {
|
||
test('fromJson читает author_roles и определяет админа', () {
|
||
final author = Author.fromJson({
|
||
'author_slug': 'admin-user',
|
||
'author_name': 'Admin',
|
||
'author_profile_icon': 'icon.jpg',
|
||
'author_is_me': false,
|
||
'author_roles': ['admin', 'consultant'],
|
||
});
|
||
|
||
expect(author.authorRoles, ['admin', 'consultant']);
|
||
expect(author.isAdmin, isTrue);
|
||
});
|
||
|
||
test('fromJson без author_roles не считает автора админом', () {
|
||
final author = Author.fromJson({
|
||
'author_slug': 'regular-user',
|
||
'author_name': 'User',
|
||
'author_profile_icon': 'icon.jpg',
|
||
'author_is_me': false,
|
||
});
|
||
|
||
expect(author.authorRoles, isEmpty);
|
||
expect(author.isAdmin, isFalse);
|
||
});
|
||
});
|
||
|
||
group('DietState', () {
|
||
test('toString возвращает правильные значения', () {
|
||
expect(DietState.active.toString(), 'active');
|
||
expect(DietState.draft.toString(), 'drafted');
|
||
expect(DietState.personal.toString(), 'personal');
|
||
});
|
||
});
|
||
}
|
||
|