@@ -117,22 +117,13 @@ describe('isNarrowLink', () => {
117
117
} ) ;
118
118
119
119
describe ( 'getLinkType' , ( ) => {
120
- test ( 'only link containing "stream" is a stream link' , ( ) => {
121
- expect ( getLinkType ( new URL ( '/#narrow/pm-with/1,2-group' , realm ) , realm ) ) . toBe ( 'pm' ) ;
120
+ test ( 'link containing "stream" is a stream link' , ( ) => {
122
121
expect ( getLinkType ( new URL ( '/#narrow/stream/jest' , realm ) , realm ) ) . toBe ( 'stream' ) ;
123
122
expect ( getLinkType ( new URL ( '/#narrow/stream/stream/' , realm ) , realm ) ) . toBe ( 'stream' ) ;
124
- } ) ;
125
-
126
- test ( 'when a url is not a topic narrow return false' , ( ) => {
127
- expect ( getLinkType ( new URL ( '/#narrow/pm-with/1,2-group' , realm ) , realm ) ) . toBe ( 'pm' ) ;
128
- expect ( getLinkType ( new URL ( '/#narrow/stream/jest' , realm ) , realm ) ) . toBe ( 'stream' ) ;
129
- expect ( getLinkType ( new URL ( '/#narrow/stream/stream/topic/topic/near/' , realm ) , realm ) ) . toBe (
130
- 'home' ,
131
- ) ;
132
123
expect ( getLinkType ( new URL ( '/#narrow/stream/topic/' , realm ) , realm ) ) . toBe ( 'stream' ) ;
133
124
} ) ;
134
125
135
- test ( 'when a url is a topic narrow return true ' , ( ) => {
126
+ test ( 'link containing "topic" is a topic link ' , ( ) => {
136
127
expect ( getLinkType ( new URL ( '/#narrow/stream/jest/topic/test' , realm ) , realm ) ) . toBe ( 'topic' ) ;
137
128
expect (
138
129
getLinkType ( new URL ( '/#narrow/stream/mobile/subject/topic/near/378333' , realm ) , realm ) ,
@@ -150,22 +141,31 @@ describe('getLinkType', () => {
150
141
) ;
151
142
} ) ;
152
143
153
- test ( 'only link containing "pm-with" is a group link' , ( ) => {
154
- expect ( getLinkType ( new URL ( '/#narrow/stream/jest/topic/test' , realm ) , realm ) ) . toBe ( 'topic' ) ;
144
+ test ( 'link containing "pm-with" is a PM link' , ( ) => {
155
145
expect ( getLinkType ( new URL ( '/#narrow/pm-with/1,2-group' , realm ) , realm ) ) . toBe ( 'pm' ) ;
156
146
expect ( getLinkType ( new URL ( '/#narrow/pm-with/1,2-group/near/1' , realm ) , realm ) ) . toBe ( 'pm' ) ;
157
147
expect (
158
148
getLinkType ( new URL ( '/#narrow/pm-with/a.40b.2Ecom.2Ec.2Ed.2Ecom/near/3' , realm ) , realm ) ,
159
149
) . toBe ( 'pm' ) ;
160
150
} ) ;
161
151
162
- test ( 'only link containing "is" is a special link' , ( ) => {
163
- expect ( getLinkType ( new URL ( '/#narrow/stream/jest/topic/test' , realm ) , realm ) ) . toBe ( 'topic' ) ;
152
+ test ( 'link containing "is" with valid operand is a special link' , ( ) => {
164
153
expect ( getLinkType ( new URL ( '/#narrow/is/private' , realm ) , realm ) ) . toBe ( 'special' ) ;
165
154
expect ( getLinkType ( new URL ( '/#narrow/is/starred' , realm ) , realm ) ) . toBe ( 'special' ) ;
166
155
expect ( getLinkType ( new URL ( '/#narrow/is/mentioned' , realm ) , realm ) ) . toBe ( 'special' ) ;
156
+ } ) ;
157
+
158
+ test ( 'unexpected link shape gives "home"' , ( ) => {
159
+ // `near` with no operand
160
+ expect ( getLinkType ( new URL ( '/#narrow/stream/stream/topic/topic/near/' , realm ) , realm ) ) . toBe (
161
+ 'home' ,
162
+ ) ;
163
+
164
+ // `is` with invalid operand
167
165
expect ( getLinkType ( new URL ( '/#narrow/is/men' , realm ) , realm ) ) . toBe ( 'home' ) ;
168
166
expect ( getLinkType ( new URL ( '/#narrow/is/men/stream' , realm ) , realm ) ) . toBe ( 'home' ) ;
167
+
168
+ // invalid operand `are`; `stream` operator with no operand
169
169
expect ( getLinkType ( new URL ( '/#narrow/are/men/stream' , realm ) , realm ) ) . toBe ( 'home' ) ;
170
170
} ) ;
171
171
} ) ;
0 commit comments