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

preferences_spec.js « utils « diffs « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b09db2c10030d10a3d08d2cf7cb7f25223fe930b (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
39
import Cookies from 'js-cookie';
import {
  DIFF_FILE_BY_FILE_COOKIE_NAME,
  DIFF_VIEW_FILE_BY_FILE,
  DIFF_VIEW_ALL_FILES,
} from '~/diffs/constants';
import { fileByFile } from '~/diffs/utils/preferences';
import { getParameterValues } from '~/lib/utils/url_utility';

jest.mock('~/lib/utils/url_utility');

describe('diffs preferences', () => {
  describe('fileByFile', () => {
    it.each`
      result   | preference | cookie                    | searchParam
      ${false} | ${false}   | ${undefined}              | ${undefined}
      ${true}  | ${true}    | ${undefined}              | ${undefined}
      ${true}  | ${false}   | ${DIFF_VIEW_FILE_BY_FILE} | ${undefined}
      ${false} | ${true}    | ${DIFF_VIEW_ALL_FILES}    | ${undefined}
      ${true}  | ${false}   | ${undefined}              | ${[DIFF_VIEW_FILE_BY_FILE]}
      ${false} | ${true}    | ${undefined}              | ${[DIFF_VIEW_ALL_FILES]}
      ${true}  | ${false}   | ${DIFF_VIEW_FILE_BY_FILE} | ${[DIFF_VIEW_FILE_BY_FILE]}
      ${true}  | ${true}    | ${DIFF_VIEW_ALL_FILES}    | ${[DIFF_VIEW_FILE_BY_FILE]}
      ${false} | ${false}   | ${DIFF_VIEW_ALL_FILES}    | ${[DIFF_VIEW_ALL_FILES]}
      ${false} | ${true}    | ${DIFF_VIEW_FILE_BY_FILE} | ${[DIFF_VIEW_ALL_FILES]}
    `(
      'should return $result when { preference: $preference, cookie: $cookie, search: $searchParam }',
      ({ result, preference, cookie, searchParam }) => {
        if (cookie) {
          Cookies.set(DIFF_FILE_BY_FILE_COOKIE_NAME, cookie);
        }

        getParameterValues.mockReturnValue(searchParam);

        expect(fileByFile(preference)).toBe(result);
      },
    );
  });
});