From b91a8260c9620553af37ba17c800a1064c10dc48 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Mon, 4 Nov 2024 17:50:26 -0800 Subject: [PATCH] action_sheet test [nfc]: Share store as a late variable These tests are all already relying on the detail that the setupToMessageActionSheet helper uses `eg.selfAccount` for the account. Better to encapsulate that detail, and have them rely on it giving the test cases a reference to the store directly. --- test/widgets/action_sheet_test.dart | 30 ++--------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/test/widgets/action_sheet_test.dart b/test/widgets/action_sheet_test.dart index 1c8f86272a..bf052437a8 100644 --- a/test/widgets/action_sheet_test.dart +++ b/test/widgets/action_sheet_test.dart @@ -44,6 +44,7 @@ GetMessagesResult _getMessagesResult(Message message) { ); } +late PerAccountStore store; late FakeApiConnection connection; /// Simulates loading a [MessageListPage] and long-pressing on [message]. @@ -54,7 +55,7 @@ Future setupToMessageActionSheet(WidgetTester tester, { addTearDown(testBinding.reset); await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot()); - final store = await testBinding.globalStore.perAccount(eg.selfAccount.id); + store = await testBinding.globalStore.perAccount(eg.selfAccount.id); await store.addUser(eg.user(userId: message.senderId)); if (message is StreamMessage) { final stream = eg.stream(streamId: message.streamId); @@ -111,9 +112,7 @@ void main() { testWidgets('success', (tester) async { final message = eg.streamMessage(); await setupToMessageActionSheet(tester, message: message, narrow: TopicNarrow.ofMessage(message)); - final store = await testBinding.globalStore.perAccount(eg.selfAccount.id); - final connection = store.connection as FakeApiConnection; connection.prepare(json: {}); await tapButton(tester); await tester.pump(Duration.zero); @@ -131,9 +130,6 @@ void main() { testWidgets('request has an error', (tester) async { final message = eg.streamMessage(); await setupToMessageActionSheet(tester, message: message, narrow: TopicNarrow.ofMessage(message)); - final store = await testBinding.globalStore.perAccount(eg.selfAccount.id); - - final connection = store.connection as FakeApiConnection; connection.prepare(httpStatus: 400, json: { 'code': 'BAD_REQUEST', @@ -165,9 +161,7 @@ void main() { testWidgets('star success', (tester) async { final message = eg.streamMessage(flags: []); await setupToMessageActionSheet(tester, message: message, narrow: TopicNarrow.ofMessage(message)); - final store = await testBinding.globalStore.perAccount(eg.selfAccount.id); - final connection = store.connection as FakeApiConnection; connection.prepare(json: {}); await tapButton(tester); await tester.pump(Duration.zero); @@ -185,9 +179,7 @@ void main() { testWidgets('unstar success', (tester) async { final message = eg.streamMessage(flags: [MessageFlag.starred]); await setupToMessageActionSheet(tester, message: message, narrow: TopicNarrow.ofMessage(message)); - final store = await testBinding.globalStore.perAccount(eg.selfAccount.id); - final connection = store.connection as FakeApiConnection; connection.prepare(json: {}); await tapButton(tester, starred: true); await tester.pump(Duration.zero); @@ -205,11 +197,8 @@ void main() { testWidgets('star request has an error', (tester) async { final message = eg.streamMessage(flags: []); await setupToMessageActionSheet(tester, message: message, narrow: TopicNarrow.ofMessage(message)); - final store = await testBinding.globalStore.perAccount(eg.selfAccount.id); final zulipLocalizations = GlobalLocalizations.zulipLocalizations; - final connection = store.connection as FakeApiConnection; - connection.prepare(httpStatus: 400, json: { 'code': 'BAD_REQUEST', 'msg': 'Invalid message(s)', @@ -226,11 +215,8 @@ void main() { testWidgets('unstar request has an error', (tester) async { final message = eg.streamMessage(flags: [MessageFlag.starred]); await setupToMessageActionSheet(tester, message: message, narrow: TopicNarrow.ofMessage(message)); - final store = await testBinding.globalStore.perAccount(eg.selfAccount.id); final zulipLocalizations = GlobalLocalizations.zulipLocalizations; - final connection = store.connection as FakeApiConnection; - connection.prepare(httpStatus: 400, json: { 'code': 'BAD_REQUEST', 'msg': 'Invalid message(s)', @@ -297,7 +283,6 @@ void main() { testWidgets('in channel narrow', (tester) async { final message = eg.streamMessage(); await setupToMessageActionSheet(tester, message: message, narrow: ChannelNarrow(message.streamId)); - final store = await testBinding.globalStore.perAccount(eg.selfAccount.id); final composeBoxController = findComposeBoxController(tester)!; final contentController = composeBoxController.contentController; @@ -321,7 +306,6 @@ void main() { testWidgets('in topic narrow', (tester) async { final message = eg.streamMessage(); await setupToMessageActionSheet(tester, message: message, narrow: TopicNarrow.ofMessage(message)); - final store = await testBinding.globalStore.perAccount(eg.selfAccount.id); final composeBoxController = findComposeBoxController(tester)!; final contentController = composeBoxController.contentController; @@ -340,7 +324,6 @@ void main() { final message = eg.dmMessage(from: eg.selfUser, to: [eg.otherUser]); await setupToMessageActionSheet(tester, message: message, narrow: DmNarrow.ofMessage(message, selfUserId: eg.selfUser.userId)); - final store = await testBinding.globalStore.perAccount(eg.selfAccount.id); final composeBoxController = findComposeBoxController(tester)!; final contentController = composeBoxController.contentController; @@ -358,7 +341,6 @@ void main() { testWidgets('request has an error', (tester) async { final message = eg.streamMessage(); await setupToMessageActionSheet(tester, message: message, narrow: TopicNarrow.ofMessage(message)); - final store = await testBinding.globalStore.perAccount(eg.selfAccount.id); final composeBoxController = findComposeBoxController(tester)!; final contentController = composeBoxController.contentController; @@ -454,7 +436,6 @@ void main() { // Get the action sheet fully deployed while the old narrow applies. await tester.pumpAndSettle(); - final store = await testBinding.globalStore.perAccount(eg.selfAccount.id); final newStream = eg.stream(); const newTopic = 'other topic'; // This result isn't quite realistic for this request: it should get @@ -517,7 +498,6 @@ void main() { testWidgets('success', (tester) async { final message = eg.streamMessage(); await setupToMessageActionSheet(tester, message: message, narrow: TopicNarrow.ofMessage(message)); - final store = await testBinding.globalStore.perAccount(eg.selfAccount.id); prepareRawContentResponseSuccess(store, message: message, rawContent: 'Hello world'); await tapCopyMessageTextButton(tester); @@ -531,7 +511,6 @@ void main() { final message = eg.streamMessage(); await setupToMessageActionSheet(tester, message: message, narrow: TopicNarrow.ofMessage(message)); - final store = await testBinding.globalStore.perAccount(eg.selfAccount.id); // Make the request take a bit of time to complete… prepareRawContentResponseSuccess(store, message: message, rawContent: 'Hello world', @@ -553,7 +532,6 @@ void main() { testWidgets('request has an error', (tester) async { final message = eg.streamMessage(); await setupToMessageActionSheet(tester, message: message, narrow: TopicNarrow.ofMessage(message)); - final store = await testBinding.globalStore.perAccount(eg.selfAccount.id); prepareRawContentResponseError(store); await tapCopyMessageTextButton(tester); @@ -585,7 +563,6 @@ void main() { final message = eg.streamMessage(); final narrow = TopicNarrow.ofMessage(message); await setupToMessageActionSheet(tester, message: message, narrow: narrow); - final store = await testBinding.globalStore.perAccount(eg.selfAccount.id); await tapCopyMessageLinkButton(tester); await tester.pump(Duration.zero); @@ -615,7 +592,6 @@ void main() { final mockSharePlus = setupMockSharePlus(); final message = eg.streamMessage(); await setupToMessageActionSheet(tester, message: message, narrow: TopicNarrow.ofMessage(message)); - final store = await testBinding.globalStore.perAccount(eg.selfAccount.id); prepareRawContentResponseSuccess(store, message: message, rawContent: 'Hello world'); await tapShareButton(tester); @@ -627,7 +603,6 @@ void main() { final mockSharePlus = setupMockSharePlus(); final message = eg.streamMessage(); await setupToMessageActionSheet(tester, message: message, narrow: TopicNarrow.ofMessage(message)); - final store = await testBinding.globalStore.perAccount(eg.selfAccount.id); prepareRawContentResponseSuccess(store, message: message, rawContent: 'Hello world'); mockSharePlus.resultString = 'dev.fluttercommunity.plus/share/unavailable'; @@ -643,7 +618,6 @@ void main() { final mockSharePlus = setupMockSharePlus(); final message = eg.streamMessage(); await setupToMessageActionSheet(tester, message: message, narrow: TopicNarrow.ofMessage(message)); - final store = await testBinding.globalStore.perAccount(eg.selfAccount.id); prepareRawContentResponseError(store); await tapShareButton(tester);