|
1 | 1 | import 'package:checks/checks.dart'; |
2 | 2 | import 'package:flutter/cupertino.dart'; |
3 | 3 | import 'package:flutter/material.dart'; |
4 | | -import 'package:zulip/widgets/icons.dart'; |
| 4 | +import 'package:flutter/rendering.dart'; |
5 | 5 | import 'package:flutter_test/flutter_test.dart'; |
6 | 6 | import 'package:zulip/model/store.dart'; |
7 | 7 | import 'package:zulip/widgets/content.dart'; |
| 8 | +import 'package:zulip/widgets/icons.dart'; |
8 | 9 | import 'package:zulip/widgets/store.dart'; |
9 | 10 | import 'package:zulip/widgets/user.dart'; |
10 | | -import 'dart:io'; |
11 | 11 | import '../example_data.dart' as eg; |
12 | 12 | import '../model/binding.dart'; |
13 | 13 | import '../model/test_store.dart'; |
14 | 14 | import '../stdlib_checks.dart'; |
15 | 15 | import '../test_images.dart'; |
16 | 16 | import 'test_app.dart'; |
17 | 17 |
|
18 | | -class MockHttpClient extends Fake implements HttpClient { |
19 | | - @override |
20 | | - Future<HttpClientRequest> getUrl(Uri url) async { |
21 | | - throw const SocketException('test error'); |
22 | | - } |
23 | | -} |
24 | | - |
25 | 18 | void main() { |
26 | 19 | TestZulipBinding.ensureInitialized(); |
27 | 20 |
|
@@ -86,25 +79,26 @@ void main() { |
86 | 79 | check(await actualUrl(tester, avatarUrl)).isNull(); |
87 | 80 | debugNetworkImageHttpClientProvider = null; |
88 | 81 | }); |
89 | | - |
90 | 82 | testWidgets('shows placeholder when image URL gives error', (WidgetTester tester) async { |
91 | | - await HttpOverrides.runZoned(() async { |
92 | | - addTearDown(testBinding.reset); |
93 | | - await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot()); |
94 | | - final store = await testBinding.globalStore.perAccount(eg.selfAccount.id); |
95 | | - final user = eg.user(avatarUrl: 'https://zulip.com/avatar.png'); |
96 | | - await store.addUser(user); |
97 | | - |
98 | | - await tester.pumpWidget(TestZulipApp( |
| 83 | + addTearDown(testBinding.reset); |
| 84 | + prepareBoringImageHttpClient(success: false); |
| 85 | + await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot()); |
| 86 | + final store = await testBinding.globalStore.perAccount(eg.selfAccount.id); |
| 87 | + final badUser = eg.user(avatarUrl: 'https://zulip.com/avatarinvalid.png'); |
| 88 | + await store.addUser(badUser); |
| 89 | + await tester.pumpWidget(TestZulipApp( |
| 90 | + child: PerAccountStoreWidget( |
99 | 91 | accountId: eg.selfAccount.id, |
100 | | - child: AvatarImage(userId: user.userId, size: 32))); |
101 | | - await tester.pump(); // Image provider is created |
102 | | - await tester.pump(); // Image fails to load |
103 | | - expect(find.byIcon(ZulipIcons.person), findsOneWidget); |
104 | | - |
105 | | - expect(find.byType(DecoratedBox), findsOneWidget); |
106 | | - |
107 | | - }, createHttpClient: (context) => MockHttpClient()); |
| 92 | + child: AvatarImage(userId: badUser.userId, size: 30)))); |
| 93 | + await tester.pumpAndSettle(); |
| 94 | + expect( |
| 95 | + find.descendant( |
| 96 | + of: find.byType(AvatarImage), |
| 97 | + matching: find.byIcon(ZulipIcons.person), |
| 98 | + ), |
| 99 | + findsOneWidget, |
| 100 | + ); |
| 101 | + debugNetworkImageHttpClientProvider = null; |
108 | 102 | }); |
109 | 103 | }); |
110 | 104 | } |
0 commit comments