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

provider_repo_table_row_spec.js « components « import_projects « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 02c786d8d0bba79b5e9aec55dbb9124aa4dd57f3 (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import Vuex from 'vuex';
import { createLocalVue, mount } from '@vue/test-utils';
import { state, actions, getters, mutations } from '~/import_projects/store';
import providerRepoTableRow from '~/import_projects/components/provider_repo_table_row.vue';
import STATUS_MAP, { STATUSES } from '~/import_projects/constants';

describe('ProviderRepoTableRow', () => {
  let vm;
  const fetchImport = jest.fn((context, data) => actions.requestImport(context, data));
  const importPath = '/import-path';
  const defaultTargetNamespace = 'user';
  const ciCdOnly = true;
  const repo = {
    id: 10,
    sanitizedName: 'sanitizedName',
    fullName: 'fullName',
    providerLink: 'providerLink',
  };

  function initStore() {
    const stubbedActions = Object.assign({}, actions, {
      fetchImport,
    });

    const store = new Vuex.Store({
      state: state(),
      actions: stubbedActions,
      mutations,
      getters,
    });

    return store;
  }

  function mountComponent() {
    const localVue = createLocalVue();
    localVue.use(Vuex);

    const store = initStore();
    store.dispatch('setInitialData', { importPath, defaultTargetNamespace, ciCdOnly });

    const component = mount(providerRepoTableRow, {
      localVue,
      store,
      propsData: {
        repo,
      },
      sync: false,
    });

    return component.vm;
  }

  beforeEach(() => {
    vm = mountComponent();
  });

  afterEach(() => {
    vm.$destroy();
  });

  it('renders a provider repo table row', () => {
    const providerLink = vm.$el.querySelector('.js-provider-link');
    const statusObject = STATUS_MAP[STATUSES.NONE];

    expect(vm.$el.classList.contains('js-provider-repo')).toBe(true);
    expect(providerLink.href).toMatch(repo.providerLink);
    expect(providerLink.textContent).toMatch(repo.fullName);
    expect(vm.$el.querySelector(`.${statusObject.textClass}`).textContent).toMatch(
      statusObject.text,
    );

    expect(vm.$el.querySelector(`.ic-status_${statusObject.icon}`)).not.toBeNull();
    expect(vm.$el.querySelector('.js-import-button')).not.toBeNull();
  });

  it('renders a select2 namespace select', () => {
    const dropdownTrigger = vm.$el.querySelector('.js-namespace-select');

    expect(dropdownTrigger).not.toBeNull();
    expect(dropdownTrigger.classList.contains('select2-container')).toBe(true);

    dropdownTrigger.click();

    expect(vm.$el.querySelector('.select2-drop')).not.toBeNull();
  });

  it('imports repo when clicking import button', () => {
    vm.$el.querySelector('.js-import-button').click();

    return vm.$nextTick().then(() => {
      const { calls } = fetchImport.mock;

      // Not using .toBeCalledWith because it expects
      // an unmatchable and undefined 3rd argument.
      expect(calls.length).toBe(1);
      expect(calls[0][1]).toEqual({
        repo,
        newName: repo.sanitizedName,
        targetNamespace: defaultTargetNamespace,
      });
    });
  });
});