summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOskar <oskar@mullvad.net>2025-09-30 14:04:07 +0200
committerOskar <oskar@mullvad.net>2025-10-01 13:19:43 +0200
commit3c2b13593aaf9ca1a44e4a2566216cd5ed7020cd (patch)
tree0c482be860be765db315bfa391d4603dc2fc0098
parentabf1237e5bd8bc7027cf5f66c0af29603ca3288c (diff)
downloadmullvadvpn-3c2b13593aaf9ca1a44e4a2566216cd5ed7020cd.tar.xz
mullvadvpn-3c2b13593aaf9ca1a44e4a2566216cd5ed7020cd.zip
Add generatePath helper function
-rw-r--r--desktop/packages/mullvad-vpn/test/e2e/lib/path-helpers.ts11
-rw-r--r--desktop/packages/mullvad-vpn/test/unit/path-helpers.spec.ts10
2 files changed, 20 insertions, 1 deletions
diff --git a/desktop/packages/mullvad-vpn/test/e2e/lib/path-helpers.ts b/desktop/packages/mullvad-vpn/test/e2e/lib/path-helpers.ts
index 5fe0573084..53986e7002 100644
--- a/desktop/packages/mullvad-vpn/test/e2e/lib/path-helpers.ts
+++ b/desktop/packages/mullvad-vpn/test/e2e/lib/path-helpers.ts
@@ -1,5 +1,16 @@
import { expect } from '@playwright/test';
+import { RoutePath } from '../../../src/shared/routes';
+
+export function generatePath(path: RoutePath, params: Record<string, string>): string {
+ return Object.entries(params)
+ .reduce(
+ (path, [name, value]) => path.replace(new RegExp(`:${name}\\??`), value),
+ path as string,
+ )
+ .replaceAll(new RegExp('/:.*?\\?', 'g'), '');
+}
+
// Match the actual path against against the expected path where the expected can contain parameters
function toMatchPath(actual: string, expected: string | null) {
const pass = matchPaths(expected, actual);
diff --git a/desktop/packages/mullvad-vpn/test/unit/path-helpers.spec.ts b/desktop/packages/mullvad-vpn/test/unit/path-helpers.spec.ts
index 0c0936c8aa..807604d2ea 100644
--- a/desktop/packages/mullvad-vpn/test/unit/path-helpers.spec.ts
+++ b/desktop/packages/mullvad-vpn/test/unit/path-helpers.spec.ts
@@ -1,7 +1,8 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';
-import { matchPaths } from '../e2e/lib/path-helpers';
+import { RoutePath } from '../../src/shared/routes';
+import { generatePath, matchPaths } from '../e2e/lib/path-helpers';
describe('E2E test path helper', () => {
it('should identify matching paths', () => {
@@ -21,4 +22,11 @@ describe('E2E test path helper', () => {
expect(() => matchPaths('/a/b/c', '/a/b/:param')).to.throw();
});
+
+ it('should correctly replace parameters', () => {
+ expect(generatePath('/a/b' as RoutePath, {})).to.equal('/a/b');
+ expect(generatePath('/a/:param' as RoutePath, { param: 'b' })).to.equal('/a/b');
+ expect(generatePath('/a/:param?' as RoutePath, { param: 'b' })).to.equal('/a/b');
+ expect(generatePath('/a/:param?' as RoutePath, {})).to.equal('/a');
+ });
});