Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/widgets/user.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't delete this blank line; it separates third-party imports from our own imports. (Here and elsewhere in the PR.)

import '../api/model/model.dart';
import '../model/avatar_url.dart';
import '../model/binding.dart';
Expand Down Expand Up @@ -90,6 +89,7 @@ class AvatarImage extends StatelessWidget {
avatarUrl.get(physicalSize),
filterQuality: FilterQuality.medium,
fit: BoxFit.cover,
errorBuilder: (_, _, _) => _AvatarPlaceholder(size: size),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also change the resolvedUrl == null case to return _AvatarPlaceholder, too, for this part of the issue description in #1558:

because the URL is invalid

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and add a test for that.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for the user == null case above that, for this part of the issue description:

Or, pre-#1556, for a message from an unknown sender

);
}
}
Expand Down
17 changes: 11 additions & 6 deletions test/test_images.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:async';
import 'dart:io';

import 'dart:typed_data';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';

Expand All @@ -12,15 +12,20 @@ import 'package:flutter_test/flutter_test.dart';
/// before the end of the test.
// TODO(upstream) simplify callers by using addTearDown: https://github.com/flutter/flutter/issues/123189
// See also: https://github.com/flutter/flutter/issues/121917
FakeImageHttpClient prepareBoringImageHttpClient() {
FakeImageHttpClient prepareBoringImageHttpClient({bool success = true}) {
final httpClient = FakeImageHttpClient();
debugNetworkImageHttpClientProvider = () => httpClient;
httpClient.request.response
..statusCode = HttpStatus.ok
..content = kSolidBlueAvatar;
if (success) {
httpClient.request.response
..statusCode = HttpStatus.ok
..content = kSolidBlueAvatar;
} else {
httpClient.request.response
..statusCode = HttpStatus.notFound
..content = Uint8List(0);
}
return httpClient;
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep this blank line, which exists to give the code some breathing room so it's more readable.

class FakeImageHttpClient extends Fake implements HttpClient {
final FakeImageHttpClientRequest request = FakeImageHttpClientRequest();

Expand Down
24 changes: 23 additions & 1 deletion test/widgets/user_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:zulip/model/store.dart';
import 'package:zulip/widgets/content.dart';
import 'package:zulip/widgets/icons.dart';
import 'package:zulip/widgets/store.dart';
import 'package:zulip/widgets/user.dart';

import '../example_data.dart' as eg;
import '../model/binding.dart';
import '../model/test_store.dart';
import '../stdlib_checks.dart';
import '../test_images.dart';
import 'test_app.dart';

void main() {
TestZulipBinding.ensureInitialized();
Expand Down Expand Up @@ -78,5 +79,26 @@ void main() {
check(await actualUrl(tester, avatarUrl)).isNull();
debugNetworkImageHttpClientProvider = null;
});
testWidgets('shows placeholder when image URL gives error', (WidgetTester tester) async {
addTearDown(testBinding.reset);
prepareBoringImageHttpClient(success: false);
await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot());
final store = await testBinding.globalStore.perAccount(eg.selfAccount.id);
final badUser = eg.user(avatarUrl: 'https://zulip.com/avatarinvalid.png');
await store.addUser(badUser);
await tester.pumpWidget(TestZulipApp(
child: PerAccountStoreWidget(
accountId: eg.selfAccount.id,
child: AvatarImage(userId: badUser.userId, size: 30))));
Comment on lines +89 to +92
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be able to pass an accountId to TestZulipApp instead of adding a PerAccountStoreWidget here.

await tester.pumpAndSettle();
expect(
find.descendant(
of: find.byType(AvatarImage),
matching: find.byIcon(ZulipIcons.person),
),
findsOneWidget,
);
debugNetworkImageHttpClientProvider = null;
});
Comment on lines +82 to +102
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits:

  • Empty line before a test
  • Try to adjust indentation and spacing to follow the pattern of existing tests
  • Use check instead of expect; see existing tests for examples

});
}