Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compose_box: Replace compose box with a banner when cannot post in a channel #886

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
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)]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compose_box: Replace compose box with a banner when cannot post in a channel

This seems like a reasonable change to the action-sheet tests, but why is it needed in this commit, which is about the compose box?

…Ah, I think I understand: it's a boring but necessary bit of setup so that the simulated action sheet doesn't crash in the code that decides whether to show the error banner. Is that right?

There are quite a few other changes in this commit that look like they're made for the same reason. Would you move those to a prep commit before this commit? That should make it easier to focus on the interesting changes here. 🙂

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
22 changes: 17 additions & 5 deletions test/widgets/compose_box_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,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.');
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this belongs to the previous commit.

addTearDown(testBinding.reset);
final account = eg.account(user: selfUser ?? eg.selfUser);
await testBinding.globalStore.add(account, eg.initialSnapshot(
Expand Down Expand Up @@ -189,15 +194,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 @@ -208,7 +215,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 @@ -272,7 +280,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 @@ -328,7 +338,9 @@ void main() {

group('attach from camera', () {
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
6 changes: 4 additions & 2 deletions test/widgets/message_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,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