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