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

utils_spec.js « experimentation « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 87dd2d595ba5834739a844011a11f1561d36ba17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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);
    });
  });
});