debian-mirror-gitlab/spec/frontend/experimentation/utils_spec.js
2021-04-17 20:07:23 +05:30

38 lines
1.6 KiB
JavaScript

import * as experimentUtils from '~/experimentation/utils';
const TEST_KEY = 'abc';
describe('experiment Utilities', () => {
const oldGon = window.gon;
afterEach(() => {
window.gon = oldGon;
});
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;
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;
expect(experimentUtils.isExperimentVariant(...input)).toEqual(output);
});
});
});