@networkpro/web 1.14.1 → 1.14.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,44 +6,54 @@ SPDX-License-Identifier: CC-BY-4.0 OR GPL-3.0-or-later
6
6
  This file is part of Network Pro.
7
7
  ========================================================================== */
8
8
 
9
- import { appendUTM } from '$lib/utils/utm.js';
10
- import { afterEach, describe, expect, it } from 'vitest';
9
+ // Mock SvelteKit environment and store
10
+ vi.mock('$app/environment', () => ({ browser: true }));
11
11
 
12
- describe('appendUTM', () => {
13
- const originalWindow = globalThis.window;
12
+ import { writable } from 'svelte/store';
14
13
 
15
- afterEach(() => {
16
- globalThis.window = originalWindow;
14
+ vi.mock('$app/stores', () => {
15
+ const mockPageStore = writable({
16
+ url: {
17
+ pathname: '/contact',
18
+ },
17
19
  });
18
20
 
19
- it('should return null when not in a browser environment', () => {
20
- // @ts-expect-error simulating SSR
21
- delete globalThis.window;
21
+ return {
22
+ getStores: () => ({
23
+ page: mockPageStore,
24
+ }),
25
+ };
26
+ });
27
+
28
+ import { appendUTM } from '$lib/utils/utm.js';
29
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
22
30
 
23
- const url = 'https://example.com';
24
- const result = appendUTM(url);
25
- expect(result).toBe(null);
26
- });
31
+ describe('appendUTM', () => {
32
+ const originalWindow = globalThis.window;
27
33
 
28
- it('should return URL with utm_source appended', () => {
34
+ beforeEach(() => {
29
35
  globalThis.window = {
30
- // @ts-expect-error mock minimal window for test
31
- location: { search: '?utm_source=linkedin' },
36
+ location: { search: '' },
32
37
  };
38
+ });
39
+
40
+ afterEach(() => {
41
+ globalThis.window = originalWindow;
42
+ });
33
43
 
44
+ it('should return URL with utm parameters for /contact', () => {
34
45
  const url = 'https://example.com';
35
46
  const result = appendUTM(url);
36
- expect(result).toBe('https://example.com?utm_source=linkedin');
47
+ expect(result).toBe(
48
+ 'https://example.com?utm_source=netwk.pro&utm_medium=redirect&utm_campaign=contact',
49
+ );
37
50
  });
38
51
 
39
- it('should return original URL if no utm_source is present', () => {
40
- globalThis.window = {
41
- // @ts-expect-error – mock minimal window for test
42
- location: { search: '' },
43
- };
44
-
45
- const url = 'https://example.com';
52
+ it('should append using & if URL already has query params', () => {
53
+ const url = 'https://example.com?existing=value';
46
54
  const result = appendUTM(url);
47
- expect(result).toBe('https://example.com');
55
+ expect(result).toBe(
56
+ 'https://example.com?existing=value&utm_source=netwk.pro&utm_medium=redirect&utm_campaign=contact',
57
+ );
48
58
  });
49
59
  });