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