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

import_error_details_spec.js « components « history « import « pages « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4ff3f0361cf4b320833e72ed41013ae0d8399369 (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
import { GlLoadingIcon } from '@gitlab/ui';
import { mount, shallowMount } from '@vue/test-utils';
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
import ImportErrorDetails from '~/pages/import/history/components/import_error_details.vue';

describe('ImportErrorDetails', () => {
  const FAKE_ID = 5;
  const API_URL = `/api/v4/projects/${FAKE_ID}`;

  let wrapper;
  let mock;

  function createComponent({ shallow = true } = {}) {
    const mountFn = shallow ? shallowMount : mount;
    wrapper = mountFn(ImportErrorDetails, {
      propsData: {
        id: FAKE_ID,
      },
    });
  }

  const originalApiVersion = gon.api_version;
  beforeAll(() => {
    gon.api_version = 'v4';
  });

  afterAll(() => {
    gon.api_version = originalApiVersion;
  });

  beforeEach(() => {
    mock = new MockAdapter(axios);
  });

  afterEach(() => {
    mock.restore();
    wrapper.destroy();
  });

  describe('general behavior', () => {
    it('renders loading state when loading', () => {
      createComponent();
      expect(wrapper.find(GlLoadingIcon).exists()).toBe(true);
    });

    it('renders import_error if it is available', async () => {
      const FAKE_IMPORT_ERROR = 'IMPORT ERROR';
      mock.onGet(API_URL).reply(200, { import_error: FAKE_IMPORT_ERROR });
      createComponent();
      await axios.waitForAll();

      expect(wrapper.find(GlLoadingIcon).exists()).toBe(false);
      expect(wrapper.find('pre').text()).toBe(FAKE_IMPORT_ERROR);
    });

    it('renders default text if error is not available', async () => {
      mock.onGet(API_URL).reply(200, { import_error: null });
      createComponent();
      await axios.waitForAll();

      expect(wrapper.find(GlLoadingIcon).exists()).toBe(false);
      expect(wrapper.find('pre').text()).toBe('No additional information provided.');
    });
  });
});