Skip to content

Commit b2d6c50

Browse files
committed
compose test [nfc]: Move some edit message helpers out of group
Helpers for starting an edit interaction and dealing with the confirmation dialog will be useful as we support retrieving messages not sent.
1 parent 6604cf4 commit b2d6c50

File tree

1 file changed

+53
-53
lines changed

1 file changed

+53
-53
lines changed

test/widgets/compose_box_test.dart

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,6 +1412,51 @@ void main() {
14121412
});
14131413
});
14141414

1415+
/// Starts an edit interaction from the action sheet's 'Edit message' button.
1416+
///
1417+
/// The fetch-raw-content request is prepared with [delay] (default 1s).
1418+
Future<void> startEditInteractionFromActionSheet(
1419+
WidgetTester tester, {
1420+
required int messageId,
1421+
String originalRawContent = 'foo',
1422+
Duration delay = const Duration(seconds: 1),
1423+
bool fetchShouldSucceed = true,
1424+
}) async {
1425+
await tester.longPress(find.byWidgetPredicate((widget) =>
1426+
widget is MessageWithPossibleSender && widget.item.message.id == messageId));
1427+
// sheet appears onscreen; default duration of bottom-sheet enter animation
1428+
await tester.pump(const Duration(milliseconds: 250));
1429+
final findEditButton = find.descendant(
1430+
of: find.byType(BottomSheet),
1431+
matching: find.byIcon(ZulipIcons.edit, skipOffstage: false));
1432+
await tester.ensureVisible(findEditButton);
1433+
if (fetchShouldSucceed) {
1434+
connection.prepare(delay: delay,
1435+
json: GetMessageResult(message: eg.streamMessage(content: originalRawContent)).toJson());
1436+
} else {
1437+
connection.prepare(apiException: eg.apiBadRequest(), delay: delay);
1438+
}
1439+
await tester.tap(findEditButton);
1440+
await tester.pump();
1441+
await tester.pump();
1442+
connection.takeRequests();
1443+
}
1444+
1445+
Future<void> expectAndHandleDiscardConfirmation(
1446+
WidgetTester tester, {
1447+
required bool shouldContinue,
1448+
}) async {
1449+
final (actionButton, cancelButton) = checkSuggestedActionDialog(tester,
1450+
expectedTitle: 'Discard the message you’re writing?',
1451+
expectedMessage: 'When you edit a message, the content that was previously in the compose box is discarded.',
1452+
expectedActionButtonText: 'Discard');
1453+
if (shouldContinue) {
1454+
await tester.tap(find.byWidget(actionButton));
1455+
} else {
1456+
await tester.tap(find.byWidget(cancelButton));
1457+
}
1458+
}
1459+
14151460
group('edit message', () {
14161461
final channel = eg.stream();
14171462
final topic = 'topic';
@@ -1464,44 +1509,14 @@ void main() {
14641509
check(connection.lastRequest).equals(lastRequest);
14651510
}
14661511

1467-
/// Starts an interaction from the action sheet's 'Edit message' button.
1468-
///
1469-
/// The fetch-raw-content request is prepared with [delay] (default 1s).
1470-
Future<void> startInteractionFromActionSheet(
1471-
WidgetTester tester, {
1472-
required int messageId,
1473-
String originalRawContent = 'foo',
1474-
Duration delay = const Duration(seconds: 1),
1475-
bool fetchShouldSucceed = true,
1476-
}) async {
1477-
await tester.longPress(find.byWidgetPredicate((widget) =>
1478-
widget is MessageWithPossibleSender && widget.item.message.id == messageId));
1479-
// sheet appears onscreen; default duration of bottom-sheet enter animation
1480-
await tester.pump(const Duration(milliseconds: 250));
1481-
final findEditButton = find.descendant(
1482-
of: find.byType(BottomSheet),
1483-
matching: find.byIcon(ZulipIcons.edit, skipOffstage: false));
1484-
await tester.ensureVisible(findEditButton);
1485-
if (fetchShouldSucceed) {
1486-
connection.prepare(delay: delay,
1487-
json: GetMessageResult(message: eg.streamMessage(content: originalRawContent)).toJson());
1488-
} else {
1489-
connection.prepare(apiException: eg.apiBadRequest(), delay: delay);
1490-
}
1491-
await tester.tap(findEditButton);
1492-
await tester.pump();
1493-
await tester.pump();
1494-
connection.takeRequests();
1495-
}
1496-
14971512
/// Starts an interaction by tapping a failed edit in the message list.
14981513
Future<void> startInteractionFromRestoreFailedEdit(
14991514
WidgetTester tester, {
15001515
required int messageId,
15011516
String originalRawContent = 'foo',
15021517
String newContent = 'bar',
15031518
}) async {
1504-
await startInteractionFromActionSheet(tester,
1519+
await startEditInteractionFromActionSheet(tester,
15051520
messageId: messageId, originalRawContent: originalRawContent);
15061521
await tester.pump(Duration(seconds: 1)); // raw-content request
15071522
await enterContent(tester, newContent);
@@ -1557,7 +1572,7 @@ void main() {
15571572
final messageId = msgIdInNarrow(narrow);
15581573
switch (start) {
15591574
case _EditInteractionStart.actionSheet:
1560-
await startInteractionFromActionSheet(tester,
1575+
await startEditInteractionFromActionSheet(tester,
15611576
messageId: messageId,
15621577
originalRawContent: 'foo');
15631578
await checkAwaitingRawMessageContent(tester);
@@ -1608,21 +1623,6 @@ void main() {
16081623
testSmoke(narrow: topicNarrow, start: _EditInteractionStart.restoreFailedEdit);
16091624
testSmoke(narrow: dmNarrow, start: _EditInteractionStart.restoreFailedEdit);
16101625

1611-
Future<void> expectAndHandleDiscardConfirmation(
1612-
WidgetTester tester, {
1613-
required bool shouldContinue,
1614-
}) async {
1615-
final (actionButton, cancelButton) = checkSuggestedActionDialog(tester,
1616-
expectedTitle: 'Discard the message you’re writing?',
1617-
expectedMessage: 'When you edit a message, the content that was previously in the compose box is discarded.',
1618-
expectedActionButtonText: 'Discard');
1619-
if (shouldContinue) {
1620-
await tester.tap(find.byWidget(actionButton));
1621-
} else {
1622-
await tester.tap(find.byWidget(cancelButton));
1623-
}
1624-
}
1625-
16261626
// Test the "Discard…?" confirmation dialog when you tap "Edit message" in
16271627
// the action sheet but there's text in the compose box for a new message.
16281628
void testInterruptComposingFromActionSheet({required Narrow narrow}) {
@@ -1637,7 +1637,7 @@ void main() {
16371637
await enterContent(tester, 'composing new message');
16381638

16391639
// Expect confirmation dialog; tap Cancel
1640-
await startInteractionFromActionSheet(tester, messageId: messageId);
1640+
await startEditInteractionFromActionSheet(tester, messageId: messageId);
16411641
await expectAndHandleDiscardConfirmation(tester, shouldContinue: false);
16421642
check(connection.takeRequests()).isEmpty();
16431643
// fetch-raw-content request wasn't actually sent;
@@ -1651,7 +1651,7 @@ void main() {
16511651
checkContentInputValue(tester, 'composing new message…');
16521652

16531653
// Try again, but this time tap Discard and expect to enter an edit session
1654-
await startInteractionFromActionSheet(tester,
1654+
await startEditInteractionFromActionSheet(tester,
16551655
messageId: messageId, originalRawContent: 'foo');
16561656
await expectAndHandleDiscardConfirmation(tester, shouldContinue: true);
16571657
await tester.pump();
@@ -1685,7 +1685,7 @@ void main() {
16851685
final messageId = msgIdInNarrow(narrow);
16861686
await prepareEditMessage(tester, narrow: narrow);
16871687

1688-
await startInteractionFromActionSheet(tester,
1688+
await startEditInteractionFromActionSheet(tester,
16891689
messageId: messageId, originalRawContent: 'foo');
16901690
await tester.pump(Duration(seconds: 1)); // raw-content request
16911691
await enterContent(tester, 'bar');
@@ -1742,7 +1742,7 @@ void main() {
17421742
checkNotInEditingMode(tester, narrow: narrow);
17431743

17441744
final messageId = msgIdInNarrow(narrow);
1745-
await startInteractionFromActionSheet(tester,
1745+
await startEditInteractionFromActionSheet(tester,
17461746
messageId: messageId,
17471747
originalRawContent: 'foo',
17481748
fetchShouldSucceed: false);
@@ -1790,7 +1790,7 @@ void main() {
17901790
final messageId = msgIdInNarrow(narrow);
17911791
switch (start) {
17921792
case _EditInteractionStart.actionSheet:
1793-
await startInteractionFromActionSheet(tester,
1793+
await startEditInteractionFromActionSheet(tester,
17941794
messageId: messageId, delay: Duration(seconds: 5));
17951795
await checkAwaitingRawMessageContent(tester);
17961796
await tester.pump(duringFetchRawContentRequest!
@@ -1809,7 +1809,7 @@ void main() {
18091809

18101810
// We've canceled the previous edit session, so we should be able to
18111811
// do a new edit-message session…
1812-
await startInteractionFromActionSheet(tester,
1812+
await startEditInteractionFromActionSheet(tester,
18131813
messageId: messageId, originalRawContent: 'foo');
18141814
await checkAwaitingRawMessageContent(tester);
18151815
await tester.pump(Duration(seconds: 1)); // fetch-raw-content request

0 commit comments

Comments
 (0)