Skip to content

Commit 55cf074

Browse files
chrisbobbegnprice
authored andcommitted
test [nfc]: Move fake-image-request code to its own file
1 parent feabdfe commit 55cf074

File tree

2 files changed

+70
-66
lines changed

2 files changed

+70
-66
lines changed

test/test_images.dart

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import 'dart:async';
2+
import 'dart:io';
3+
4+
import 'package:flutter_test/flutter_test.dart';
5+
6+
class FakeImageHttpClient extends Fake implements HttpClient {
7+
final FakeImageHttpClientRequest request = FakeImageHttpClientRequest();
8+
9+
@override
10+
Future<HttpClientRequest> getUrl(Uri url) async => request;
11+
}
12+
13+
class FakeImageHttpClientRequest extends Fake implements HttpClientRequest {
14+
final FakeImageHttpClientResponse response = FakeImageHttpClientResponse();
15+
16+
@override
17+
final FakeImageHttpHeaders headers = FakeImageHttpHeaders();
18+
19+
@override
20+
Future<HttpClientResponse> close() async => response;
21+
}
22+
23+
class FakeImageHttpHeaders extends Fake implements HttpHeaders {
24+
final Map<String, List<String>> values = {};
25+
26+
@override
27+
void add(String name, Object value, {bool preserveHeaderCase = false}) {
28+
(values[name] ??= []).add(value.toString());
29+
}
30+
}
31+
32+
class FakeImageHttpClientResponse extends Fake implements HttpClientResponse {
33+
@override
34+
int statusCode = HttpStatus.ok;
35+
36+
late List<int> content;
37+
38+
@override
39+
int get contentLength => content.length;
40+
41+
@override
42+
HttpClientResponseCompressionState get compressionState => HttpClientResponseCompressionState.notCompressed;
43+
44+
@override
45+
StreamSubscription<List<int>> listen(void Function(List<int> event)? onData, {Function? onError, void Function()? onDone, bool? cancelOnError}) {
46+
return Stream.value(content).listen(
47+
onData, onDone: onDone, onError: onError, cancelOnError: cancelOnError);
48+
}
49+
}
50+
51+
/// A 100x100 PNG image of solid Zulip blue, [kZulipBrandColor].
52+
// Made from the following SVG:
53+
// <svg xmlns="http://www.w3.org/2000/svg" width="1" height="1" viewBox="0 0 1 1">
54+
// <rect style="fill:#6492fe;fill-opacity:1" width="1" height="1" x="0" y="0" />
55+
// </svg>
56+
// with `inkscape tmp.svg -w 100 --export-png=tmp1.png`,
57+
// `zopflipng tmp1.png tmp.png`,
58+
// and `xxd -i tmp.png`.
59+
const List<int> kSolidBlueAvatar = [
60+
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
61+
0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x64,
62+
0x01, 0x03, 0x00, 0x00, 0x00, 0x4a, 0x2c, 0x07, 0x17, 0x00, 0x00, 0x00,
63+
0x03, 0x50, 0x4c, 0x54, 0x45, 0x64, 0x92, 0xfe, 0xf1, 0xd6, 0x69, 0xa5,
64+
0x00, 0x00, 0x00, 0x13, 0x49, 0x44, 0x41, 0x54, 0x78, 0x01, 0x63, 0xa0,
65+
0x2b, 0x18, 0x05, 0xa3, 0x60, 0x14, 0x8c, 0x82, 0x51, 0x00, 0x00, 0x05,
66+
0x78, 0x00, 0x01, 0x1e, 0xcd, 0x28, 0xcd, 0x00, 0x00, 0x00, 0x00, 0x49,
67+
0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82,
68+
];

test/widgets/content_test.dart

+2-66
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'dart:async';
21
import 'dart:io';
32

43
import 'package:checks/checks.dart';
@@ -13,6 +12,7 @@ import 'package:zulip/widgets/store.dart';
1312

