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

utils_spec.js « settings « projects « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d85f43778b1f1665a9ffb5d5cb13b1addd860084 (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
import { getAccessLevels, generateRefDestinationPath } from '~/projects/settings/utils';
import setWindowLocation from 'helpers/set_window_location_helper';
import { pushAccessLevelsMockResponse, pushAccessLevelsMockResult } from './mock_data';

describe('Utils', () => {
  describe('getAccessLevels', () => {
    it('takes accessLevels response data and returns acecssLevels object', () => {
      const pushAccessLevels = getAccessLevels(pushAccessLevelsMockResponse);
      expect(pushAccessLevels).toEqual(pushAccessLevelsMockResult);
    });
  });

  describe('generateRefDestinationPath', () => {
    const projectRootPath = 'http://test.host/root/Project1';
    const settingsCi = '-/settings/ci_cd';

    it.each`
      currentPath                           | selectedRef             | result
      ${`${projectRootPath}`}               | ${undefined}            | ${`${projectRootPath}`}
      ${`${projectRootPath}`}               | ${'test'}               | ${`${projectRootPath}`}
      ${`${projectRootPath}/${settingsCi}`} | ${'test'}               | ${`${projectRootPath}/${settingsCi}?ref=test`}
      ${`${projectRootPath}/${settingsCi}`} | ${'branch-hyphen'}      | ${`${projectRootPath}/${settingsCi}?ref=branch-hyphen`}
      ${`${projectRootPath}/${settingsCi}`} | ${'test/branch'}        | ${`${projectRootPath}/${settingsCi}?ref=test%2Fbranch`}
      ${`${projectRootPath}/${settingsCi}`} | ${'test/branch-hyphen'} | ${`${projectRootPath}/${settingsCi}?ref=test%2Fbranch-hyphen`}
    `(
      'generates the correct destination path for the `$selectedRef` ref and current url $currentPath by outputting $result',
      ({ currentPath, selectedRef, result }) => {
        setWindowLocation(currentPath);
        expect(generateRefDestinationPath(selectedRef)).toBe(result);
      },
    );
  });
});