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 7, 2024
1 parent f741a8c commit 2f6b8e0
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 @@ -35,6 +35,7 @@ import 'compose_box_checks.dart';
import 'dialog_checks.dart';
import 'test_app.dart';

late PerAccountStore store;
late FakeApiConnection connection;

/// Simulates loading a [MessageListPage] and long-pressing on [message].
Expand All @@ -45,7 +46,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 @@ -103,9 +104,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 @@ -123,9 +122,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 @@ -157,9 +153,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 @@ -177,9 +171,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 @@ -197,11 +189,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 @@ -218,11 +207,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 @@ -291,7 +277,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 @@ -315,7 +300,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 @@ -334,7 +318,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 @@ -352,7 +335,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 @@ -452,7 +434,6 @@ void main() {
// by giving the code maximum opportunity to latch onto the old topic.)
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 @@ -516,7 +497,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 @@ -530,7 +510,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 @@ -552,7 +531,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 @@ -584,7 +562,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 @@ -614,7 +591,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 @@ -626,7 +602,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 @@ -642,7 +617,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 2f6b8e0

Please sign in to comment.