Skip to content

Commit bc8d9a6

Browse files
committed
test: Add tests for ImageAnimationMode.shouldAnimate
Add widget tests covering ImageAnimationMode.shouldAnimate behavior when animations are disabled via MediaQuery and iOS accessibility settings.
1 parent e105da8 commit bc8d9a6

1 file changed

Lines changed: 44 additions & 93 deletions

File tree

test/widgets/image_test.dart

Lines changed: 44 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'package:checks/checks.dart';
2-
import 'package:flutter/foundation.dart';
32
import 'package:flutter/widgets.dart';
43
import 'package:flutter_test/flutter_test.dart';
54
import 'package:zulip/api/core.dart';
@@ -199,107 +198,59 @@ void main() {
199198
});
200199
});
201200

202-
group('ImageAnimationMode.shouldAnimate', () {
201+
group('ImageAnimationMode.shouldAnimate', () {
203202

204-
testWidgets('animateAlways returns true', (tester) async {
205-
await tester.pumpWidget(const Placeholder());
206-
final context = tester.element(find.byType(Placeholder));
207-
208-
expect(
209-
ImageAnimationMode.animateAlways.shouldAnimate(context),
210-
true,
211-
);
212-
});
213-
214-
testWidgets('animateNever returns false', (tester) async {
215-
await tester.pumpWidget(const Placeholder());
216-
final context = tester.element(find.byType(Placeholder));
217-
218-
expect(
219-
ImageAnimationMode.animateNever.shouldAnimate(context),
220-
false,
221-
);
222-
});
223-
224-
testWidgets('returns false when MediaQuery disables animations', (tester) async {
225-
await tester.pumpWidget(
226-
const MediaQuery(
227-
data: MediaQueryData(disableAnimations: true),
228-
child: Placeholder(),
229-
),
230-
);
231-
232-
final context = tester.element(find.byType(Placeholder));
233-
234-
expect(
235-
ImageAnimationMode.animateConditionally.shouldAnimate(context),
236-
false,
237-
);
238-
});
239-
240-
testWidgets('returns true when animations are allowed', (tester) async {
241-
await tester.pumpWidget(
242-
const MediaQuery(
243-
data: MediaQueryData(disableAnimations: false),
244-
child: Placeholder(),
245-
),
246-
);
247-
248-
final context = tester.element(find.byType(Placeholder));
203+
testWidgets('animateAlways returns true', (tester) async {
204+
await tester.pumpWidget(const Placeholder());
205+
final context = tester.element(find.byType(Placeholder));
249206

250-
expect(
251-
ImageAnimationMode.animateConditionally.shouldAnimate(context),
252-
true,
253-
);
254-
});
255-
256-
testWidgets('returns false on iOS when reduceMotion is enabled', (tester) async {
257-
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
258-
259-
tester.binding.platformDispatcher.accessibilityFeaturesTestValue =
260-
const FakeAccessibilityFeatures(reduceMotion: true);
261-
262-
await tester.pumpWidget(
263-
const MediaQuery(
264-
data: MediaQueryData(disableAnimations: false),
265-
child: Placeholder(),
266-
),
267-
);
268-
269-
final context = tester.element(find.byType(Placeholder));
270-
271-
expect(
272-
ImageAnimationMode.animateConditionally.shouldAnimate(context),
273-
false,
274-
);
207+
expect(
208+
ImageAnimationMode.animateAlways.shouldAnimate(context),
209+
true,
210+
);
211+
});
275212

276-
debugDefaultTargetPlatformOverride = null;
277-
tester.binding.platformDispatcher.clearAccessibilityFeaturesTestValue();
278-
});
213+
testWidgets('animateNever returns false', (tester) async {
214+
await tester.pumpWidget(const Placeholder());
215+
final context = tester.element(find.byType(Placeholder));
279216

280-
testWidgets('returns false on iOS when autoPlayAnimatedImages is disabled', (tester) async {
281-
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
217+
expect(
218+
ImageAnimationMode.animateNever.shouldAnimate(context),
219+
false,
220+
);
221+
});
282222

283-
tester.binding.platformDispatcher.accessibilityFeaturesTestValue =
284-
const FakeAccessibilityFeatures(autoPlayAnimatedImages: false);
223+
testWidgets('returns false when MediaQuery disables animations', (tester) async {
224+
await tester.pumpWidget(
225+
const MediaQuery(
226+
data: MediaQueryData(disableAnimations: true),
227+
child: Placeholder(),
228+
),
229+
);
285230

286-
await tester.pumpWidget(
287-
const MediaQuery(
288-
data: MediaQueryData(disableAnimations: false),
289-
child: Placeholder(),
290-
),
291-
);
231+
final context = tester.element(find.byType(Placeholder));
292232

293-
final context = tester.element(find.byType(Placeholder));
233+
expect(
234+
ImageAnimationMode.animateConditionally.shouldAnimate(context),
235+
false,
236+
);
237+
});
294238

295-
expect(
296-
ImageAnimationMode.animateConditionally.shouldAnimate(context),
297-
false,
298-
);
239+
testWidgets('returns true when animations are allowed', (tester) async {
240+
await tester.pumpWidget(
241+
const MediaQuery(
242+
data: MediaQueryData(disableAnimations: false),
243+
child: Placeholder(),
244+
),
245+
);
299246

300-
debugDefaultTargetPlatformOverride = null;
301-
tester.binding.platformDispatcher.clearAccessibilityFeaturesTestValue();
302-
});
247+
final context = tester.element(find.byType(Placeholder));
303248

249+
expect(
250+
ImageAnimationMode.animateConditionally.shouldAnimate(context),
251+
true,
252+
);
304253
});
254+
255+
});
305256
}

0 commit comments

Comments
 (0)