Skip to content

Commit

Permalink
test [nfc]: Add streams and eg.selfUser to store in several tests
Browse files Browse the repository at this point in the history
Adding of these is necessary in the next commit(s), otherwise these
tests will fail.
  • Loading branch information
sm-sayedi committed Aug 20, 2024
1 parent 3ee93ba commit 12610dc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion test/widgets/action_sheet_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Future<void> setupToMessageActionSheet(WidgetTester tester, {

await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot());
final store = await testBinding.globalStore.perAccount(eg.selfAccount.id);
await store.addUser(eg.user(userId: message.senderId));
await store.addUsers([eg.selfUser, eg.user(userId: message.senderId)]);
if (message is StreamMessage) {
final stream = eg.stream(streamId: message.streamId);
await store.addStream(stream);
Expand Down
2 changes: 2 additions & 0 deletions test/widgets/autocomplete_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@ Future<Finder> setupToTopicInput(WidgetTester tester, {
addTearDown(testBinding.reset);
await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot());
final store = await testBinding.globalStore.perAccount(eg.selfAccount.id);
await store.addUser(eg.selfUser);
final connection = store.connection as FakeApiConnection;

// prepare message list data
final stream = eg.stream();
await store.addStream(stream);
final message = eg.streamMessage(stream: stream, sender: eg.selfUser);
connection.prepare(json: GetMessagesResult(
anchor: message.id,
Expand Down
24 changes: 18 additions & 6 deletions test/widgets/compose_box_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ void main() {
List<User> users = const [],
List<ZulipStream> streams = const [],
}) async {
if (narrow is ChannelNarrow || narrow is TopicNarrow) {
final channelId = narrow is ChannelNarrow ? narrow.streamId : (narrow as TopicNarrow).streamId;
assert(streams.any((stream) => stream.streamId == channelId),
'Add a channel with "streamId" the same as of $narrow.streamId to the store.');
}
addTearDown(testBinding.reset);
final account = eg.account(user: selfUser ?? eg.selfUser);
await testBinding.globalStore.add(account, eg.initialSnapshot(
Expand Down Expand Up @@ -188,15 +193,17 @@ void main() {
}

testWidgets('_StreamComposeBox', (tester) async {
final channel = eg.stream();
final key = await prepareComposeBox(tester,
narrow: ChannelNarrow(eg.stream().streamId));
narrow: ChannelNarrow(channel.streamId), streams: [channel]);
checkComposeBoxTextFields(tester, controllerKey: key,
expectTopicTextField: true);
});

testWidgets('_FixedDestinationComposeBox', (tester) async {
final channel = eg.stream();
final key = await prepareComposeBox(tester,
narrow: TopicNarrow.ofMessage(eg.streamMessage()));
narrow: TopicNarrow(channel.streamId, 'topic'), streams: [channel]);
checkComposeBoxTextFields(tester, controllerKey: key,
expectTopicTextField: false);
});
Expand All @@ -207,7 +214,8 @@ void main() {
required void Function(int messageId) prepareResponse,
}) async {
final zulipLocalizations = GlobalLocalizations.zulipLocalizations;
await prepareComposeBox(tester, narrow: const TopicNarrow(123, 'some topic'));
await prepareComposeBox(tester, narrow: const TopicNarrow(123, 'some topic'),
streams: [eg.stream(streamId: 123)]);

final contentInputFinder = find.byWidgetPredicate(
(widget) => widget is TextField && widget.controller is ComposeContentController);
Expand Down Expand Up @@ -271,7 +279,9 @@ void main() {

group('attach from media library', () {
testWidgets('success', (tester) async {
final controllerKey = await prepareComposeBox(tester, narrow: ChannelNarrow(eg.stream().streamId));
final channel = eg.stream();
final controllerKey = await prepareComposeBox(tester,
narrow: ChannelNarrow(channel.streamId), streams: [channel]);
final composeBoxController = controllerKey.currentState!;

// (When we check that the send button looks disabled, it should be because
Expand Down Expand Up @@ -326,8 +336,10 @@ void main() {
});

group('attach from camera', () {
testWidgets('success', (tester) async {
final controllerKey = await prepareComposeBox(tester, narrow: ChannelNarrow(eg.stream().streamId));
testWidgets('succMessageListPageState.narrowess', (tester) async {
final channel = eg.stream();
final controllerKey = await prepareComposeBox(tester,
narrow: ChannelNarrow(channel.streamId), streams: [channel]);
final composeBoxController = controllerKey.currentState!;

// (When we check that the send button looks disabled, it should be because
Expand Down
6 changes: 4 additions & 2 deletions test/widgets/message_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,17 @@ void main() {
testWidgets('MessageListPageState.narrow', (tester) async {
final stream = eg.stream();
await setupMessageListPage(tester, narrow: ChannelNarrow(stream.streamId),
messages: [eg.streamMessage(stream: stream, content: "<p>a message</p>")]);
messages: [eg.streamMessage(stream: stream, content: "<p>a message</p>")],
streams: [stream]);
final state = MessageListPage.ancestorOf(tester.element(find.text("a message")));
check(state.narrow).equals(ChannelNarrow(stream.streamId));
});

testWidgets('composeBoxController finds compose box', (tester) async {
final stream = eg.stream();
await setupMessageListPage(tester, narrow: ChannelNarrow(stream.streamId),
messages: [eg.streamMessage(stream: stream, content: "<p>a message</p>")]);
messages: [eg.streamMessage(stream: stream, content: "<p>a message</p>")],
streams: [stream]);
final state = MessageListPage.ancestorOf(tester.element(find.text("a message")));
check(state.composeBoxController).isNotNull();
});
Expand Down

0 comments on commit 12610dc

Please sign in to comment.