Commit 5d99898e authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Merge branch 'update-fe-experiment-util-function' into 'master'

Allow "control" and "candidate" function names

See merge request gitlab-org/gitlab!73718
parents 6edb1769 5fc702af
......@@ -26,14 +26,14 @@ export function getExperimentVariant(experimentName) {
return getExperimentData(experimentName)?.variant || DEFAULT_VARIANT;
}
export function experiment(experimentName, variants) {
export function experiment(experimentName, { use, control, candidate, ...variants }) {
const variant = getExperimentVariant(experimentName);
switch (variant) {
case DEFAULT_VARIANT:
return variants.use.call();
return (use || control).call();
case CANDIDATE_VARIANT:
return variants.try.call();
return (variants.try || candidate).call();
default:
return variants[variant].call();
}
......
......@@ -85,20 +85,22 @@ describe('experiment Utilities', () => {
});
describe('experiment', () => {
const useSpy = jest.fn();
const controlSpy = jest.fn();
const trySpy = jest.fn();
const candidateSpy = jest.fn();
const getUpStandUpSpy = jest.fn();
const variants = {
use: controlSpy,
try: candidateSpy,
use: useSpy,
try: trySpy,
get_up_stand_up: getUpStandUpSpy,
};
describe('when there is no experiment data', () => {
it('calls control variant', () => {
experimentUtils.experiment('marley', variants);
expect(controlSpy).toHaveBeenCalled();
expect(useSpy).toHaveBeenCalled();
});
});
......@@ -107,7 +109,14 @@ describe('experiment Utilities', () => {
it('calls the control variant', () => {
experimentUtils.experiment('marley', variants);
expect(controlSpy).toHaveBeenCalled();
expect(useSpy).toHaveBeenCalled();
});
describe("when 'control' is provided instead of 'use'", () => {
it('calls the control variant', () => {
experimentUtils.experiment('marley', { control: controlSpy });
expect(controlSpy).toHaveBeenCalled();
});
});
});
......@@ -116,7 +125,14 @@ describe('experiment Utilities', () => {
it('calls the candidate variant', () => {
experimentUtils.experiment('marley', variants);
expect(candidateSpy).toHaveBeenCalled();
expect(trySpy).toHaveBeenCalled();
});
describe("when 'candidate' is provided instead of 'try'", () => {
it('calls the control variant', () => {
experimentUtils.experiment('marley', { candidate: candidateSpy });
expect(candidateSpy).toHaveBeenCalled();
});
});
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment