forked from eatvio/eatvio_app
fix: issue-942, issue-967, fixed images positioning for blog posts
This commit is contained in:
@@ -56,6 +56,33 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
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');
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:eatvio_app/features/feed/models/post_feed_pagination_model.dart';
|
||||
import 'package:eatvio_app/features/feed/presentation/widgets/blog_post_media_content.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:network_image_mock/network_image_mock.dart';
|
||||
|
||||
void main() {
|
||||
const gallery = [
|
||||
FeedGalleryImage(
|
||||
url: 'https://example.com/a.jpg',
|
||||
orientation: 'horizontal',
|
||||
),
|
||||
FeedGalleryImage(url: 'https://example.com/b.jpg', orientation: 'vertical'),
|
||||
];
|
||||
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
home: MediaQuery(
|
||||
data: const MediaQueryData(size: Size(390, 844)),
|
||||
child: Scaffold(body: child),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
BlogPostMediaContent media({
|
||||
List<FeedGalleryImage> images = gallery,
|
||||
String imageUrl = '',
|
||||
}) {
|
||||
return BlogPostMediaContent(
|
||||
galleryImages: images,
|
||||
imageUrl: imageUrl,
|
||||
videoEmbedUrl: null,
|
||||
videoUrlThumb: null,
|
||||
currentGalleryIndex: 0,
|
||||
onOpenGallery: (_, _) {},
|
||||
onGalleryChanged: (_) {},
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('gallery slides use fitWidth so photos fill the card width', (
|
||||
tester,
|
||||
) async {
|
||||
await mockNetworkImagesFor(() async {
|
||||
await tester.pumpWidget(wrap(media()));
|
||||
await tester.pump();
|
||||
|
||||
final images = tester.widgetList<CachedNetworkImage>(
|
||||
find.byType(CachedNetworkImage),
|
||||
);
|
||||
expect(images, isNotEmpty);
|
||||
for (final image in images) {
|
||||
expect(image.fit, BoxFit.fitWidth);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('single gallery image uses fitWidth without a forced height', (
|
||||
tester,
|
||||
) async {
|
||||
await mockNetworkImagesFor(() async {
|
||||
await tester.pumpWidget(wrap(media(images: [gallery.first])));
|
||||
await tester.pump();
|
||||
|
||||
final image = tester.widget<CachedNetworkImage>(
|
||||
find.byType(CachedNetworkImage),
|
||||
);
|
||||
expect(image.fit, BoxFit.fitWidth);
|
||||
expect(image.height, isNull);
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('cover-only image keeps fitWidth', (tester) async {
|
||||
await mockNetworkImagesFor(() async {
|
||||
await tester.pumpWidget(
|
||||
wrap(
|
||||
media(images: const [], imageUrl: 'https://example.com/cover.jpg'),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
final image = tester.widget<CachedNetworkImage>(
|
||||
find.byType(CachedNetworkImage),
|
||||
);
|
||||
expect(image.fit, BoxFit.fitWidth);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user