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

project_form_group_spec.js « components « confidential_merge_request « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 975701ebd9635851051cfba83eb8f8ccb9c4337f (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { shallowMount } from '@vue/test-utils';
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
import ProjectFormGroup from '~/confidential_merge_request/components/project_form_group.vue';

const mockData = [
  {
    id: 1,
    name_with_namespace: 'root / gitlab-ce',
    path_with_namespace: 'root/gitlab-ce',
    namespace: {
      full_path: 'root',
    },
  },
  {
    id: 2,
    name_with_namespace: 'test / gitlab-ce',
    path_with_namespace: 'test/gitlab-ce',
    namespace: {
      full_path: 'test',
    },
  },
];
let vm;
let mock;

function factory(projects = mockData) {
  mock = new MockAdapter(axios);
  mock.onGet(/api\/(.*)\/projects\/gitlab-org%2Fgitlab-ce\/forks/).reply(200, projects);

  vm = shallowMount(ProjectFormGroup, {
    propsData: {
      namespacePath: 'gitlab-org',
      projectPath: 'gitlab-org/gitlab-ce',
      newForkPath: 'https://test.com',
      helpPagePath: '/help',
    },
  });
}

describe('Confidential merge request project form group component', () => {
  afterEach(() => {
    mock.restore();
    vm.destroy();
  });

  it('renders fork dropdown', () => {
    factory();

    return vm.vm.$nextTick(() => {
      expect(vm.element).toMatchSnapshot();
    });
  });

  it('sets selected project as first fork', () => {
    factory();

    return vm.vm.$nextTick(() => {
      expect(vm.vm.selectedProject).toEqual({
        id: 1,
        name: 'root / gitlab-ce',
        pathWithNamespace: 'root/gitlab-ce',
        namespaceFullpath: 'root',
      });
    });
  });

  it('renders empty state when response is empty', () => {
    factory([]);

    return vm.vm.$nextTick(() => {
      expect(vm.element).toMatchSnapshot();
    });
  });
});