|
1 | 1 | import 'package:checks/checks.dart';
|
2 | 2 | import 'package:test/scaffolding.dart';
|
3 | 3 | import 'package:zulip/model/compose.dart';
|
| 4 | +import 'package:zulip/model/narrow.dart'; |
| 5 | + |
| 6 | +import '../example_data.dart' as eg; |
| 7 | +import 'test_store.dart'; |
4 | 8 |
|
5 | 9 | void main() {
|
6 | 10 | group('wrapWithBacktickFence', () {
|
@@ -187,4 +191,71 @@ hello
|
187 | 191 | ''');
|
188 | 192 | });
|
189 | 193 | });
|
| 194 | + |
| 195 | + group('narrowLink', () { |
| 196 | + test('AllMessagesNarrow', () { |
| 197 | + final store = eg.store(); |
| 198 | + check(narrowLink(store, const AllMessagesNarrow())).equals(store.account.realmUrl.resolve('#narrow')); |
| 199 | + }); |
| 200 | + |
| 201 | + test('StreamNarrow / TopicNarrow', () { |
| 202 | + void checkNarrow(String expectedFragment, { |
| 203 | + required int streamId, |
| 204 | + required String name, |
| 205 | + String? topic, |
| 206 | + }) { |
| 207 | + assert(expectedFragment.startsWith('#'), 'wrong-looking expectedFragment'); |
| 208 | + final store = eg.store(); |
| 209 | + store.addStream(eg.stream(streamId: streamId, name: name)); |
| 210 | + final narrow = topic == null |
| 211 | + ? StreamNarrow(streamId) |
| 212 | + : TopicNarrow(streamId, topic); |
| 213 | + check(narrowLink(store, narrow)).equals(store.account.realmUrl.resolve(expectedFragment)); |
| 214 | + } |
| 215 | + |
| 216 | + checkNarrow(streamId: 1, name: 'announce', '#narrow/stream/1-announce'); |
| 217 | + checkNarrow(streamId: 378, name: 'api design', '#narrow/stream/378-api-design'); |
| 218 | + checkNarrow(streamId: 391, name: 'Outreachy', '#narrow/stream/391-Outreachy'); |
| 219 | + checkNarrow(streamId: 415, name: 'chat.zulip.org', '#narrow/stream/415-chat.2Ezulip.2Eorg'); |
| 220 | + checkNarrow(streamId: 419, name: 'français', '#narrow/stream/419-fran.C3.A7ais'); |
| 221 | + checkNarrow(streamId: 403, name: 'Hshs[™~}(.', '#narrow/stream/403-Hshs.5B.E2.84.A2~.7D.28.2E'); |
| 222 | + |
| 223 | + checkNarrow(streamId: 48, name: 'mobile', topic: 'Welcome screen UI', |
| 224 | + '#narrow/stream/48-mobile/topic/Welcome.20screen.20UI'); |
| 225 | + checkNarrow(streamId: 243, name: 'mobile-team', topic: 'Podfile.lock clash #F92', |
| 226 | + '#narrow/stream/243-mobile-team/topic/Podfile.2Elock.20clash.20.23F92'); |
| 227 | + checkNarrow(streamId: 377, name: 'translation/zh_tw', topic: '翻譯 "stream"', |
| 228 | + '#narrow/stream/377-translation.2Fzh_tw/topic/.E7.BF.BB.E8.AD.AF.20.22stream.22'); |
| 229 | + }); |
| 230 | + |
| 231 | + test('DmNarrow', () { |
| 232 | + void checkNarrow(String expectedFragment, String legacyExpectedFragment, { |
| 233 | + required List<int> allRecipientIds, |
| 234 | + required int selfUserId, |
| 235 | + }) { |
| 236 | + assert(expectedFragment.startsWith('#'), 'wrong-looking expectedFragment'); |
| 237 | + final store = eg.store(); |
| 238 | + final narrow = DmNarrow(allRecipientIds: allRecipientIds, selfUserId: selfUserId); |
| 239 | + check(narrowLink(store, narrow)).equals(store.account.realmUrl.resolve(expectedFragment)); |
| 240 | + store.connection.zulipFeatureLevel = 176; |
| 241 | + check(narrowLink(store, narrow)).equals(store.account.realmUrl.resolve(legacyExpectedFragment)); |
| 242 | + } |
| 243 | + |
| 244 | + checkNarrow(allRecipientIds: [1], selfUserId: 1, |
| 245 | + '#narrow/dm/1-dm', |
| 246 | + '#narrow/pm-with/1-pm'); |
| 247 | + checkNarrow(allRecipientIds: [1, 2], selfUserId: 1, |
| 248 | + '#narrow/dm/1,2-dm', |
| 249 | + '#narrow/pm-with/1,2-pm'); |
| 250 | + checkNarrow(allRecipientIds: [1, 2, 3], selfUserId: 1, |
| 251 | + '#narrow/dm/1,2,3-group', |
| 252 | + '#narrow/pm-with/1,2,3-group'); |
| 253 | + checkNarrow(allRecipientIds: [1, 2, 3, 4], selfUserId: 4, |
| 254 | + '#narrow/dm/1,2,3,4-group', |
| 255 | + '#narrow/pm-with/1,2,3,4-group'); |
| 256 | + }); |
| 257 | + |
| 258 | + // TODO other Narrow subclasses as we add them: |
| 259 | + // starred, mentioned; searches; arbitrary |
| 260 | + }); |
190 | 261 | }
|
0 commit comments