feat(dependencies): add rxdart package and improve string extension methods for better handling of empty strings and gender parsing

This commit is contained in:
mso7nueh
2025-12-04 15:45:54 +03:00
parent 0cd8e662d9
commit 953230b387
100 changed files with 7202 additions and 14 deletions

View File

@@ -0,0 +1,69 @@
import 'package:eatvio_app/core/models/pagination_model.dart';
import 'package:eatvio_app/features/feed/models/comment_model.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('CommentModel', () {
test('создает CommentModel с правильными значениями', () {
final comment = Comment(
id: 1,
authorName: 'Author Name',
authorSlug: 'author',
authorProfileIcon: 'https://example.com/icon.jpg',
body: 'Test comment',
childrenComments: [],
createdAt: DateTime(2024, 1, 1),
);
final model = CommentModel(
data: [comment],
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(model.data.length, 1);
expect(model.data.first.id, 1);
expect(model.data.first.body, 'Test comment');
});
});
group('Comment', () {
test('создает Comment с вложенными комментариями', () {
final childComment = Comment(
id: 2,
authorName: 'Child Author',
authorSlug: 'child-author',
authorProfileIcon: 'https://example.com/icon2.jpg',
body: 'Child comment',
childrenComments: [],
createdAt: DateTime(2024, 1, 2),
);
final parentComment = Comment(
id: 1,
authorName: 'Author Name',
authorSlug: 'author',
authorProfileIcon: 'https://example.com/icon.jpg',
body: 'Parent comment',
childrenComments: [childComment],
createdAt: DateTime(2024, 1, 1),
);
expect(parentComment.childrenComments.length, 1);
expect(parentComment.childrenComments.first.id, 2);
});
});
}

View File

@@ -0,0 +1,67 @@
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('DietState', () {
test('toString возвращает правильные значения', () {
expect(DietState.active.toString(), 'active');
expect(DietState.draft.toString(), 'drafted');
expect(DietState.personal.toString(), 'personal');
});
});
}

View File

@@ -0,0 +1,67 @@
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
import 'package:eatvio_app/features/feed/models/feed_blog_post_model.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('FeedBlogPostModel', () {
test('создает FeedBlogPostModel с правильными значениями', () {
final model = FeedBlogPostModel(
id: 1,
state: 'published',
image: 'https://example.com/image.jpg',
description: 'Test description',
author: const Author(
authorSlug: 'author',
authorName: 'Author Name',
authorProfileIcon: 'https://example.com/icon.jpg',
authorIsMe: false,
isEntitySubscribedByMe: null,
authorPlaceInRating: null,
),
videoUrl: '',
createdAt: DateTime(2024, 1, 1),
updatedAt: DateTime(2024, 1, 2),
title: 'Test Post',
totalLikes: 10,
totalViews: 100,
totalComments: 5,
wasLikedByMe: false,
);
expect(model.id, 1);
expect(model.title, 'Test Post');
expect(model.totalLikes, 10);
expect(model.wasLikedByMe, isFalse);
});
test('fromJson создает FeedBlogPostModel из JSON', () {
final json = {
'id': 1,
'state': 'published',
'image': 'https://example.com/image.jpg',
'description': 'Test description',
'author': {
'author_slug': 'author',
'author_name': 'Author Name',
'author_profile_icon': 'https://example.com/icon.jpg',
'author_is_me': false,
},
'video_url': '',
'created_at': '2024-01-01T00:00:00Z',
'updated_at': '2024-01-02T00:00:00Z',
'title': 'Test Post',
'total_likes': 10,
'total_views': 100,
'total_comments': 5,
'was_liked_by_me': false,
};
final model = FeedBlogPostModel.fromJson(json);
expect(model.id, 1);
expect(model.title, 'Test Post');
expect(model.totalLikes, 10);
});
});
}

View File

@@ -0,0 +1,52 @@
import 'package:eatvio_app/core/models/pagination_model.dart';
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
import 'package:eatvio_app/features/feed/models/feed_blog_post_model.dart';
import 'package:eatvio_app/features/feed/models/feed_blog_post_settings_model.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('FeedBlogPostSettingsModel', () {
test('создает FeedBlogPostSettingsModel с правильными значениями', () {
final blogPost = FeedBlogPostModel(
id: 1,
state: 'active',
image: 'https://example.com/image.jpg',
description: 'Test description',
author: const Author(
authorSlug: 'author',
authorName: 'Author Name',
authorProfileIcon: 'https://example.com/icon.jpg',
authorIsMe: false,
isEntitySubscribedByMe: null,
authorPlaceInRating: null,
),
videoUrl: 'https://example.com/video.mp4',
createdAt: DateTime(2024, 1, 1),
updatedAt: DateTime(2024, 1, 2),
title: 'Test Post',
totalLikes: 10,
totalViews: 100,
totalComments: 5,
wasLikedByMe: false,
);
final model = FeedBlogPostSettingsModel(
feedBlogPostList: [blogPost],
meta: const Meta(
currentPage: 1,
from: 1,
lastPage: 1,
links: [],
perPage: 10,
to: 1,
total: 1,
),
);
expect(model.feedBlogPostList.length, 1);
expect(model.feedBlogPostList.first.id, 1);
expect(model.meta.total, 1);
});
});
}

