test(mobile): finish upload cancellation before fixture teardown

Signed-off-by: Logan Johnson <loganj@squareup.com>
This commit is contained in:
Logan Johnson
2026-09-05 17:03:39 -04:00
parent 39a1e7fdf4
commit 05c7cf00c4

View File

@@ -3231,12 +3231,15 @@ void main() {
final signer = nostr.Keys.generate();
final publishedEvents = <Map<String, dynamic>>[];
final uploadResponse = Completer<http.Response>();
var uploadStarted = false;
var sends = 0;
final uploadService = MediaUploadService(
baseUrl: 'https://relay.example',
nsec: signer.nsec,
httpClient: http_testing.MockClient(
(request) => uploadResponse.future,
),
httpClient: http_testing.MockClient((request) {
uploadStarted = true;
return uploadResponse.future;
}),
pickGalleryVideo: () async => null,
pickGalleryImage: () async => null,
pickGalleryImages: () async => [
@@ -3250,7 +3253,9 @@ void main() {
currentPubkey: signer.public,
relayAgents: [_testAgent(agentPubkey)],
channels: [_makeCurrentChannel(), _makeSharedMemberChannel()],
onSend: (_, _, {mediaTags = const <List<String>>[]}) async {},
onSend: (_, _, {mediaTags = const <List<String>>[]}) async {
sends += 1;
},
),
);
@@ -3271,7 +3276,12 @@ void main() {
await tester.pumpAndSettle();
await tester.tap(find.text('Helper Bot'));
await tester.pumpAndSettle();
await tester.enterText(find.byType(TextField), 'hello @Helper Bot');
await tester.enterText(find.byType(TextField), 'hello @Helper Bot ');
await tester.pumpAndSettle();
final submittedText = tester
.widget<TextField>(find.byType(TextField))
.controller!
.text;
await tester.tap(find.byIcon(LucideIcons.arrowUp));
await tester.pump();
@@ -3281,6 +3291,7 @@ void main() {
);
await tester.pump(const Duration(milliseconds: 220));
expect(uploadStarted, isTrue);
await tester.tap(find.byKey(const ValueKey('compose-upload-cancel')));
uploadResponse.complete(
http.Response(
@@ -3303,8 +3314,13 @@ void main() {
);
expect(
tester.widget<TextField>(find.byType(TextField)).controller!.text,
'hello @Helper Bot',
submittedText,
);
expect(sends, 0);
// Restoring the draft can start a new autocomplete debounce. Dispose
// its owner before draining fake time; do not leak a timer to teardown.
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump(const Duration(milliseconds: 300));
},
);