@@ -16,6 +16,7 @@ import {
16
16
} from '../internalLinks' ;
17
17
import * as eg from '../../__tests__/lib/exampleData' ;
18
18
import { isUrlRelative } from '../url' ;
19
+ import type { LinkType } from '../internalLinks' ;
19
20
20
21
const realm = new URL ( 'https://example.com' ) ;
21
22
const urlOnRealm = relativeUrl => {
@@ -121,19 +122,19 @@ describe('isNarrowLink', () => {
121
122
} ) ;
122
123
123
124
describe ( 'getLinkType' , ( ) => {
125
+ const mkCheck = ( expected : LinkType ) => hash => {
126
+ expect ( getLinkType ( new URL ( hash , realm ) , realm ) ) . toBe ( expected ) ;
127
+ } ;
128
+
124
129
test ( 'link containing "stream" is a stream link' , ( ) => {
125
- const check = hash => {
126
- expect ( getLinkType ( new URL ( hash , realm ) , realm ) ) . toBe ( 'stream' ) ;
127
- } ;
130
+ const check = mkCheck ( 'stream' ) ;
128
131
[ '/#narrow/stream/jest' , '/#narrow/stream/stream/' , '/#narrow/stream/topic/' ] . forEach ( hash =>
129
132
check ( hash ) ,
130
133
) ;
131
134
} ) ;
132
135
133
136
test ( 'link containing "topic" is a topic link' , ( ) => {
134
- const check = hash => {
135
- expect ( getLinkType ( new URL ( hash , realm ) , realm ) ) . toBe ( 'topic' ) ;
136
- } ;
137
+ const check = mkCheck ( 'topic' ) ;
137
138
[
138
139
'/#narrow/stream/jest/topic/test' ,
139
140
'/#narrow/stream/mobile/subject/topic/near/378333' ,
@@ -145,9 +146,7 @@ describe('getLinkType', () => {
145
146
} ) ;
146
147
147
148
test ( 'link containing "pm-with" is a PM link' , ( ) => {
148
- const check = hash => {
149
- expect ( getLinkType ( new URL ( hash , realm ) , realm ) ) . toBe ( 'pm' ) ;
150
- } ;
149
+ const check = mkCheck ( 'pm' ) ;
151
150
[
152
151
'/#narrow/pm-with/1,2-group' ,
153
152
'/#narrow/pm-with/1,2-group/near/1' ,
@@ -156,18 +155,14 @@ describe('getLinkType', () => {
156
155
} ) ;
157
156
158
157
test ( 'link containing "is" with valid operand is a special link' , ( ) => {
159
- const check = hash => {
160
- expect ( getLinkType ( new URL ( hash , realm ) , realm ) ) . toBe ( 'special' ) ;
161
- } ;
158
+ const check = mkCheck ( 'special' ) ;
162
159
[ '/#narrow/is/private' , '/#narrow/is/starred' , '/#narrow/is/mentioned' ] . forEach ( hash =>
163
160
check ( hash ) ,
164
161
) ;
165
162
} ) ;
166
163
167
164
test ( 'unexpected link shape gives "home"' , ( ) => {
168
- const check = hash => {
169
- expect ( getLinkType ( new URL ( hash , realm ) , realm ) ) . toBe ( 'home' ) ;
170
- } ;
165
+ const check = mkCheck ( 'home' ) ;
171
166
[
172
167
// `near` with no operand
173
168
'/#narrow/stream/stream/topic/topic/near/' ,
0 commit comments