diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-20 13:18:24 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-20 13:18:24 +0000 |
commit | 0653e08efd039a5905f3fa4f6e9cef9f5d2f799c (patch) | |
tree | 4dcc884cf6d81db44adae4aa99f8ec1233a41f55 /spec/frontend/experimentation/utils_spec.js | |
parent | 744144d28e3e7fddc117924fef88de5d9674fe4c (diff) | |
download | gitlab-ce-0653e08efd039a5905f3fa4f6e9cef9f5d2f799c.tar.gz |
Add latest changes from gitlab-org/gitlab@14-3-stable-eev14.3.0-rc42
Diffstat (limited to 'spec/frontend/experimentation/utils_spec.js')
-rw-r--r-- | spec/frontend/experimentation/utils_spec.js | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/spec/frontend/experimentation/utils_spec.js b/spec/frontend/experimentation/utils_spec.js index 2ba8c65a252..999bed1ffbd 100644 --- a/spec/frontend/experimentation/utils_spec.js +++ b/spec/frontend/experimentation/utils_spec.js @@ -37,6 +37,50 @@ describe('experiment Utilities', () => { }); }); + describe('getAllExperimentContexts', () => { + const schema = TRACKING_CONTEXT_SCHEMA; + let origGon; + + beforeEach(() => { + origGon = window.gon; + }); + + afterEach(() => { + window.gon = origGon; + }); + + it('collects all of the experiment contexts into a single array', () => { + const experiments = [ + { experiment: 'abc', variant: 'candidate' }, + { experiment: 'def', variant: 'control' }, + { experiment: 'ghi', variant: 'blue' }, + ]; + window.gon = { + experiment: experiments.reduce((collector, { experiment, variant }) => { + return { ...collector, [experiment]: { experiment, variant } }; + }, {}), + }; + + expect(experimentUtils.getAllExperimentContexts()).toEqual( + experiments.map((data) => ({ schema, data })), + ); + }); + + it('returns an empty array if there are no experiments', () => { + window.gon.experiment = {}; + + expect(experimentUtils.getAllExperimentContexts()).toEqual([]); + }); + + it('includes all additional experiment data', () => { + const experiment = 'experimentWithCustomData'; + const data = { experiment, variant: 'control', color: 'blue', style: 'rounded' }; + window.gon.experiment[experiment] = data; + + expect(experimentUtils.getAllExperimentContexts()).toContainEqual({ schema, data }); + }); + }); + describe('isExperimentVariant', () => { describe.each` gon | input | output |