|
| 1 | +import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest' |
| 2 | +import { RecordSDK } from '../sdk/record' |
| 3 | + |
| 4 | +const recordSpy = vi.fn((...args: any[]) => { |
| 5 | + return vi.fn() |
| 6 | +}) |
| 7 | +vi.mock('rrweb', () => ({ |
| 8 | + addCustomEvent: vi.fn(), |
| 9 | + record: (...args: any[]) => recordSpy(...args), |
| 10 | +})) |
| 11 | + |
| 12 | +// Mock GraphQL generated SDK used inside RecordSDK.initializeSession |
| 13 | +vi.mock('../client/graph/generated/operations', () => ({ |
| 14 | + getSdk: () => ({ |
| 15 | + initializeSession: vi.fn().mockResolvedValue({ |
| 16 | + initializeSession: { |
| 17 | + secure_id: 'test-session', |
| 18 | + project_id: '1', |
| 19 | + }, |
| 20 | + }), |
| 21 | + }), |
| 22 | +})) |
| 23 | + |
| 24 | +// Provide a minimal worker mock used by RecordSDK |
| 25 | +vi.mock('../client/workers/highlight-client-worker?worker&inline', () => ({ |
| 26 | + default: class MockWorker { |
| 27 | + onmessage: any |
| 28 | + postMessage() {} |
| 29 | + }, |
| 30 | +})) |
| 31 | + |
| 32 | +describe('RecordSDK -> rrweb.record config wiring', () => { |
| 33 | + const originalWindow = global.window |
| 34 | + |
| 35 | + beforeEach(() => { |
| 36 | + vi.useFakeTimers() |
| 37 | + recordSpy.mockClear() |
| 38 | + }) |
| 39 | + |
| 40 | + afterEach(() => { |
| 41 | + vi.useRealTimers() |
| 42 | + global.window = originalWindow |
| 43 | + }) |
| 44 | + |
| 45 | + it('passes default ignore/block/mask options to rrweb.record', async () => { |
| 46 | + const sdk = new RecordSDK({ |
| 47 | + organizationID: '1', |
| 48 | + sessionSecureID: 'seed', |
| 49 | + }) |
| 50 | + |
| 51 | + await sdk.start() |
| 52 | + |
| 53 | + expect(recordSpy).toHaveBeenCalledTimes(1) |
| 54 | + const arg = (recordSpy.mock.calls as any[])[0][0] |
| 55 | + // Defaults |
| 56 | + expect(arg.ignoreClass).toBe('highlight-ignore') |
| 57 | + expect(arg.blockClass).toBe('highlight-block') |
| 58 | + expect(arg.ignoreSelector).toBeUndefined() |
| 59 | + expect(arg.blockSelector).toBeUndefined() |
| 60 | + expect(arg.maskTextClass).toBeUndefined() |
| 61 | + expect(arg.maskTextSelector).toBeUndefined() |
| 62 | + }) |
| 63 | + |
| 64 | + it('respects overridden ignore/block/mask options', async () => { |
| 65 | + const sdk = new RecordSDK({ |
| 66 | + organizationID: '1', |
| 67 | + sessionSecureID: 'seed', |
| 68 | + ignoreClass: 'custom-ignore', |
| 69 | + ignoreSelector: '.ignore-me', |
| 70 | + blockClass: 'custom-block', |
| 71 | + blockSelector: '.block-me', |
| 72 | + maskTextClass: 'mask-this', |
| 73 | + maskTextSelector: '.mask-me', |
| 74 | + }) |
| 75 | + |
| 76 | + await sdk.start() |
| 77 | + |
| 78 | + expect(recordSpy).toHaveBeenCalledTimes(1) |
| 79 | + const arg = (recordSpy.mock.calls as any[])[0][0] |
| 80 | + expect(arg.ignoreClass).toBe('custom-ignore') |
| 81 | + expect(arg.ignoreSelector).toBe('.ignore-me') |
| 82 | + expect(arg.blockClass).toBe('custom-block') |
| 83 | + expect(arg.blockSelector).toBe('.block-me') |
| 84 | + expect(arg.maskTextClass).toBe('mask-this') |
| 85 | + expect(arg.maskTextSelector).toBe('.mask-me') |
| 86 | + }) |
| 87 | +}) |
0 commit comments