Skip to content

Commit

Permalink
action_sheet test [nfc]: Share store as a late variable
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gnprice committed Nov 5, 2024
1 parent f103128 commit b91a826
Showing 1 changed file with 2 additions and 28 deletions.
30 changes: 2 additions & 28 deletions test/widgets/action_sheet_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ GetMessagesResult _getMessagesResult(Message message) {
);
}

late PerAccountStore store;
late FakeApiConnection connection;

/// Simulates loading a [MessageListPage] and long-pressing on [message].
Expand All @@ -54,7 +55,7 @@ Future<void> 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);
Expand Down Expand Up @@ -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);
Expand All @@ -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',
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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)',
Expand All @@ -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)',
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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',
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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';
Expand All @@ -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);
Expand Down

0 comments on commit b91a826

Please sign in to comment.