forked from zulip/zulip-flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
action_sheet: Add "Quote and reply" button
Fixes: zulip#116
- Loading branch information
1 parent
e49f47e
commit 10953f1
Showing
2 changed files
with
207 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import 'package:checks/checks.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:zulip/api/route/messages.dart'; | ||
import 'package:zulip/model/compose.dart'; | ||
import 'package:zulip/model/narrow.dart'; | ||
import 'package:zulip/widgets/compose_box.dart'; | ||
import 'package:zulip/widgets/content.dart'; | ||
import 'package:zulip/widgets/message_list.dart'; | ||
import 'package:zulip/widgets/store.dart'; | ||
import '../api/fake_api.dart'; | ||
|
||
import '../example_data.dart' as eg; | ||
import '../model/binding.dart'; | ||
import '../model/test_store.dart'; | ||
|
||
void main() { | ||
group('QuoteAndReplyButton', () { | ||
TestDataBinding.ensureInitialized(); | ||
|
||
testWidgets('happy path', (WidgetTester tester) async { | ||
addTearDown(TestDataBinding.instance.reset); | ||
|
||
final sender = eg.user(); | ||
final stream = eg.stream(); | ||
final message = eg.streamMessage(sender: sender, stream: stream); | ||
await TestDataBinding.instance.globalStore.add(eg.selfAccount, eg.initialSnapshot); | ||
final store = await TestDataBinding.instance.globalStore.perAccount(eg.selfAccount.id); | ||
store.addUser(sender); | ||
store.addStream(stream); | ||
final connection = store.connection as FakeApiConnection; | ||
|
||
// prepare message list data | ||
connection.prepare(json: GetMessagesResult( | ||
anchor: message.id, | ||
foundNewest: true, | ||
foundOldest: true, | ||
foundAnchor: true, | ||
historyLimited: false, | ||
messages: [message], | ||
).toJson()); | ||
|
||
await tester.pumpWidget( | ||
MaterialApp( | ||
home: GlobalStoreWidget( | ||
child: PerAccountStoreWidget( | ||
accountId: eg.selfAccount.id, | ||
child: MessageListPage( | ||
narrow: StreamNarrow(message.streamId)))))); | ||
|
||
// global store, per-account store, and message list get loaded | ||
await tester.pumpAndSettle(); | ||
|
||
// request the message action sheet | ||
final messageContent = tester.widget<MessageContent>( | ||
find.byWidgetPredicate((Widget widget) => widget is MessageContent && widget.message.id == message.id)); | ||
await tester.longPress(find.byWidget(messageContent)); | ||
await tester.pumpAndSettle(); // sheet appears onscreen | ||
|
||
// Prepare fetch-raw-Markdown response | ||
// TODO: Message should really only differ from `message` | ||
// in its content / content_type, not in `id` or anything else. | ||
connection.prepare(json: | ||
GetMessageResult(message: eg.streamMessage(contentMarkdown: 'Hello world')).toJson()); | ||
|
||
// compose box exists because this is a stream narrow | ||
final composeBox = tester.widget<ComposeBox>(find.byType(ComposeBox)); | ||
final composeBoxController = composeBox.controllerKey!.currentState!; | ||
final contentController = composeBoxController.contentController; | ||
|
||
// the "Quote and reply" button, which exists because the compose box exists | ||
await tester.tap(find.byIcon(Icons.format_quote_outlined)); | ||
|
||
final expectedPlaceholder = quoteAndReplyPlaceholder(store, message: message); | ||
// expect newline from [ComposeContentController.insertPadded] | ||
String expectedText = '$expectedPlaceholder\n'; | ||
check(contentController.value).equals(TextEditingValue( | ||
text: expectedText, | ||
// compose input not yet focused, so there is no selection | ||
selection: const TextSelection.collapsed(offset: -1))); | ||
|
||
// message is fetched; compose box updates | ||
await tester.pumpAndSettle(); | ||
|
||
final expectedQuoteAndReplyText = quoteAndReply(store, message: message, rawContent: 'Hello world'); | ||
// expect newline from [ComposeContentController.insertPadded] | ||
expectedText = '$expectedQuoteAndReplyText\n'; | ||
check(contentController.value).equals(TextEditingValue( | ||
text: expectedText, | ||
// compose input focused, so there is a selection | ||
selection: TextSelection.collapsed(offset: expectedText.length))); | ||
}); | ||
}); | ||
} |