View File

@@ -0,0 +1,95 @@
import 'package:eatvio_app/core/models/pagination_model.dart';
import 'package:eatvio_app/features/feed/models/feed_consultant_model.dart';
import 'package:eatvio_app/features/profile/models/badge_model.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('FeedConsultantModel', () {
test('создает FeedConsultantModel с правильными значениями', () {
const model = FeedConsultantModel(
slug: 'consultant-1',
name: 'Consultant Name',
description: 'Test description',
ratingPlace: 1,
totalScores: 450,
photo: 'https://example.com/photo.jpg',
badges: [
BadgeModel(
id: 1,
title: 'Badge 1',
description: 'Description',
image: 'https://example.com/badge1.jpg',
type: 'type',
),
],
);
expect(model.slug, 'consultant-1');
expect(model.name, 'Consultant Name');
expect(model.totalScores, 450);
expect(model.badges.length, 1);
});
test('fromJson создает FeedConsultantModel из JSON', () {
final json = {
'slug': 'consultant-1',
'name': 'Consultant Name',
'additional_info': 'Test description',
'rating_place': 1,
'total_scores': 450,
'profile_photo_url': 'https://example.com/photo.jpg',
'badges': [
{
'id': 1,
'title': 'Badge 1',
'description': 'Description',
'image': 'https://example.com/badge1.jpg',
'type': 'type'
},
],
};
final model = FeedConsultantModel.fromJson(json);
expect(model.slug, 'consultant-1');
expect(model.totalScores, 450);
});
});
group('FeedConsultantPaginationModel', () {
test('создает FeedConsultantPaginationModel с правильными значениями', () {
const consultant = FeedConsultantModel(
slug: 'consultant-1',
name: 'Consultant Name',
description: 'Test description',
ratingPlace: null,
totalScores: 450,
photo: 'https://example.com/photo.jpg',
badges: [],
);
const pagination = FeedConsultantPaginationModel(
data: [consultant],
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.slug, 'consultant-1');
});
});
}

View File

@@ -0,0 +1,61 @@
import 'package:eatvio_app/core/models/pagination_model.dart';
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('PlanPaginationModel', () {
test('создает PlanPaginationModel с правильными значениями', () {
const plan = PlanModel(
id: 1,
slug: 'test-plan',
name: 'Test Plan',
image: 'https://example.com/image.jpg',
duration: 7,
state: 'active',
type: PlanType(fit: true, slim: false, behavior: false, wellness: false),
details: 'Test details',
packetsCount: 3,
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,
isFavorite: false,
minPriceOfOptions: 1000,
maxPriceOfOptions: 2000,
wasLikedByMe: false,
);
const pagination = PlanPaginationModel(
data: [plan],
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 Plan');
});
});
}

View File

@@ -0,0 +1,50 @@
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
import 'package:eatvio_app/features/feed/models/recipes_model.dart';
import 'package:eatvio_app/features/feed/models/recipes_pagination_model.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('RecipesPagination', () {
test('создает RecipesPagination с правильными значениями', () {
const recipe = Recipe(
id: 1,
image: 'https://example.com/image.jpg',
state: 'active',
cookingTime: 30,
activeCookingTime: 15,
ingredients: [],
description: 'Test description',
steps: [],
videoUrl: null,
createdAt: null,
updatedAt: null,
title: 'Test Recipe',
type: 'main',
slug: 'test-recipe',
commentsCount: 5,
wasLikedByMe: false,
isFavorite: false,
calories: 300.0,
servings: 4,
likesCount: 10,
viewsCount: 100,
tags: [],
author: Author(
authorSlug: 'author',
authorName: 'Author Name',
authorProfileIcon: 'https://example.com/icon.jpg',
authorIsMe: false,
isEntitySubscribedByMe: null,
authorPlaceInRating: null,
),
);
const pagination = RecipesPagination(recipesList: [recipe]);
expect(pagination.recipesList.length, 1);
expect(pagination.recipesList.first.id, 1);
expect(pagination.recipesList.first.title, 'Test Recipe');
});
});
}

View File

@@ -0,0 +1,42 @@
import 'package:eatvio_app/features/feed/models/view_model.dart';
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', () {
final json = {
'type': 'diets',
'ids': [1, 2],
};
final model = ViewModel.fromJson(json);
expect(model.type, 'diets');
expect(model.ids, [1, 2]);
});
});
}