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: 0e73d50fdb56e0977ba2a9726f2ff1e9f7bda4f0 (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
import { GlSprintf } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import MockAdapter from 'axios-mock-adapter';
import ProjectFormGroup from '~/confidential_merge_request/components/project_form_group.vue';
import axios from '~/lib/utils/axios_utils';

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 wrapper;
let mock;

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

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

  return axios.waitForAll();
}

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

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

    expect(wrapper.element).toMatchSnapshot();
  });

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

    expect(wrapper.vm.selectedProject).toEqual({
      id: 1,
      name: 'root / gitlab-ce',
      pathWithNamespace: 'root/gitlab-ce',
      namespaceFullpath: 'root',
    });
  });

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

    expect(wrapper.element).toMatchSnapshot();
  });
});