Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-04-02 21:09:20 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-04-02 21:09:20 +0300
commitfee10148072e2e96d14034f099985a441a844c6e (patch)
tree64ed9aa910ed10df0f06a0b010f221443baec8bc /spec/frontend/experimentation/utils_spec.js
parent02c151e384fe058fa070d50c6df94898385ff09c (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/experimentation/utils_spec.js')
-rw-r--r--spec/frontend/experimentation/utils_spec.js103
1 files changed, 74 insertions, 29 deletions
diff --git a/spec/frontend/experimentation/utils_spec.js b/spec/frontend/experimentation/utils_spec.js
index 80ea10db727..ec09bbab349 100644
--- a/spec/frontend/experimentation/utils_spec.js
+++ b/spec/frontend/experimentation/utils_spec.js
@@ -1,48 +1,93 @@
-import { DEFAULT_VARIANT } from '~/experimentation/constants';
+import { assignGitlabExperiment } from 'helpers/experimentation_helper';
+import { DEFAULT_VARIANT, CANDIDATE_VARIANT } from '~/experimentation/constants';
import * as experimentUtils from '~/experimentation/utils';
-const TEST_KEY = 'abc';
-
describe('experiment Utilities', () => {
- const oldGon = window.gon;
-
- afterEach(() => {
- window.gon = oldGon;
- });
+ const TEST_KEY = 'abc';
describe('getExperimentData', () => {
- it.each`
- gon | input | output
- ${{ experiment: { [TEST_KEY]: '_data_' } }} | ${[TEST_KEY]} | ${'_data_'}
- ${{}} | ${[TEST_KEY]} | ${undefined}
- `('with input=$input and gon=$gon, returns $output', ({ gon, input, output }) => {
- window.gon = gon;
+ describe.each`
+ gon | input | output
+ ${[TEST_KEY, '_data_']} | ${[TEST_KEY]} | ${{ variant: '_data_' }}
+ ${[]} | ${[TEST_KEY]} | ${undefined}
+ `('with input=$input and gon=$gon', ({ gon, input, output }) => {
+ assignGitlabExperiment(...gon);
- expect(experimentUtils.getExperimentData(...input)).toEqual(output);
+ it(`returns ${output}`, () => {
+ expect(experimentUtils.getExperimentData(...input)).toEqual(output);
+ });
});
});
describe('isExperimentVariant', () => {
- it.each`
- gon | input | output
- ${{ experiment: { [TEST_KEY]: { variant: 'control' } } }} | ${[TEST_KEY, 'control']} | ${true}
- ${{ experiment: { [TEST_KEY]: { variant: '_variant_name' } } }} | ${[TEST_KEY, '_variant_name']} | ${true}
- ${{ experiment: { [TEST_KEY]: { variant: '_variant_name' } } }} | ${[TEST_KEY, '_bogus_name']} | ${false}
- ${{ experiment: { [TEST_KEY]: { variant: '_variant_name' } } }} | ${['boguskey', '_variant_name']} | ${false}
- ${{}} | ${[TEST_KEY, '_variant_name']} | ${false}
- `('with input=$input and gon=$gon, returns $output', ({ gon, input, output }) => {
- window.gon = gon;
+ describe.each`
+ gon | input | output
+ ${[TEST_KEY, DEFAULT_VARIANT]} | ${[TEST_KEY, DEFAULT_VARIANT]} | ${true}
+ ${[TEST_KEY, '_variant_name']} | ${[TEST_KEY, '_variant_name']} | ${true}
+ ${[TEST_KEY, '_variant_name']} | ${[TEST_KEY, '_bogus_name']} | ${false}
+ ${[TEST_KEY, '_variant_name']} | ${['boguskey', '_variant_name']} | ${false}
+ ${[]} | ${[TEST_KEY, '_variant_name']} | ${false}
+ `('with input=$input and gon=$gon', ({ gon, input, output }) => {
+ assignGitlabExperiment(...gon);
+
+ it(`returns ${output}`, () => {
+ expect(experimentUtils.isExperimentVariant(...input)).toEqual(output);
+ });
+ });
+ });
+
+ describe('experiment', () => {
+ const controlSpy = jest.fn();
+ const candidateSpy = jest.fn();
+ const getUpStandUpSpy = jest.fn();
+
+ const variants = {
+ use: controlSpy,
+ try: candidateSpy,
+ get_up_stand_up: getUpStandUpSpy,
+ };
+
+ describe('when there is no experiment data', () => {
+ it('calls control variant', () => {
+ experimentUtils.experiment('marley', variants);
+ expect(controlSpy).toHaveBeenCalled();
+ });
+ });
+
+ describe('when experiment variant is "control"', () => {
+ assignGitlabExperiment('marley', DEFAULT_VARIANT);
+
+ it('calls the control variant', () => {
+ experimentUtils.experiment('marley', variants);
+ expect(controlSpy).toHaveBeenCalled();
+ });
+ });
+
+ describe('when experiment variant is "candidate"', () => {
+ assignGitlabExperiment('marley', CANDIDATE_VARIANT);
+
+ it('calls the candidate variant', () => {
+ experimentUtils.experiment('marley', variants);
+ expect(candidateSpy).toHaveBeenCalled();
+ });
+ });
+
+ describe('when experiment variant is "get_up_stand_up"', () => {
+ assignGitlabExperiment('marley', 'get_up_stand_up');
- expect(experimentUtils.isExperimentVariant(...input)).toEqual(output);
+ it('calls the get-up-stand-up variant', () => {
+ experimentUtils.experiment('marley', variants);
+ expect(getUpStandUpSpy).toHaveBeenCalled();
+ });
});
});
describe('getExperimentVariant', () => {
it.each`
- gon | input | output
- ${{ experiment: { [TEST_KEY]: { variant: 'control' } } }} | ${[TEST_KEY]} | ${'control'}
- ${{ experiment: { [TEST_KEY]: { variant: 'candidate' } } }} | ${[TEST_KEY]} | ${'candidate'}
- ${{}} | ${[TEST_KEY]} | ${DEFAULT_VARIANT}
+ gon | input | output
+ ${{ experiment: { [TEST_KEY]: { variant: DEFAULT_VARIANT } } }} | ${[TEST_KEY]} | ${DEFAULT_VARIANT}
+ ${{ experiment: { [TEST_KEY]: { variant: CANDIDATE_VARIANT } } }} | ${[TEST_KEY]} | ${CANDIDATE_VARIANT}
+ ${{}} | ${[TEST_KEY]} | ${DEFAULT_VARIANT}
`('with input=$input and gon=$gon, returns $output', ({ gon, input, output }) => {
window.gon = gon;