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

index_spec.js « preview « components « repository « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0d9bfc62ed53f5583f76305c743d34b16032e14a (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 { GlLoadingIcon } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { nextTick } from 'vue';
import { handleLocationHash } from '~/lib/utils/common_utils';
import Preview from '~/repository/components/preview/index.vue';

jest.mock('~/lib/utils/common_utils');

let vm;
let $apollo;

function factory(blob) {
  $apollo = {
    query: jest.fn().mockReturnValue(Promise.resolve({})),
  };

  vm = shallowMount(Preview, {
    propsData: {
      blob,
    },
    mocks: {
      $apollo,
    },
  });
}

describe('Repository file preview component', () => {
  afterEach(() => {
    vm.destroy();
  });

  it('renders file HTML', async () => {
    factory({
      webPath: 'http://test.com',
      name: 'README.md',
    });

    // setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
    // eslint-disable-next-line no-restricted-syntax
    vm.setData({ readme: { html: '<div class="blob">test</div>' } });

    await nextTick();
    expect(vm.element).toMatchSnapshot();
  });

  it('handles hash after render', async () => {
    factory({
      webPath: 'http://test.com',
      name: 'README.md',
    });

    // setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
    // eslint-disable-next-line no-restricted-syntax
    vm.setData({ readme: { html: '<div class="blob">test</div>' } });

    await nextTick();
    expect(handleLocationHash).toHaveBeenCalled();
  });

  it('renders loading icon', async () => {
    factory({
      webPath: 'http://test.com',
      name: 'README.md',
    });

    // setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
    // eslint-disable-next-line no-restricted-syntax
    vm.setData({ loading: 1 });

    await nextTick();
    expect(vm.find(GlLoadingIcon).exists()).toBe(true);
  });
});