@@ -47,7 +47,8 @@ describe('isNarrowLink', () => {
47
47
[ true , 'with numeric stream ID' , urlOnRealm ( '#narrow/stream/123-jest' ) ] ,
48
48
[ true , 'with numeric stream ID and topic' , urlOnRealm ( '#narrow/stream/123-jest/topic/topic1' ) ] ,
49
49
50
- [ true , 'with numeric pm user IDs' , urlOnRealm ( '#narrow/pm-with/123-mark' ) ] ,
50
+ [ true , 'with numeric pm user IDs (new operator)' , urlOnRealm ( '#narrow/dm/123-mark' ) ] ,
51
+ [ true , 'with numeric pm user IDs (old operator)' , urlOnRealm ( '#narrow/pm-with/123-mark' ) ] ,
51
52
52
53
[ false , 'wrong fragment' , urlOnRealm ( '#nope' ) ] ,
53
54
[ false , 'wrong path' , urlOnRealm ( '/user_uploads/#narrow/stream/jest' ) ] ,
@@ -183,6 +184,15 @@ describe('getNarrowFromNarrowLink (part 1)', () => {
183
184
] . forEach ( hash => check ( hash ) ) ;
184
185
} ) ;
185
186
187
+ describe ( '"/#narrow/dm/<…>" is a PM link' , ( ) => {
188
+ const check = mkCheck ( isPmNarrow ) ;
189
+ [
190
+ '/#narrow/dm/1,2-group' ,
191
+ '/#narrow/dm/1,2-group/near/1' ,
192
+ '/#narrow/dm/a.40b.2Ecom.2Ec.2Ed.2Ecom/near/3' ,
193
+ ] . forEach ( hash => check ( hash ) ) ;
194
+ } ) ;
195
+
186
196
describe ( '"/#narrow/pm-with/<…>" is a PM link' , ( ) => {
187
197
const check = mkCheck ( isPmNarrow ) ;
188
198
[
@@ -194,9 +204,12 @@ describe('getNarrowFromNarrowLink (part 1)', () => {
194
204
195
205
describe ( '"/#narrow/is/<…>" with valid operand is a special link' , ( ) => {
196
206
const check = mkCheck ( isSpecialNarrow ) ;
197
- [ '/#narrow/is/private' , '/#narrow/is/starred' , '/#narrow/is/mentioned' ] . forEach ( hash =>
198
- check ( hash ) ,
199
- ) ;
207
+ [
208
+ '/#narrow/is/dm' ,
209
+ '/#narrow/is/private' ,
210
+ '/#narrow/is/starred' ,
211
+ '/#narrow/is/mentioned' ,
212
+ ] . forEach ( hash => check ( hash ) ) ;
200
213
} ) ;
201
214
202
215
describe ( 'unexpected link shape gives null' , ( ) => {
@@ -375,6 +388,9 @@ describe('getNarrowFromNarrowLink (part 2)', () => {
375
388
376
389
test ( 'on group PM link' , ( ) => {
377
390
const ids = `${ userB . user_id } ,${ userC . user_id } ` ;
391
+ expect ( get ( `https://example.com/#narrow/dm/${ ids } -group` , [ ] ) ) . toEqual (
392
+ pmNarrowFromUsersUnsafe ( [ userB , userC ] ) ,
393
+ ) ;
378
394
expect ( get ( `https://example.com/#narrow/pm-with/${ ids } -group` , [ ] ) ) . toEqual (
379
395
pmNarrowFromUsersUnsafe ( [ userB , userC ] ) ,
380
396
) ;
@@ -383,19 +399,26 @@ describe('getNarrowFromNarrowLink (part 2)', () => {
383
399
test ( 'on group PM link including self' , ( ) => {
384
400
// The webapp doesn't generate these, but best to handle them anyway.
385
401
const ids = `${ eg . selfUser . user_id } ,${ userB . user_id } ,${ userC . user_id } ` ;
402
+ expect ( get ( `https://example.com/#narrow/dm/${ ids } -group` , [ ] ) ) . toEqual (
403
+ pmNarrowFromUsersUnsafe ( [ userB , userC ] ) ,
404
+ ) ;
386
405
expect ( get ( `https://example.com/#narrow/pm-with/${ ids } -group` , [ ] ) ) . toEqual (
387
406
pmNarrowFromUsersUnsafe ( [ userB , userC ] ) ,
388
407
) ;
389
408
} ) ;
390
409
391
410
test ( 'on a special link' , ( ) => {
411
+ expect ( get ( '/#narrow/is/dm' , [ ] ) ) . toEqual ( ALL_PRIVATE_NARROW ) ;
392
412
expect ( get ( '/#narrow/is/private' , [ ] ) ) . toEqual ( ALL_PRIVATE_NARROW ) ;
393
413
expect ( get ( '/#narrow/is/starred' , [ ] ) ) . toEqual ( STARRED_NARROW ) ;
394
414
expect ( get ( '/#narrow/is/mentioned' , [ ] ) ) . toEqual ( MENTIONED_NARROW ) ;
395
415
} ) ;
396
416
397
417
test ( 'on a message link' , ( ) => {
398
418
const ids = `${ userB . user_id } ,${ userC . user_id } ` ;
419
+ expect ( get ( `https://example.com/#narrow/dm/${ ids } -group/near/2` , [ ] ) ) . toEqual (
420
+ pmNarrowFromUsersUnsafe ( [ userB , userC ] ) ,
421
+ ) ;
399
422
expect ( get ( `https://example.com/#narrow/pm-with/${ ids } -group/near/2` , [ ] ) ) . toEqual (
400
423
pmNarrowFromUsersUnsafe ( [ userB , userC ] ) ,
401
424
) ;
@@ -421,6 +444,7 @@ describe('getNearOperandFromLink', () => {
421
444
} ) ;
422
445
423
446
test ( 'when link is a group link, return anchor message id' , ( ) => {
447
+ expect ( getNearOperandFromLink ( new URL ( '/#narrow/dm/1,3-group/near/1/' , realm ) , realm ) ) . toBe ( 1 ) ;
424
448
expect (
425
449
getNearOperandFromLink ( new URL ( '/#narrow/pm-with/1,3-group/near/1/' , realm ) , realm ) ,
426
450
) . toBe ( 1 ) ;
0 commit comments