1413
import '../example_data.dart' as eg;
1514
import '../model/binding.dart';
15+
import '../test_images.dart';
1616
import 'dialog_checks.dart';
1717

1818
void main() {
@@ -126,7 +126,7 @@ void main() {
126126
addTearDown(TestZulipBinding.instance.reset);
127127
await globalStore.add(eg.selfAccount, eg.initialSnapshot());
128128

129-
final httpClient = _FakeHttpClient();
129+
final httpClient = FakeImageHttpClient();
130130
debugNetworkImageHttpClientProvider = () => httpClient;
131131
httpClient.request.response
132132
..statusCode = HttpStatus.ok
@@ -162,67 +162,3 @@ void main() {
162162
});
163163
});
164164
}
165-
166-
class _FakeHttpClient extends Fake implements HttpClient {
167-
final _FakeHttpClientRequest request = _FakeHttpClientRequest();
168-
169-
@override
170-
Future<HttpClientRequest> getUrl(Uri url) async => request;
171-
}
172-
173-
class _FakeHttpClientRequest extends Fake implements HttpClientRequest {
174-
final _FakeHttpClientResponse response = _FakeHttpClientResponse();
175-
176-
@override
177-
final _FakeHttpHeaders headers = _FakeHttpHeaders();
178-
179-
@override
180-
Future<HttpClientResponse> close() async => response;
181-
}
182-
183-
class _FakeHttpHeaders extends Fake implements HttpHeaders {
184-
final Map<String, List<String>> values = {};
185-
186-
@override
187-
void add(String name, Object value, {bool preserveHeaderCase = false}) {
188-
(values[name] ??= []).add(value.toString());
189-
}
190-
}
191-
192-
class _FakeHttpClientResponse extends Fake implements HttpClientResponse {
193-
@override
194-
int statusCode = HttpStatus.ok;
195-
196-
late List<int> content;
197-
198-
@override
199-
int get contentLength => content.length;
200-
201-
@override
202-
HttpClientResponseCompressionState get compressionState => HttpClientResponseCompressionState.notCompressed;
203-
204-
@override
205-
StreamSubscription<List<int>> listen(void Function(List<int> event)? onData, {Function? onError, void Function()? onDone, bool? cancelOnError}) {
206-
return Stream.value(content).listen(
207-
onData, onDone: onDone, onError: onError, cancelOnError: cancelOnError);
208-
}
209-
}
210-
211-
/// A 100x100 PNG image of solid Zulip blue, [kZulipBrandColor].
212-
// Made from the following SVG:
213-
// <svg xmlns="http://www.w3.org/2000/svg" width="1" height="1" viewBox="0 0 1 1">
214-
// <rect style="fill:#6492fe;fill-opacity:1" width="1" height="1" x="0" y="0" />
215-
// </svg>
216-
// with `inkscape tmp.svg -w 100 --export-png=tmp1.png`,
217-
// `zopflipng tmp1.png tmp.png`,
218-
// and `xxd -i tmp.png`.
219-
const List<int> kSolidBlueAvatar = [
220-
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
221-
0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x64,
222-
0x01, 0x03, 0x00, 0x00, 0x00, 0x4a, 0x2c, 0x07, 0x17, 0x00, 0x00, 0x00,
223-
0x03, 0x50, 0x4c, 0x54, 0x45, 0x64, 0x92, 0xfe, 0xf1, 0xd6, 0x69, 0xa5,
224-
0x00, 0x00, 0x00, 0x13, 0x49, 0x44, 0x41, 0x54, 0x78, 0x01, 0x63, 0xa0,
225-
0x2b, 0x18, 0x05, 0xa3, 0x60, 0x14, 0x8c, 0x82, 0x51, 0x00, 0x00, 0x05,
226-
0x78, 0x00, 0x01, 0x1e, 0xcd, 0x28, 0xcd, 0x00, 0x00, 0x00, 0x00, 0x49,
227-
0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82,
228-
];

0 commit comments

Comments
 (0)