Skip to content

Commit 508b485

Browse files
chrisbobbegnprice
authored andcommitted
internalLinks tests: Organize getLinkType cases by expected result
Some cases were duplicated; deduplicate those.
1 parent 4b63be2 commit 508b485

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/utils/__tests__/internalLinks-test.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -117,22 +117,13 @@ describe('isNarrowLink', () => {
117117
});
118118

119119
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', () => {
122121
expect(getLinkType(new URL('/#narrow/stream/jest', realm), realm)).toBe('stream');
123122
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-
);
132123
expect(getLinkType(new URL('/#narrow/stream/topic/', realm), realm)).toBe('stream');
133124
});
134125

135-
test('when a url is a topic narrow return true', () => {
126+
test('link containing "topic" is a topic link', () => {
136127
expect(getLinkType(new URL('/#narrow/stream/jest/topic/test', realm), realm)).toBe('topic');
137128
expect(
138129
getLinkType(new URL('/#narrow/stream/mobile/subject/topic/near/378333', realm), realm),
@@ -150,22 +141,31 @@ describe('getLinkType', () => {
150141
);
151142
});
152143

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', () => {
155145
expect(getLinkType(new URL('/#narrow/pm-with/1,2-group', realm), realm)).toBe('pm');
156146
expect(getLinkType(new URL('/#narrow/pm-with/1,2-group/near/1', realm), realm)).toBe('pm');
157147
expect(
158148
getLinkType(new URL('/#narrow/pm-with/a.40b.2Ecom.2Ec.2Ed.2Ecom/near/3', realm), realm),
159149
).toBe('pm');
160150
});
161151

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', () => {
164153
expect(getLinkType(new URL('/#narrow/is/private', realm), realm)).toBe('special');
165154
expect(getLinkType(new URL('/#narrow/is/starred', realm), realm)).toBe('special');
166155
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
167165
expect(getLinkType(new URL('/#narrow/is/men', realm), realm)).toBe('home');
168166
expect(getLinkType(new URL('/#narrow/is/men/stream', realm), realm)).toBe('home');
167+
168+
// invalid operand `are`; `stream` operator with no operand
169169
expect(getLinkType(new URL('/#narrow/are/men/stream', realm), realm)).toBe('home');
170170
});
171171
});

0 commit comments

Comments
 (0)