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
|
import { GlLoadingIcon } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import Vue from 'vue';
import VueApollo from 'vue-apollo';
import createMockApollo from 'helpers/mock_apollo_helper';
import { handleLocationHash } from '~/lib/utils/common_utils';
import waitForPromises from 'helpers/wait_for_promises';
import Preview from '~/repository/components/preview/index.vue';
const PROPS_DATA = {
blob: {
webPath: 'http://test.com',
name: 'README.md',
},
};
const MOCK_README_DATA = {
__typename: 'ReadmeFile',
html: '<div class="blob">test</div>',
};
jest.mock('~/lib/utils/common_utils');
Vue.use(VueApollo);
let wrapper;
let mockApollo;
let mockReadmeData;
const mockResolvers = {
Query: {
readme: () => mockReadmeData(),
},
};
function createComponent() {
mockApollo = createMockApollo([], mockResolvers);
return shallowMount(Preview, {
propsData: PROPS_DATA,
apolloProvider: mockApollo,
});
}
describe('Repository file preview component', () => {
beforeEach(() => {
mockReadmeData = jest.fn();
wrapper = createComponent();
mockReadmeData.mockResolvedValue(MOCK_README_DATA);
});
afterEach(() => {
wrapper.destroy();
});
it('handles hash after render', async () => {
await waitForPromises();
expect(handleLocationHash).toHaveBeenCalled();
});
it('renders loading icon', async () => {
expect(wrapper.findComponent(GlLoadingIcon).exists()).toBe(true);
});
});
|