forked from zulip/zulip-flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
narrow: Add DmNarrow; handle in message list
This takes care of the bulk of zulip#142. The only thing missing is a way to navigate to one of these narrows, which we'll add next.
- Loading branch information
Showing
5 changed files
with
188 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
import 'package:checks/checks.dart'; | ||
import 'package:zulip/api/model/narrow.dart'; | ||
import 'package:zulip/model/narrow.dart'; | ||
|
||
extension NarrowChecks on Subject<Narrow> { | ||
Subject<ApiNarrow> get apiEncode => has((x) => x.apiEncode(), 'apiEncode()'); | ||
} | ||
|
||
extension DmNarrowChecks on Subject<DmNarrow> { | ||
Subject<List<int>> get allRecipientIds => has((x) => x.allRecipientIds, 'allRecipientIds'); | ||
Subject<List<int>> get otherRecipientIds => has((x) => x.otherRecipientIds, 'otherRecipientIds'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
|
||
import 'package:checks/checks.dart'; | ||
import 'package:test/scaffolding.dart'; | ||
import 'package:zulip/api/model/model.dart'; | ||
import 'package:zulip/model/narrow.dart'; | ||
|
||
import '../example_data.dart' as eg; | ||
import 'narrow_checks.dart'; | ||
|
||
void main() { | ||
group('DmNarrow', () { | ||
test('constructor assertions', () { | ||
check(() => DmNarrow(allRecipientIds: [2, 12], selfUserId: 2)).returnsNormally(); | ||
check(() => DmNarrow(allRecipientIds: [2], selfUserId: 2)).returnsNormally(); | ||
|
||
check(() => DmNarrow(allRecipientIds: [12, 2], selfUserId: 2)).throws(); | ||
check(() => DmNarrow(allRecipientIds: [2, 2], selfUserId: 2)).throws(); | ||
check(() => DmNarrow(allRecipientIds: [2, 12], selfUserId: 1)).throws(); | ||
check(() => DmNarrow(allRecipientIds: [], selfUserId: 2)).throws(); | ||
}); | ||
|
||
test('otherRecipientIds', () { | ||
check(DmNarrow(allRecipientIds: [1, 2, 3], selfUserId: 2)) | ||
.otherRecipientIds.deepEquals([1, 3]); | ||
check(DmNarrow(allRecipientIds: [1, 2], selfUserId: 2)) | ||
.otherRecipientIds.deepEquals([1]); | ||
check(DmNarrow(allRecipientIds: [2], selfUserId: 2)) | ||
.otherRecipientIds.deepEquals([]); | ||
}); | ||
|
||
test('containsMessage', () { | ||
final user1 = eg.user(userId: 1); | ||
final user2 = eg.user(userId: 2); | ||
final user3 = eg.user(userId: 3); | ||
final narrow2 = DmNarrow(allRecipientIds: [2], selfUserId: 2); | ||
final narrow12 = DmNarrow(allRecipientIds: [1, 2], selfUserId: 2); | ||
final narrow123 = DmNarrow(allRecipientIds: [1, 2, 3], selfUserId: 2); | ||
|
||
Message dm(User from, List<User> to) => eg.dmMessage(from: from, to: to); | ||
final streamMessage = eg.streamMessage(sender: user2); | ||
|
||
check(narrow2.containsMessage(streamMessage)).isFalse(); | ||
check(narrow2.containsMessage(dm(user2, []))).isTrue(); | ||
check(narrow2.containsMessage(dm(user1, [user2]))).isFalse(); | ||
check(narrow2.containsMessage(dm(user2, [user1]))).isFalse(); | ||
check(narrow2.containsMessage(dm(user1, [user2, user3]))).isFalse(); | ||
check(narrow2.containsMessage(dm(user2, [user1, user3]))).isFalse(); | ||
check(narrow2.containsMessage(dm(user3, [user1, user2]))).isFalse(); | ||
|
||
check(narrow12.containsMessage(streamMessage)).isFalse(); | ||
check(narrow12.containsMessage(dm(user2, []))).isFalse(); | ||
check(narrow12.containsMessage(dm(user1, [user2]))).isTrue(); | ||
check(narrow12.containsMessage(dm(user2, [user1]))).isTrue(); | ||
check(narrow12.containsMessage(dm(user1, [user2, user3]))).isFalse(); | ||
check(narrow12.containsMessage(dm(user2, [user1, user3]))).isFalse(); | ||
check(narrow12.containsMessage(dm(user3, [user1, user2]))).isFalse(); | ||
|
||
check(narrow123.containsMessage(streamMessage)).isFalse(); | ||
check(narrow123.containsMessage(dm(user2, []))).isFalse(); | ||
check(narrow123.containsMessage(dm(user1, [user2]))).isFalse(); | ||
check(narrow123.containsMessage(dm(user2, [user1]))).isFalse(); | ||
check(narrow123.containsMessage(dm(user1, [user2, user3]))).isTrue(); | ||
check(narrow123.containsMessage(dm(user2, [user1, user3]))).isTrue(); | ||
check(narrow123.containsMessage(dm(user3, [user1, user2]))).isTrue(); | ||
}); | ||
}); | ||
} |