Skip to content

Commit 02a66ea

Browse files
review: add comment and tests
1 parent b8e023e commit 02a66ea

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/store/getUrlData.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const getUrlData = ({
88
customBackend?: string;
99
}) => {
1010
// UI could be located in "monitoring" or "ui" folders
11+
// my-host:8765/some/path/monitoring/react-router-path or my-host:8765/some/path/ui/react-router-path
1112
const parsedPrefix = window.location.pathname.match(/.*(?=\/(monitoring|ui)\/)/) || [];
1213
const basenamePrefix = parsedPrefix.length > 0 ? parsedPrefix[0] : '';
1314
const folder = parsedPrefix.length > 1 ? parsedPrefix[1] : '';

src/utils/__test__/index.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import {normalizePathSlashes} from '../';
2+
3+
describe('normalizePathSlashes', () => {
4+
test('should handle empty strings', () => {
5+
expect(normalizePathSlashes('')).toBe('');
6+
});
7+
test('should handle strings without slashes', () => {
8+
expect(normalizePathSlashes('path')).toBe('path');
9+
});
10+
test('should handle paths with single slash', () => {
11+
expect(normalizePathSlashes('/path')).toBe('/path');
12+
});
13+
test('should handle paths with trailing slash', () => {
14+
expect(normalizePathSlashes('path/')).toBe('path/');
15+
});
16+
test('should handle paths with multiple trailing slashes', () => {
17+
expect(normalizePathSlashes('path////')).toBe('path/');
18+
});
19+
test('should handle full paths with normal slashes', () => {
20+
expect(normalizePathSlashes('http://example.com/path/to/resource')).toBe(
21+
'http://example.com/path/to/resource',
22+
);
23+
});
24+
test('should replace multiple slashes with a single slash', () => {
25+
expect(normalizePathSlashes('http://example.com//path//to////resource')).toBe(
26+
'http://example.com/path/to/resource',
27+
);
28+
});
29+
test('should replace slashes more than two slashes after a colon', () => {
30+
expect(normalizePathSlashes('http://///example.com/path/to/resource')).toBe(
31+
'http://example.com/path/to/resource',
32+
);
33+
});
34+
});

0 commit comments

Comments
 (0)