feat(post_creatin): fixed animation widget for profile feed

This commit is contained in:
misha
2026-08-05 15:21:23 +03:00
parent 04de956769
commit 478a53674a
6 changed files with 727 additions and 162 deletions

View File

@@ -47,13 +47,77 @@ class _FakeHttpClientRequest implements HttpClientRequest {
dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
}
class _FakeHttpClientResponse extends Stream<List<int>> implements HttpClientResponse {
class _FakeHttpClientResponse extends Stream<List<int>>
implements HttpClientResponse {
// 1x1 transparent PNG.
static final List<int> _png = <int>[
0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x01, 0x08, 0x06, 0x00, 0x00, 0x00, 0x1F, 0x15, 0xC4, 0x89, 0x00, 0x00, 0x00, 0x0A, 0x49, 0x44, 0x41,
0x54, 0x78, 0x9C, 0x63, 0x00, 0x01, 0x00, 0x00, 0x05, 0x00, 0x01, 0x0D, 0x0A, 0x2D, 0xB4, 0x00, 0x00, 0x00, 0x00, 0x49,
0x45, 0x4E, 0x44, 0xAE, 0x42, 0x60, 0x82,
0x89,
0x50,
0x4E,
0x47,
0x0D,
0x0A,
0x1A,
0x0A,
0x00,
0x00,
0x00,
0x0D,
0x49,
0x48,
0x44,
0x52,
0x00,
0x00,
0x00,
0x01,
0x00,
0x00,
0x00,
0x01,
0x08,
0x06,
0x00,
0x00,
0x00,
0x1F,
0x15,
0xC4,
0x89,
0x00,
0x00,
0x00,
0x0A,
0x49,
0x44,
0x41,
0x54,
0x78,
0x9C,
0x63,
0x00,
0x01,
0x00,
0x00,
0x05,
0x00,
0x01,
0x0D,
0x0A,
0x2D,
0xB4,
0x00,
0x00,
0x00,
0x00,
0x49,
0x45,
0x4E,
0x44,
0xAE,
0x42,
0x60,
0x82,
];
@override
@@ -63,11 +127,22 @@ class _FakeHttpClientResponse extends Stream<List<int>> implements HttpClientRes
int get contentLength => _png.length;
@override
HttpClientResponseCompressionState get compressionState => HttpClientResponseCompressionState.notCompressed;
HttpClientResponseCompressionState get compressionState =>
HttpClientResponseCompressionState.notCompressed;
@override
StreamSubscription<List<int>> listen(void Function(List<int>)? onData, {Function? onError, void Function()? onDone, bool? cancelOnError}) {
return Stream<List<int>>.fromIterable([_png]).listen(onData, onError: onError, onDone: onDone, cancelOnError: cancelOnError);
StreamSubscription<List<int>> listen(
void Function(List<int>)? onData, {
Function? onError,
void Function()? onDone,
bool? cancelOnError,
}) {
return Stream<List<int>>.fromIterable([_png]).listen(
onData,
onError: onError,
onDone: onDone,
cancelOnError: cancelOnError,
);
}
@override
@@ -78,12 +153,18 @@ class _FakeHttpClientResponse extends Stream<List<int>> implements HttpClientRes
void main() {
group('ProfileBlogPostWidget smoke', () {
setUpAll(() async {
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
dotenv.loadFromString(
envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost',
);
});
setUp(() async {
await sl.reset();
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
sl.registerLazySingleton<AppConfig>(
() =>
AppConfig(buildType: AppBuildType.tests)
..setBaseUrl('http://localhost'),
);
});
const profile = ProfileModel(
@@ -160,7 +241,13 @@ void main() {
testWidgets('renders gallery and video media content', (tester) async {
final post = FeedFixtures.feedBlogPostGalleryAndVideo();
final loadedState = ProfileState.loaded(profile: profile, profileDetails: details, blogPosts: [post], isMyProfile: true, certPhotos: []);
final loadedState = ProfileState.loaded(
profile: profile,
profileDetails: details,
blogPosts: [post],
isMyProfile: true,
certPhotos: [],
);
final cubit = MockProfileCubit();
when(cubit.state).thenReturn(loadedState);
when(cubit.stream).thenAnswer((_) => const Stream<ProfileState>.empty());
@@ -174,7 +261,13 @@ void main() {
testWidgets('renders gallery-only media content', (tester) async {
final post = FeedFixtures.feedBlogPostWithGallery();
final loadedState = ProfileState.loaded(profile: profile, profileDetails: details, blogPosts: [post], isMyProfile: true, certPhotos: []);
final loadedState = ProfileState.loaded(
profile: profile,
profileDetails: details,
blogPosts: [post],
isMyProfile: true,
certPhotos: [],
);
final cubit = MockProfileCubit();
when(cubit.state).thenReturn(loadedState);
when(cubit.stream).thenAnswer((_) => const Stream<ProfileState>.empty());
@@ -188,7 +281,13 @@ void main() {
testWidgets('renders video-only media content', (tester) async {
final post = FeedFixtures.feedBlogPostVideoOnly();
final loadedState = ProfileState.loaded(profile: profile, profileDetails: details, blogPosts: [post], isMyProfile: true, certPhotos: []);
final loadedState = ProfileState.loaded(
profile: profile,
profileDetails: details,
blogPosts: [post],
isMyProfile: true,
certPhotos: [],
);
final cubit = MockProfileCubit();
when(cubit.state).thenReturn(loadedState);
when(cubit.stream).thenAnswer((_) => const Stream<ProfileState>.empty());
@@ -199,5 +298,84 @@ void main() {
expect(find.byType(BlogPostMediaContent), findsOneWidget);
expect(find.text('Видео'), findsOneWidget);
});
testWidgets('cover-only posts with the same image use unique hero tags', (
tester,
) async {
const sharedImage = 'https://example.com/same-cover.jpg';
final posts = [
FeedFixtures.feedBlogPostModel().copyWith(
id: 11,
title: 'Первый',
description: 'Текст',
image: sharedImage,
images: const [],
videoUrl: '',
videoEmbedUrl: null,
),
FeedFixtures.feedBlogPostModel().copyWith(
id: 22,
title: 'Второй',
description: 'Текст',
image: sharedImage,
images: const [],
videoUrl: '',
videoEmbedUrl: null,
),
];
final loadedState = ProfileState.loaded(
profile: profile,
profileDetails: details,
blogPosts: posts,
isMyProfile: true,
certPhotos: [],
);
final cubit = MockProfileCubit();
when(cubit.state).thenReturn(loadedState);
when(cubit.stream).thenAnswer((_) => const Stream<ProfileState>.empty());
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
await HttpOverrides.runZoned(() async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeHelper().themeData(),
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: const [Locale('ru')],
home: Scaffold(
body: MediaQuery(
data: const MediaQueryData(size: Size(800, 1600)),
child: SingleChildScrollView(
child: Column(
children: [
ProfileBlogPostWidget(index: 0, profileCubit: cubit),
ProfileBlogPostWidget(index: 1, profileCubit: cubit),
],
),
),
),
),
),
);
await tester.pumpAndSettle(const Duration(milliseconds: 200));
}, createHttpClient: (_) => _FakeHttpClient());
final tags = tester
.widgetList<Hero>(find.byType(Hero))
.map((hero) => hero.tag)
.toList();
expect(
tags,
containsAll([
'profile-blog-post-11-cover',
'profile-blog-post-22-cover',
]),
);
expect(tags.toSet().length, tags.length);
});
});
}