Skip to content

Commit 2f9bedb

Browse files
committed
test [nfc]: Move prepareBoringImageHttpClient to test_images.dart
This was already being used for tests outside the test file it was defined in, and we'd like to start using it in an additional different test file. So, define it centrally in this place that makes sense.
1 parent 1de3f11 commit 2f9bedb

File tree

3 files changed

+19
-20
lines changed

3 files changed

+19
-20
lines changed

test/test_images.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
11
import 'dart:async';
22
import 'dart:io';
33

4+
import 'package:flutter/widgets.dart';
45
import 'package:flutter_test/flutter_test.dart';
56

7+
/// Set [debugNetworkImageHttpClientProvider] to return a constant image.
8+
///
9+
/// Returns the [FakeImageHttpClient] that handles the requests.
10+
///
11+
/// The caller must set [debugNetworkImageHttpClientProvider] back to null
12+
/// before the end of the test.
13+
// TODO(upstream) simplify callers by using addTearDown: https://github.com/flutter/flutter/issues/123189
14+
// See also: https://github.com/flutter/flutter/issues/121917
15+
FakeImageHttpClient prepareBoringImageHttpClient() {
16+
final httpClient = FakeImageHttpClient();
17+
debugNetworkImageHttpClientProvider = () => httpClient;
18+
httpClient.request.response
19+
..statusCode = HttpStatus.ok
20+
..content = kSolidBlueAvatar;
21+
return httpClient;
22+
}
23+
624
class FakeImageHttpClient extends Fake implements HttpClient {
725
final FakeImageHttpClientRequest request = FakeImageHttpClientRequest();
826

test/widgets/autocomplete_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import '../api/fake_api.dart';
1414
import '../example_data.dart' as eg;
1515
import '../model/binding.dart';
1616
import '../model/test_store.dart';
17-
import 'content_test.dart';
17+
import '../test_images.dart';
1818

1919
/// Simulates loading a [MessageListPage] and tapping to focus the compose input.
2020
///

test/widgets/content_test.dart

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import 'dart:io';
2-
31
import 'package:checks/checks.dart';
42
import 'package:flutter/foundation.dart';
53
import 'package:flutter/material.dart';
@@ -27,23 +25,6 @@ import 'dialog_checks.dart';
2725
import 'message_list_checks.dart';
2826
import 'page_checks.dart';
2927

30-
/// Set [debugNetworkImageHttpClientProvider] to return a constant image.
31-
///
32-
/// Returns the [FakeImageHttpClient] that handles the requests.
33-
///
34-
/// The caller must set [debugNetworkImageHttpClientProvider] back to null
35-
/// before the end of the test.
36-
// TODO(upstream) simplify callers by using addTearDown: https://github.com/flutter/flutter/issues/123189
37-
// See also: https://github.com/flutter/flutter/issues/121917
38-
FakeImageHttpClient prepareBoringImageHttpClient() {
39-
final httpClient = FakeImageHttpClient();
40-
debugNetworkImageHttpClientProvider = () => httpClient;
41-
httpClient.request.response
42-
..statusCode = HttpStatus.ok
43-
..content = kSolidBlueAvatar;
44-
return httpClient;
45-
}
46-
4728
void main() {
4829
// For testing a new content feature:
4930
//

0 commit comments

Comments
 (0)