forked from eatvio/eatvio_app
57 lines
2.2 KiB
Dart
57 lines
2.2 KiB
Dart
import 'package:eatvio_app/core/app_config.dart';
|
||
import 'package:eatvio_app/core/app_initializer.dart';
|
||
import 'package:eatvio_app/core/locator_service.dart';
|
||
import 'package:eatvio_app/features/feed/models/post_feed_mapper.dart';
|
||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||
import 'package:flutter_test/flutter_test.dart';
|
||
|
||
import '../../../fixtures/feed_fixtures.dart';
|
||
|
||
void main() {
|
||
group('PostFeedMapper', () {
|
||
setUpAll(() async {
|
||
await sl.reset();
|
||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||
});
|
||
|
||
test('maps fixture item post_id to FeedBlogPostModel.id', () {
|
||
final item = FeedFixtures.postFeedItem();
|
||
final model = PostFeedMapper.fromPostFeedItem(item, currentUserId: 10);
|
||
|
||
expect(model.id, 1);
|
||
expect(model.author.authorIsMe, isTrue);
|
||
expect(model.author.authorSlug, 'anna-ivanova');
|
||
expect(model.images, hasLength(2));
|
||
expect(model.videoUrl, isEmpty);
|
||
expect(model.videoEmbedUrl, isNull);
|
||
expect(model.title, 'Завтрак с овсянкой');
|
||
expect(model.image, 'http://localhost/storage/posts/oatmeal.jpg');
|
||
expect(model.author.isEntitySubscribedByMe, isFalse);
|
||
});
|
||
|
||
test('maps fixture embed video post and likes', () {
|
||
final item = FeedFixtures.postFeedItem(index: 1);
|
||
final model = PostFeedMapper.fromPostFeedItem(item);
|
||
|
||
expect(model.id, 2);
|
||
expect(model.videoUrl, isEmpty);
|
||
expect(model.videoEmbedUrl, 'https://www.youtube.com/embed/dQw4w9WgXcQ');
|
||
expect(model.wasLikedByMe, isTrue);
|
||
expect(model.totalLikes, 42);
|
||
expect(model.author.authorIsMe, isFalse);
|
||
expect(model.author.isEntitySubscribedByMe, isTrue);
|
||
});
|
||
|
||
test('maps all fixture posts', () {
|
||
final posts = FeedFixtures.mappedFeedPosts(currentUserId: 11);
|
||
|
||
expect(posts, hasLength(3));
|
||
expect(posts[1].author.authorIsMe, isTrue);
|
||
expect(posts[1].author.isEntitySubscribedByMe, isTrue);
|
||
expect(posts[2].videoEmbedUrl, contains('rutube.ru/play/embed'));
|
||
expect(posts[2].author.isEntitySubscribedByMe, isNull);
|
||
});
|
||
});
|
||
}
|