@@ -194,8 +194,10 @@ describe('getNarrowFromNarrowLink (part 1)', () => {
194
194
[
195
195
'/#narrow/channel/1-jest/topic/test' ,
196
196
'/#narrow/channel/4-mobile/subject/topic/near/378333' ,
197
+ '/#narrow/channel/4-mobile/subject/topic/with/378333' ,
197
198
'/#narrow/channel/4-mobile/topic/topic/' ,
198
199
'/#narrow/channel/3-stream/topic/topic/near/1' ,
200
+ '/#narrow/channel/3-stream/topic/topic/with/1' ,
199
201
] . forEach ( hash => check ( hash ) ) ;
200
202
} ) ;
201
203
@@ -204,9 +206,12 @@ describe('getNarrowFromNarrowLink (part 1)', () => {
204
206
[
205
207
'/#narrow/stream/jest/topic/test' ,
206
208
'/#narrow/stream/mobile/subject/topic/near/378333' ,
209
+ '/#narrow/stream/mobile/subject/topic/with/378333' ,
207
210
'/#narrow/stream/mobile/topic/topic/' ,
208
211
'/#narrow/stream/stream/topic/topic/near/1' ,
212
+ '/#narrow/stream/stream/topic/topic/with/1' ,
209
213
'/#narrow/stream/stream/subject/topic/near/1' ,
214
+ '/#narrow/stream/stream/subject/topic/with/1' ,
210
215
'/#narrow/stream/stream/subject/topic' ,
211
216
] . forEach ( hash => check ( hash ) ) ;
212
217
} ) ;
@@ -216,7 +221,9 @@ describe('getNarrowFromNarrowLink (part 1)', () => {
216
221
[
217
222
'/#narrow/dm/1,2-group' ,
218
223
'/#narrow/dm/1,2-group/near/1' ,
224
+ '/#narrow/dm/1,2-group/with/1' ,
219
225
'/#narrow/dm/a.40b.2Ecom.2Ec.2Ed.2Ecom/near/3' ,
226
+ '/#narrow/dm/a.40b.2Ecom.2Ec.2Ed.2Ecom/with/3' ,
220
227
] . forEach ( hash => check ( hash ) ) ;
221
228
} ) ;
222
229
@@ -225,7 +232,9 @@ describe('getNarrowFromNarrowLink (part 1)', () => {
225
232
[
226
233
'/#narrow/pm-with/1,2-group' ,
227
234
'/#narrow/pm-with/1,2-group/near/1' ,
235
+ '/#narrow/pm-with/1,2-group/with/1' ,
228
236
'/#narrow/pm-with/a.40b.2Ecom.2Ec.2Ed.2Ecom/near/3' ,
237
+ '/#narrow/pm-with/a.40b.2Ecom.2Ec.2Ed.2Ecom/with/3' ,
229
238
] . forEach ( hash => check ( hash ) ) ;
230
239
} ) ;
231
240
@@ -245,6 +254,9 @@ describe('getNarrowFromNarrowLink (part 1)', () => {
245
254
// `near` with no operand
246
255
'/#narrow/channel/stream/topic/topic/near/' ,
247
256
257
+ // `with` with no operand
258
+ '/#narrow/channel/stream/topic/topic/with/' ,
259
+
248
260
// `is` with invalid operand
249
261
'/#narrow/is/men' ,
250
262
'/#narrow/is/men/channel' ,
@@ -472,6 +484,31 @@ describe('getNarrowFromNarrowLink (part 2)', () => {
472
484
get ( `https://example.com/#narrow/stream/${ eg . stream . name } /subject/test/near/1` , [ eg . stream ] ) ,
473
485
) . toEqual ( topicNarrow ( eg . stream . stream_id , 'test' ) ) ;
474
486
} ) ;
487
+
488
+ test ( 'on a /with/ link' , ( ) => {
489
+ const ids = `${ userB . user_id } ,${ userC . user_id } ` ;
490
+ expect ( get ( `https://example.com/#narrow/dm/${ ids } -group/with/2` , [ ] ) ) . toEqual (
491
+ pmNarrowFromUsersUnsafe ( [ userB , userC ] ) ,
492
+ ) ;
493
+ expect ( get ( `https://example.com/#narrow/pm-with/${ ids } -group/with/2` , [ ] ) ) . toEqual (
494
+ pmNarrowFromUsersUnsafe ( [ userB , userC ] ) ,
495
+ ) ;
496
+
497
+ expect (
498
+ get (
499
+ `https://example.com/#narrow/channel/${ eg . stream . stream_id } -${ eg . stream . name } /topic/test/with/1` ,
500
+ [ eg . stream ] ,
501
+ ) ,
502
+ ) . toEqual ( topicNarrow ( eg . stream . stream_id , 'test' ) ) ;
503
+
504
+ expect (
505
+ get ( `https://example.com/#narrow/stream/${ eg . stream . name } /topic/test/with/1` , [ eg . stream ] ) ,
506
+ ) . toEqual ( topicNarrow ( eg . stream . stream_id , 'test' ) ) ;
507
+
508
+ expect (
509
+ get ( `https://example.com/#narrow/stream/${ eg . stream . name } /subject/test/with/1` , [ eg . stream ] ) ,
510
+ ) . toEqual ( topicNarrow ( eg . stream . stream_id , 'test' ) ) ;
511
+ } ) ;
475
512
} ) ;
476
513
477
514
describe ( 'getNearOperandFromLink' , ( ) => {
@@ -485,13 +522,24 @@ describe('getNearOperandFromLink', () => {
485
522
expect ( getNearOperandFromLink ( new URL ( '/#narrow/near/1' , realm ) , realm ) ) . toBe ( 1 ) ;
486
523
} ) ;
487
524
525
+ test ( '`with` is the only operator' , ( ) => {
526
+ expect ( getNearOperandFromLink ( new URL ( '/#narrow/with/1' , realm ) , realm ) ) . toBe ( 1 ) ;
527
+ } ) ;
528
+
488
529
test ( 'when link is a group link, return anchor message id' , ( ) => {
489
530
expect ( getNearOperandFromLink ( new URL ( '/#narrow/dm/1,3-group/near/1/' , realm ) , realm ) ) . toBe ( 1 ) ;
490
531
expect (
491
532
getNearOperandFromLink ( new URL ( '/#narrow/pm-with/1,3-group/near/1/' , realm ) , realm ) ,
492
533
) . toBe ( 1 ) ;
493
534
} ) ;
494
535
536
+ test ( 'when link is a group link with /with/, return anchor message id' , ( ) => {
537
+ expect ( getNearOperandFromLink ( new URL ( '/#narrow/dm/1,3-group/with/1/' , realm ) , realm ) ) . toBe ( 1 ) ;
538
+ expect (
539
+ getNearOperandFromLink ( new URL ( '/#narrow/pm-with/1,3-group/with/1/' , realm ) , realm ) ,
540
+ ) . toBe ( 1 ) ;
541
+ } ) ;
542
+
495
543
test ( 'when link is a topic link, return anchor message id' , ( ) => {
496
544
expect (
497
545
getNearOperandFromLink ( new URL ( '/#narrow/channel/1-jest/topic/test/near/1' , realm ) , realm ) ,
@@ -500,4 +548,13 @@ describe('getNearOperandFromLink', () => {
500
548
getNearOperandFromLink ( new URL ( '/#narrow/stream/jest/topic/test/near/1' , realm ) , realm ) ,
501
549
) . toBe ( 1 ) ;
502
550
} ) ;
551
+
552
+ test ( 'when link is a topic link with /with/, return anchor message id' , ( ) => {
553
+ expect (
554
+ getNearOperandFromLink ( new URL ( '/#narrow/channel/1-jest/topic/test/with/1' , realm ) , realm ) ,
555
+ ) . toBe ( 1 ) ;
556
+ expect (
557
+ getNearOperandFromLink ( new URL ( '/#narrow/stream/jest/topic/test/with/1' , realm ) , realm ) ,
558
+ ) . toBe ( 1 ) ;
559
+ } ) ;
503
560
} ) ;
0 commit comments