|
| 1 | +import { isUserInVariant } from '../../experiments/ab'; |
| 2 | +import { recordAdmiralOphanEvent } from './admiral'; |
| 3 | + |
| 4 | +jest.mock('../../experiments/ab'); |
| 5 | + |
| 6 | +// Mock Ophan |
| 7 | +window.guardian.ophan = { |
| 8 | + trackComponentAttention: jest.fn(), |
| 9 | + viewId: '', |
| 10 | + pageViewId: '', |
| 11 | + record: jest.fn(), |
| 12 | +}; |
| 13 | + |
| 14 | +describe('Admiral functions', () => { |
| 15 | + describe('recordAdmiralOphanEvent', () => { |
| 16 | + it('calls ophan.record with expected params for action provided', () => { |
| 17 | + jest.mocked(isUserInVariant).mockReturnValue(true); |
| 18 | + |
| 19 | + recordAdmiralOphanEvent({ action: 'INSERT' }); |
| 20 | + const expectedComponentEvent = { |
| 21 | + component: { |
| 22 | + componentType: 'AD_BLOCK_RECOVERY', |
| 23 | + id: 'admiral-adblock-recovery', |
| 24 | + }, |
| 25 | + action: 'INSERT', |
| 26 | + abTest: { |
| 27 | + name: 'AdmiralAdblockRecovery', |
| 28 | + variant: 'variant-detect', |
| 29 | + }, |
| 30 | + }; |
| 31 | + expect(window.guardian.ophan?.record).toHaveBeenCalledWith({ |
| 32 | + componentEvent: expectedComponentEvent, |
| 33 | + }); |
| 34 | + }); |
| 35 | + |
| 36 | + it('calls ophan.record with expected params for action and value provided', () => { |
| 37 | + jest.mocked(isUserInVariant).mockReturnValue(true); |
| 38 | + |
| 39 | + recordAdmiralOphanEvent({ action: 'DETECT', value: 'whitelisted' }); |
| 40 | + const expectedComponentEvent = { |
| 41 | + component: { |
| 42 | + componentType: 'AD_BLOCK_RECOVERY', |
| 43 | + id: 'admiral-adblock-recovery', |
| 44 | + }, |
| 45 | + action: 'DETECT', |
| 46 | + value: 'whitelisted', |
| 47 | + abTest: { |
| 48 | + name: 'AdmiralAdblockRecovery', |
| 49 | + variant: 'variant-detect', |
| 50 | + }, |
| 51 | + }; |
| 52 | + expect(window.guardian.ophan?.record).toHaveBeenCalledWith({ |
| 53 | + componentEvent: expectedComponentEvent, |
| 54 | + }); |
| 55 | + }); |
| 56 | + |
| 57 | + it('omits the abTest key value pair if not in a variant', () => { |
| 58 | + jest.mocked(isUserInVariant).mockReturnValue(false); |
| 59 | + |
| 60 | + recordAdmiralOphanEvent({ action: 'DETECT', value: 'whitelisted' }); |
| 61 | + const expectedComponentEvent = { |
| 62 | + component: { |
| 63 | + componentType: 'AD_BLOCK_RECOVERY', |
| 64 | + id: 'admiral-adblock-recovery', |
| 65 | + }, |
| 66 | + action: 'DETECT', |
| 67 | + value: 'whitelisted', |
| 68 | + }; |
| 69 | + expect(window.guardian.ophan?.record).toHaveBeenCalledWith({ |
| 70 | + componentEvent: expectedComponentEvent, |
| 71 | + }); |
| 72 | + }); |
| 73 | + }); |
| 74 | +}); |
0 commit comments