|  | 
| 1 | 1 | import 'package:checks/checks.dart'; | 
| 2 | 2 | import 'package:flutter/cupertino.dart'; | 
| 3 | 3 | import 'package:flutter/material.dart'; | 
| 4 |  | -import 'package:flutter/rendering.dart'; | 
|  | 4 | +import 'package:zulip/widgets/icons.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 | 8 | import 'package:zulip/widgets/store.dart'; | 
| 9 | 9 | import 'package:zulip/widgets/user.dart'; | 
| 10 |  | - | 
|  | 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 | +import 'test_app.dart'; | 
|  | 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 | +} | 
| 16 | 24 | 
 | 
| 17 | 25 | void main() { | 
| 18 | 26 |   TestZulipBinding.ensureInitialized(); | 
| @@ -78,5 +86,28 @@ void main() { | 
| 78 | 86 |       check(await actualUrl(tester, avatarUrl)).isNull(); | 
| 79 | 87 |       debugNetworkImageHttpClientProvider = null; | 
| 80 | 88 |     }); | 
|  | 89 | + | 
|  | 90 | +    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( | 
|  | 99 | +          TestZulipApp( | 
|  | 100 | +            accountId: eg.selfAccount.id, | 
|  | 101 | +            child: AvatarImage(userId: user.userId, size: 32), | 
|  | 102 | +          ), | 
|  | 103 | +        ); | 
|  | 104 | +        await tester.pump(); // Image provider is created | 
|  | 105 | +        await tester.pump(); // Image fails to load | 
|  | 106 | +        expect(find.byIcon(ZulipIcons.person), findsOneWidget); | 
|  | 107 | + | 
|  | 108 | +        expect(find.byType(DecoratedBox), findsOneWidget); | 
|  | 109 | + | 
|  | 110 | +      }, createHttpClient: (context) => MockHttpClient()); | 
|  | 111 | +    }); | 
| 81 | 112 |   }); | 
| 82 | 113 | } | 
0 commit comments