forked from eatvio/eatvio_app
104 lines
3.0 KiB
Dart
104 lines
3.0 KiB
Dart
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('создает экземпляр с данными', () {
|
||
final comment = Comment(
|
||
id: 1,
|
||
authorName: 'Test Author',
|
||
authorSlug: 'test-author',
|
||
authorProfileIcon: 'icon.png',
|
||
body: 'Test comment',
|
||
childrenComments: [],
|
||
createdAt: DateTime.now(),
|
||
);
|
||
|
||
final model = CommentModel(
|
||
data: [comment],
|
||
links: const Links(first: '', last: '', prev: null, next: null),
|
||
meta: const Meta(currentPage: 1, from: null, lastPage: 1, links: [], perPage: 10, to: null, total: 0),
|
||
);
|
||
|
||
expect(model.data.length, 1);
|
||
expect(model.data.first.id, 1);
|
||
expect(model.data.first.body, 'Test comment');
|
||
});
|
||
|
||
test('fromJson создает модель из JSON', () {
|
||
final json = {
|
||
'data': [
|
||
{
|
||
'id': 1,
|
||
'author_name': 'Test Author',
|
||
'author_slug': 'test-author',
|
||
'author_profile_icon': 'icon.png',
|
||
'body': 'Test comment',
|
||
'children_comments': [],
|
||
'created_at': '2024-01-01T00:00:00Z',
|
||
}
|
||
],
|
||
'links': {'first': '', 'last': '', 'prev': null, 'next': null},
|
||
'meta': {
|
||
'current_page': 1,
|
||
'from': null,
|
||
'last_page': 1,
|
||
'links': [],
|
||
'per_page': 10,
|
||
'to': null,
|
||
'total': 0,
|
||
},
|
||
};
|
||
|
||
final model = CommentModel.fromJson(json);
|
||
|
||
expect(model.data.length, 1);
|
||
expect(model.data.first.id, 1);
|
||
});
|
||
});
|
||
|
||
group('Comment', () {
|
||
test('создает экземпляр с данными', () {
|
||
final comment = Comment(
|
||
id: 1,
|
||
authorName: 'Test Author',
|
||
authorSlug: 'test-author',
|
||
authorProfileIcon: 'icon.png',
|
||
body: 'Test comment',
|
||
childrenComments: [],
|
||
createdAt: DateTime.now(),
|
||
);
|
||
|
||
expect(comment.id, 1);
|
||
expect(comment.authorName, 'Test Author');
|
||
expect(comment.body, 'Test comment');
|
||
});
|
||
|
||
test('поддерживает вложенные комментарии', () {
|
||
final childComment = Comment(
|
||
id: 2,
|
||
authorName: 'Child Author',
|
||
authorSlug: 'child-author',
|
||
authorProfileIcon: 'child.png',
|
||
body: 'Child comment',
|
||
childrenComments: [],
|
||
createdAt: DateTime.now(),
|
||
);
|
||
|
||
final parentComment = Comment(
|
||
id: 1,
|
||
authorName: 'Parent Author',
|
||
authorSlug: 'parent-author',
|
||
authorProfileIcon: 'parent.png',
|
||
body: 'Parent comment',
|
||
childrenComments: [childComment],
|
||
createdAt: DateTime.now(),
|
||
);
|
||
|
||
expect(parentComment.childrenComments.length, 1);
|
||
expect(parentComment.childrenComments.first.id, 2);
|
||
});
|
||
});
|
||
}
|