diff options
Diffstat (limited to 'spec/frontend/tracking_spec.js')
-rw-r--r-- | spec/frontend/tracking_spec.js | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/spec/frontend/tracking_spec.js b/spec/frontend/tracking_spec.js index f3233bcd771..b59c3cda055 100644 --- a/spec/frontend/tracking_spec.js +++ b/spec/frontend/tracking_spec.js @@ -1,10 +1,13 @@ import { setHTMLFixture } from 'helpers/fixtures'; import { TRACKING_CONTEXT_SCHEMA } from '~/experimentation/constants'; -import { getExperimentData } from '~/experimentation/utils'; +import { getExperimentData, getAllExperimentContexts } from '~/experimentation/utils'; import Tracking, { initUserTracking, initDefaultTrackers } from '~/tracking'; import getStandardContext from '~/tracking/get_standard_context'; -jest.mock('~/experimentation/utils', () => ({ getExperimentData: jest.fn() })); +jest.mock('~/experimentation/utils', () => ({ + getExperimentData: jest.fn(), + getAllExperimentContexts: jest.fn(), +})); describe('Tracking', () => { let standardContext; @@ -29,6 +32,7 @@ describe('Tracking', () => { beforeEach(() => { getExperimentData.mockReturnValue(undefined); + getAllExperimentContexts.mockReturnValue([]); window.snowplow = window.snowplow || (() => {}); window.snowplowOptions = { @@ -100,6 +104,31 @@ describe('Tracking', () => { initDefaultTrackers(); expect(trackLoadEventsSpy).toHaveBeenCalled(); }); + + describe('when there are experiment contexts', () => { + const experimentContexts = [ + { + schema: TRACKING_CONTEXT_SCHEMA, + data: { experiment: 'experiment1', variant: 'control' }, + }, + { + schema: TRACKING_CONTEXT_SCHEMA, + data: { experiment: 'experiment_two', variant: 'candidate' }, + }, + ]; + + beforeEach(() => { + getAllExperimentContexts.mockReturnValue(experimentContexts); + }); + + it('includes those contexts alongside the standard context', () => { + initDefaultTrackers(); + expect(snowplowSpy).toHaveBeenCalledWith('trackPageView', null, [ + standardContext, + ...experimentContexts, + ]); + }); + }); }); describe('.event', () => { |