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:
@@ -1,103 +1,193 @@
|
||||
import 'package:eatvio_app/core/models/pagination_model.dart';
|
||||
import 'package:eatvio_app/features/feed/models/comment_model.dart';
|
||||
import 'package:eatvio_app/core/models/pagination_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(),
|
||||
test('creates CommentModel with empty list', () {
|
||||
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: null,
|
||||
lastPage: 1,
|
||||
links: [],
|
||||
path: '/api/comments',
|
||||
perPage: 10,
|
||||
to: null,
|
||||
total: 0,
|
||||
);
|
||||
|
||||
const model = CommentModel(
|
||||
data: [],
|
||||
links: links,
|
||||
meta: meta,
|
||||
);
|
||||
|
||||
expect(model.data, isEmpty);
|
||||
expect(model.meta.total, 0);
|
||||
});
|
||||
|
||||
test('creates CommentModel with comments', () {
|
||||
final comments = [
|
||||
Comment(
|
||||
id: 1,
|
||||
authorName: 'John Doe',
|
||||
authorSlug: 'john-doe',
|
||||
authorProfileIcon: 'icon1.jpg',
|
||||
body: 'First comment',
|
||||
childrenComments: [],
|
||||
createdAt: DateTime(2023, 1, 1),
|
||||
),
|
||||
Comment(
|
||||
id: 2,
|
||||
authorName: 'Jane Smith',
|
||||
authorSlug: 'jane-smith',
|
||||
authorProfileIcon: 'icon2.jpg',
|
||||
body: 'Second comment',
|
||||
childrenComments: [],
|
||||
createdAt: DateTime(2023, 1, 2),
|
||||
),
|
||||
];
|
||||
|
||||
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/comments',
|
||||
perPage: 10,
|
||||
to: 2,
|
||||
total: 2,
|
||||
);
|
||||
|
||||
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),
|
||||
data: comments,
|
||||
links: links,
|
||||
meta: meta,
|
||||
);
|
||||
|
||||
expect(model.data.length, 1);
|
||||
expect(model.data.first.id, 1);
|
||||
expect(model.data.first.body, 'Test comment');
|
||||
expect(model.data.length, 2);
|
||||
expect(model.data[0].id, 1);
|
||||
expect(model.data[0].authorName, 'John Doe');
|
||||
expect(model.data[1].id, 2);
|
||||
expect(model.data[1].authorName, 'Jane Smith');
|
||||
});
|
||||
|
||||
test('fromJson создает модель из JSON', () {
|
||||
test('creates CommentModel from JSON', () {
|
||||
final json = {
|
||||
'data': [
|
||||
{
|
||||
'id': 1,
|
||||
'author_name': 'Test Author',
|
||||
'author_slug': 'test-author',
|
||||
'author_profile_icon': 'icon.png',
|
||||
'author_name': 'John Doe',
|
||||
'author_slug': 'john-doe',
|
||||
'author_profile_icon': 'icon1.jpg',
|
||||
'body': 'Test comment',
|
||||
'children_comments': [],
|
||||
'created_at': '2024-01-01T00:00:00Z',
|
||||
}
|
||||
'created_at': '2023-01-01T00:00:00Z',
|
||||
},
|
||||
],
|
||||
'links': {'first': '', 'last': '', 'prev': null, 'next': null},
|
||||
'links': {
|
||||
'first': 'http://example.com?page=1',
|
||||
'last': 'http://example.com?page=1',
|
||||
'prev': null,
|
||||
'next': null,
|
||||
},
|
||||
'meta': {
|
||||
'current_page': 1,
|
||||
'from': null,
|
||||
'from': 1,
|
||||
'last_page': 1,
|
||||
'links': [],
|
||||
'path': '/api/comments',
|
||||
'per_page': 10,
|
||||
'to': null,
|
||||
'total': 0,
|
||||
'to': 1,
|
||||
'total': 1,
|
||||
},
|
||||
};
|
||||
|
||||
final model = CommentModel.fromJson(json);
|
||||
|
||||
expect(model.data.length, 1);
|
||||
expect(model.data.first.id, 1);
|
||||
expect(model.data[0].id, 1);
|
||||
expect(model.data[0].authorName, 'John Doe');
|
||||
});
|
||||
});
|
||||
|
||||
group('Comment', () {
|
||||
test('создает экземпляр с данными', () {
|
||||
test('creates Comment with all parameters', () {
|
||||
final comment = Comment(
|
||||
id: 1,
|
||||
authorName: 'Test Author',
|
||||
authorSlug: 'test-author',
|
||||
authorProfileIcon: 'icon.png',
|
||||
body: 'Test comment',
|
||||
authorName: 'John Doe',
|
||||
authorSlug: 'john-doe',
|
||||
authorProfileIcon: 'icon.jpg',
|
||||
body: 'Test comment body',
|
||||
childrenComments: [],
|
||||
createdAt: DateTime.now(),
|
||||
createdAt: DateTime(2023, 1, 1),
|
||||
);
|
||||
|
||||
expect(comment.id, 1);
|
||||
expect(comment.authorName, 'Test Author');
|
||||
expect(comment.body, 'Test comment');
|
||||
expect(comment.authorName, 'John Doe');
|
||||
expect(comment.authorSlug, 'john-doe');
|
||||
expect(comment.authorProfileIcon, 'icon.jpg');
|
||||
expect(comment.body, 'Test comment body');
|
||||
expect(comment.childrenComments, isEmpty);
|
||||
expect(comment.createdAt, DateTime(2023, 1, 1));
|
||||
});
|
||||
|
||||
test('поддерживает вложенные комментарии', () {
|
||||
test('creates Comment with nested children', () {
|
||||
final childComment = Comment(
|
||||
id: 2,
|
||||
authorName: 'Child Author',
|
||||
authorSlug: 'child-author',
|
||||
authorProfileIcon: 'child.png',
|
||||
body: 'Child comment',
|
||||
authorName: 'Jane Smith',
|
||||
authorSlug: 'jane-smith',
|
||||
authorProfileIcon: 'icon2.jpg',
|
||||
body: 'Reply comment',
|
||||
childrenComments: [],
|
||||
createdAt: DateTime.now(),
|
||||
createdAt: DateTime(2023, 1, 2),
|
||||
);
|
||||
|
||||
final parentComment = Comment(
|
||||
id: 1,
|
||||
authorName: 'Parent Author',
|
||||
authorSlug: 'parent-author',
|
||||
authorProfileIcon: 'parent.png',
|
||||
authorName: 'John Doe',
|
||||
authorSlug: 'john-doe',
|
||||
authorProfileIcon: 'icon1.jpg',
|
||||
body: 'Parent comment',
|
||||
childrenComments: [childComment],
|
||||
createdAt: DateTime.now(),
|
||||
createdAt: DateTime(2023, 1, 1),
|
||||
);
|
||||
|
||||
expect(parentComment.childrenComments.length, 1);
|
||||
expect(parentComment.childrenComments.first.id, 2);
|
||||
expect(parentComment.childrenComments[0].id, 2);
|
||||
expect(parentComment.childrenComments[0].authorName, 'Jane Smith');
|
||||
});
|
||||
|
||||
test('creates Comment from JSON', () {
|
||||
final json = {
|
||||
'id': 1,
|
||||
'author_name': 'John Doe',
|
||||
'author_slug': 'john-doe',
|
||||
'author_profile_icon': 'icon.jpg',
|
||||
'body': 'Test comment',
|
||||
'children_comments': [],
|
||||
'created_at': '2023-01-01T00:00:00Z',
|
||||
};
|
||||
|
||||
final comment = Comment.fromJson(json);
|
||||
|
||||
expect(comment.id, 1);
|
||||
expect(comment.authorName, 'John Doe');
|
||||
expect(comment.body, 'Test comment');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user