@@ -1412,6 +1412,51 @@ void main() {
1412
1412
});
1413
1413
});
1414
1414
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
+
1415
1460
group ('edit message' , () {
1416
1461
final channel = eg.stream ();
1417
1462
final topic = 'topic' ;
@@ -1464,44 +1509,14 @@ void main() {
1464
1509
check (connection.lastRequest).equals (lastRequest);
1465
1510
}
1466
1511
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
-
1497
1512
/// Starts an interaction by tapping a failed edit in the message list.
1498
1513
Future <void > startInteractionFromRestoreFailedEdit (
1499
1514
WidgetTester tester, {
1500
1515
required int messageId,
1501
1516
String originalRawContent = 'foo' ,
1502
1517
String newContent = 'bar' ,
1503
1518
}) async {
1504
- await startInteractionFromActionSheet (tester,
1519
+ await startEditInteractionFromActionSheet (tester,
1505
1520
messageId: messageId, originalRawContent: originalRawContent);
1506
1521
await tester.pump (Duration (seconds: 1 )); // raw-content request
1507
1522
await enterContent (tester, newContent);
@@ -1557,7 +1572,7 @@ void main() {
1557
1572
final messageId = msgIdInNarrow (narrow);
1558
1573
switch (start) {
1559
1574
case _EditInteractionStart .actionSheet:
1560
- await startInteractionFromActionSheet (tester,
1575
+ await startEditInteractionFromActionSheet (tester,
1561
1576
messageId: messageId,
1562
1577
originalRawContent: 'foo' );
1563
1578
await checkAwaitingRawMessageContent (tester);
@@ -1608,21 +1623,6 @@ void main() {
1608
1623
testSmoke (narrow: topicNarrow, start: _EditInteractionStart .restoreFailedEdit);
1609
1624
testSmoke (narrow: dmNarrow, start: _EditInteractionStart .restoreFailedEdit);
1610
1625
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
-
1626
1626
// Test the "Discard…?" confirmation dialog when you tap "Edit message" in
1627
1627
// the action sheet but there's text in the compose box for a new message.
1628
1628
void testInterruptComposingFromActionSheet ({required Narrow narrow}) {
@@ -1637,7 +1637,7 @@ void main() {
1637
1637
await enterContent (tester, 'composing new message' );
1638
1638
1639
1639
// Expect confirmation dialog; tap Cancel
1640
- await startInteractionFromActionSheet (tester, messageId: messageId);
1640
+ await startEditInteractionFromActionSheet (tester, messageId: messageId);
1641
1641
await expectAndHandleDiscardConfirmation (tester, shouldContinue: false );
1642
1642
check (connection.takeRequests ()).isEmpty ();
1643
1643
// fetch-raw-content request wasn't actually sent;
@@ -1651,7 +1651,7 @@ void main() {
1651
1651
checkContentInputValue (tester, 'composing new message…' );
1652
1652
1653
1653
// Try again, but this time tap Discard and expect to enter an edit session
1654
- await startInteractionFromActionSheet (tester,
1654
+ await startEditInteractionFromActionSheet (tester,
1655
1655
messageId: messageId, originalRawContent: 'foo' );
1656
1656
await expectAndHandleDiscardConfirmation (tester, shouldContinue: true );
1657
1657
await tester.pump ();
@@ -1685,7 +1685,7 @@ void main() {
1685
1685
final messageId = msgIdInNarrow (narrow);
1686
1686
await prepareEditMessage (tester, narrow: narrow);
1687
1687
1688
- await startInteractionFromActionSheet (tester,
1688
+ await startEditInteractionFromActionSheet (tester,
1689
1689
messageId: messageId, originalRawContent: 'foo' );
1690
1690
await tester.pump (Duration (seconds: 1 )); // raw-content request
1691
1691
await enterContent (tester, 'bar' );
@@ -1742,7 +1742,7 @@ void main() {
1742
1742
checkNotInEditingMode (tester, narrow: narrow);
1743
1743
1744
1744
final messageId = msgIdInNarrow (narrow);
1745
- await startInteractionFromActionSheet (tester,
1745
+ await startEditInteractionFromActionSheet (tester,
1746
1746
messageId: messageId,
1747
1747
originalRawContent: 'foo' ,
1748
1748
fetchShouldSucceed: false );
@@ -1790,7 +1790,7 @@ void main() {
1790
1790
final messageId = msgIdInNarrow (narrow);
1791
1791
switch (start) {
1792
1792
case _EditInteractionStart .actionSheet:
1793
- await startInteractionFromActionSheet (tester,
1793
+ await startEditInteractionFromActionSheet (tester,
1794
1794
messageId: messageId, delay: Duration (seconds: 5 ));
1795
1795
await checkAwaitingRawMessageContent (tester);
1796
1796
await tester.pump (duringFetchRawContentRequest!
@@ -1809,7 +1809,7 @@ void main() {
1809
1809
1810
1810
// We've canceled the previous edit session, so we should be able to
1811
1811
// do a new edit-message session…
1812
- await startInteractionFromActionSheet (tester,
1812
+ await startEditInteractionFromActionSheet (tester,
1813
1813
messageId: messageId, originalRawContent: 'foo' );
1814
1814
await checkAwaitingRawMessageContent (tester);
1815
1815
await tester.pump (Duration (seconds: 1 )); // fetch-raw-content request
0 commit comments