Skip to content

Commit 72a5166

Browse files
test(sonar): getUrlParams
1 parent 5882410 commit 72a5166

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/api/common/utils.spec.tsx

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { toCamelCase, toSnakeCase } from './utils';
1+
import { getUrlParameters, toCamelCase, toSnakeCase } from './utils';
22

33
describe('utils', () => {
44
describe('toCamelCase', () => {
@@ -57,3 +57,32 @@ describe('utils', () => {
5757
});
5858
});
5959
});
60+
61+
describe('getUrlParameters', () => {
62+
it('should return null for a null URL', () => {
63+
const result = getUrlParameters(null);
64+
expect(result).toBeNull();
65+
});
66+
67+
it('should return an empty object for a URL with no parameters', () => {
68+
const result = getUrlParameters('https://example.com');
69+
expect(result).toEqual({});
70+
});
71+
72+
it('should return an object with a single key-value pair for a URL with one parameter', () => {
73+
const result = getUrlParameters('https://example.com?name=John');
74+
expect(result).toEqual({ name: 'John' });
75+
});
76+
77+
it('should return an object with multiple key-value pairs for a URL with multiple parameters', () => {
78+
const result = getUrlParameters('https://example.com?name=John&age=30');
79+
expect(result).toEqual({ name: 'John', age: '30' });
80+
});
81+
82+
it('should handle special characters in the URL parameters', () => {
83+
const result = getUrlParameters(
84+
'https://example.com?name=John%20Doe&city=New%20York'
85+
);
86+
expect(result).toEqual({ name: 'John Doe', city: 'New York' });
87+
});
88+
});

0 commit comments

Comments
 (0)