Skip to content

Commit 07c9c71

Browse files
EnochteoHugo-RM
authored andcommitted
Added test file: client/utils/parseURLParams.test.js
I have added a test file for the URL parameter parsing utility located at client/utils/parseURLParams.js. This test file includes various test cases to ensure the correct functionality of the parseURLParams function, covering edge cases and typical usage scenarios. For the add-on flags I allowed 'on', 'true', '1', 'ON', 'True', and 'TRUE' to be interpreted as true, while 'off', 'false', '0', 'OFF', 'False', and 'FALSE' are interpreted as false. This should enhance the robustness of the URL parameter parsing in our application.
1 parent b72c387 commit 07c9c71

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { parseUrlParams } from './parseURLParams.js';
2+
import { currentP5Version } from '../../common/p5Versions';
3+
4+
describe('parseUrlParams', () => {
5+
test('returns defaults when no params are provided', () => {
6+
const url = 'https://example.com';
7+
const result = parseUrlParams(url);
8+
9+
expect(result).toEqual({
10+
version: currentP5Version,
11+
sound: undefined,
12+
preload: undefined,
13+
shapes: undefined,
14+
data: undefined
15+
});
16+
});
17+
18+
test('parses a valid p5 version and falls back for invalid versions', () => {
19+
const good = parseUrlParams('https://example.com?version=1.4.0');
20+
expect(good.version).toBe('1.4.0');
21+
22+
const bad = parseUrlParams('https://example.com?version=9.9.9');
23+
expect(bad.version).toBe(currentP5Version);
24+
});
25+
26+
test('parses boolean-like params for sound/preload/shapes/data (true variants)', () => {
27+
const trueVariants = ['on', 'true', '1', 'ON', 'True'];
28+
29+
trueVariants.forEach((v) => {
30+
const url = `https://example.com?sound=${v}&preload=${v}&shapes=${v}&data=${v}`;
31+
const result = parseUrlParams(url);
32+
expect(result.sound).toBe(true);
33+
expect(result.preload).toBe(true);
34+
expect(result.shapes).toBe(true);
35+
expect(result.data).toBe(true);
36+
});
37+
});
38+
39+
test('parses boolean-like params for sound/preload/shapes/data (false variants)', () => {
40+
const falseVariants = ['off', 'false', '0', 'OFF', 'False'];
41+
42+
falseVariants.forEach((v) => {
43+
const url = `https://example.com?sound=${v}&preload=${v}&shapes=${v}&data=${v}`;
44+
const result = parseUrlParams(url);
45+
expect(result.sound).toBe(false);
46+
expect(result.preload).toBe(false);
47+
expect(result.shapes).toBe(false);
48+
expect(result.data).toBe(false);
49+
});
50+
});
51+
});

0 commit comments

Comments
 (0)