|
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', () {
|
@@ -215,4 +219,71 @@ hello
|
215 | 219 | ''');
|
216 | 220 | });
|
217 | 221 | });
|
| 222 | + |
| 223 | + group('narrowLink', () { |
| 224 | + test('AllMessagesNarrow', () { |
| 225 | + final store = eg.store(); |
| 226 | + check(narrowLink(store, const AllMessagesNarrow())).equals(store.account.realmUrl.resolve('#narrow')); |
| 227 | + }); |
| 228 | + |
| 229 | + test('StreamNarrow / TopicNarrow', () { |
| 230 | + void checkNarrow(String expectedFragment, { |
| 231 | + required int streamId, |
| 232 | + required String name, |
| 233 | + String? topic, |
| 234 | + }) { |
| 235 | + assert(expectedFragment.startsWith('#'), 'wrong-looking expectedFragment'); |
| 236 | + final store = eg.store(); |
| 237 | + store.addStream(eg.stream(streamId: streamId, name: name)); |
| 238 | + final narrow = topic == null |
| 239 | + ? StreamNarrow(streamId) |
| 240 | + : TopicNarrow(streamId, topic); |
| 241 | + check(narrowLink(store, narrow)).equals(store.account.realmUrl.resolve(expectedFragment)); |
| 242 | + } |
| 243 | + |
| 244 | + checkNarrow(streamId: 1, name: 'announce', '#narrow/stream/1-announce'); |
| 245 | + checkNarrow(streamId: 378, name: 'api design', '#narrow/stream/378-api-design'); |
| 246 | + checkNarrow(streamId: 391, name: 'Outreachy', '#narrow/stream/391-Outreachy'); |
| 247 | + checkNarrow(streamId: 415, name: 'chat.zulip.org', '#narrow/stream/415-chat.2Ezulip.2Eorg'); |
| 248 | + checkNarrow(streamId: 419, name: 'français', '#narrow/stream/419-fran.C3.A7ais'); |
| 249 | + checkNarrow(streamId: 403, name: 'Hshs[™~}(.', '#narrow/stream/403-Hshs.5B.E2.84.A2~.7D.28.2E'); |
| 250 | + |
| 251 | + checkNarrow(streamId: 48, name: 'mobile', topic: 'Welcome screen UI', |
| 252 | + '#narrow/stream/48-mobile/topic/Welcome.20screen.20UI'); |
| 253 | + checkNarrow(streamId: 243, name: 'mobile-team', topic: 'Podfile.lock clash #F92', |
| 254 | + '#narrow/stream/243-mobile-team/topic/Podfile.2Elock.20clash.20.23F92'); |
| 255 | + checkNarrow(streamId: 377, name: 'translation/zh_tw', topic: '翻譯 "stream"', |
| 256 | + '#narrow/stream/377-translation.2Fzh_tw/topic/.E7.BF.BB.E8.AD.AF.20.22stream.22'); |
| 257 | + }); |
| 258 | + |
| 259 | + test('DmNarrow', () { |
| 260 | + void checkNarrow(String expectedFragment, String legacyExpectedFragment, { |
| 261 | + required List<int> allRecipientIds, |
| 262 | + required int selfUserId, |
| 263 | + }) { |
| 264 | + assert(expectedFragment.startsWith('#'), 'wrong-looking expectedFragment'); |
| 265 | + final store = eg.store(); |
| 266 | + final narrow = DmNarrow(allRecipientIds: allRecipientIds, selfUserId: selfUserId); |
| 267 | + check(narrowLink(store, narrow)).equals(store.account.realmUrl.resolve(expectedFragment)); |
| 268 | + store.connection.zulipFeatureLevel = 176; |
| 269 | + check(narrowLink(store, narrow)).equals(store.account.realmUrl.resolve(legacyExpectedFragment)); |
| 270 | + } |
| 271 | + |
| 272 | + checkNarrow(allRecipientIds: [1], selfUserId: 1, |
| 273 | + '#narrow/dm/1-dm', |
| 274 | + '#narrow/pm-with/1-pm'); |
| 275 | + checkNarrow(allRecipientIds: [1, 2], selfUserId: 1, |
| 276 | + '#narrow/dm/1,2-dm', |
| 277 | + '#narrow/pm-with/1,2-pm'); |
| 278 | + checkNarrow(allRecipientIds: [1, 2, 3], selfUserId: 1, |
| 279 | + '#narrow/dm/1,2,3-group', |
| 280 | + '#narrow/pm-with/1,2,3-group'); |
| 281 | + checkNarrow(allRecipientIds: [1, 2, 3, 4], selfUserId: 4, |
| 282 | + '#narrow/dm/1,2,3,4-group', |
| 283 | + '#narrow/pm-with/1,2,3,4-group'); |
| 284 | + }); |
| 285 | + |
| 286 | + // TODO other Narrow subclasses as we add them: |
| 287 | + // starred, mentioned; searches; arbitrary |
| 288 | + }); |
218 | 289 | }
|
0 commit comments