Skip to content

Commit

Permalink
action_sheet test [nfc]: Simplify prepareRawContentResponse… helpers
Browse files Browse the repository at this point in the history
Their callers always give them the shared store prepared by the
setup helper setupToMessageActionSheet.  Have these helpers just
use that directly.

If in the future we end up having a use case for customizing this
behavior, it'll probably be most convenient to have them accept
a connection instead of a store, anyway.
  • Loading branch information
gnprice committed Nov 7, 2024
1 parent 2f6b8e0 commit cdce570
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions test/widgets/action_sheet_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,25 +73,25 @@ void main() {
TestZulipBinding.ensureInitialized();
TestWidgetsFlutterBinding.ensureInitialized();

void prepareRawContentResponseSuccess(PerAccountStore store, {
void prepareRawContentResponseSuccess({
required Message message,
required String rawContent,
Duration delay = Duration.zero,
}) {
// Prepare fetch-raw-Markdown response
// TODO: Message should really only differ from `message`
// in its content / content_type, not in `id` or anything else.
(store.connection as FakeApiConnection).prepare(delay: delay, json:
connection.prepare(delay: delay, json:
GetMessageResult(message: eg.streamMessage(contentMarkdown: rawContent)).toJson());
}

void prepareRawContentResponseError(PerAccountStore store) {
void prepareRawContentResponseError() {
final fakeResponseJson = {
'code': 'BAD_REQUEST',
'msg': 'Invalid message(s)',
'result': 'error',
};
(store.connection as FakeApiConnection).prepare(httpStatus: 400, json: fakeResponseJson);
connection.prepare(httpStatus: 400, json: fakeResponseJson);
}

group('AddThumbsUpButton', () {
Expand Down Expand Up @@ -288,7 +288,7 @@ void main() {
topicController?.value = const TextEditingValue(text: kNoTopicTopic);

final valueBefore = contentController.value;
prepareRawContentResponseSuccess(store, message: message, rawContent: 'Hello world');
prepareRawContentResponseSuccess(message: message, rawContent: 'Hello world');
await tapQuoteAndReplyButton(tester);
checkLoadingState(store, contentController, valueBefore: valueBefore, message: message);
await tester.pump(Duration.zero); // message is fetched; compose box updates
Expand All @@ -305,7 +305,7 @@ void main() {
final contentController = composeBoxController.contentController;

final valueBefore = contentController.value;
prepareRawContentResponseSuccess(store, message: message, rawContent: 'Hello world');
prepareRawContentResponseSuccess(message: message, rawContent: 'Hello world');
await tapQuoteAndReplyButton(tester);
checkLoadingState(store, contentController, valueBefore: valueBefore, message: message);
await tester.pump(Duration.zero); // message is fetched; compose box updates
Expand All @@ -323,7 +323,7 @@ void main() {
final contentController = composeBoxController.contentController;

final valueBefore = contentController.value;
prepareRawContentResponseSuccess(store, message: message, rawContent: 'Hello world');
prepareRawContentResponseSuccess(message: message, rawContent: 'Hello world');
await tapQuoteAndReplyButton(tester);
checkLoadingState(store, contentController, valueBefore: valueBefore, message: message);
await tester.pump(Duration.zero); // message is fetched; compose box updates
Expand All @@ -340,7 +340,7 @@ void main() {
final contentController = composeBoxController.contentController;

final valueBefore = contentController.value = TextEditingValue.empty;
prepareRawContentResponseError(store);
prepareRawContentResponseError();
await tapQuoteAndReplyButton(tester);
checkLoadingState(store, contentController, valueBefore: valueBefore, message: message);
await tester.pump(Duration.zero); // error arrives; error dialog shows
Expand Down Expand Up @@ -498,7 +498,7 @@ void main() {
final message = eg.streamMessage();
await setupToMessageActionSheet(tester, message: message, narrow: TopicNarrow.ofMessage(message));

prepareRawContentResponseSuccess(store, message: message, rawContent: 'Hello world');
prepareRawContentResponseSuccess(message: message, rawContent: 'Hello world');
await tapCopyMessageTextButton(tester);
await tester.pump(Duration.zero);
check(await Clipboard.getData('text/plain')).isNotNull().text.equals('Hello world');
Expand All @@ -512,7 +512,7 @@ void main() {
await setupToMessageActionSheet(tester, message: message, narrow: TopicNarrow.ofMessage(message));

// Make the request take a bit of time to complete…
prepareRawContentResponseSuccess(store, message: message, rawContent: 'Hello world',
prepareRawContentResponseSuccess(message: message, rawContent: 'Hello world',
delay: const Duration(milliseconds: 500));
await tapCopyMessageTextButton(tester);
// … and pump a frame to finish the NavigationState.pop animation…
Expand All @@ -532,7 +532,7 @@ void main() {
final message = eg.streamMessage();
await setupToMessageActionSheet(tester, message: message, narrow: TopicNarrow.ofMessage(message));

prepareRawContentResponseError(store);
prepareRawContentResponseError();
await tapCopyMessageTextButton(tester);
await tester.pump(Duration.zero); // error arrives; error dialog shows

Expand Down Expand Up @@ -592,7 +592,7 @@ void main() {
final message = eg.streamMessage();
await setupToMessageActionSheet(tester, message: message, narrow: TopicNarrow.ofMessage(message));

prepareRawContentResponseSuccess(store, message: message, rawContent: 'Hello world');
prepareRawContentResponseSuccess(message: message, rawContent: 'Hello world');
await tapShareButton(tester);
await tester.pump(Duration.zero);
check(mockSharePlus.sharedString).equals('Hello world');
Expand All @@ -603,7 +603,7 @@ void main() {
final message = eg.streamMessage();
await setupToMessageActionSheet(tester, message: message, narrow: TopicNarrow.ofMessage(message));

prepareRawContentResponseSuccess(store, message: message, rawContent: 'Hello world');
prepareRawContentResponseSuccess(message: message, rawContent: 'Hello world');
mockSharePlus.resultString = 'dev.fluttercommunity.plus/share/unavailable';
await tapShareButton(tester);
await tester.pump(Duration.zero);
Expand All @@ -618,7 +618,7 @@ void main() {
final message = eg.streamMessage();
await setupToMessageActionSheet(tester, message: message, narrow: TopicNarrow.ofMessage(message));

prepareRawContentResponseError(store);
prepareRawContentResponseError();
await tapShareButton(tester);
await tester.pump(Duration.zero); // error arrives; error dialog shows

Expand Down

0 comments on commit cdce570

Please sign in to comment.