debian-mirror-gitlab/spec/frontend/repository/components/preview/index_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

61 lines
1.4 KiB
JavaScript
Raw Normal View History

2019-12-26 22:10:19 +05:30
import { GlLoadingIcon } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { shallowMount } from '@vue/test-utils';
2023-05-27 22:25:52 +05:30
import Vue from 'vue';
import VueApollo from 'vue-apollo';
import createMockApollo from 'helpers/mock_apollo_helper';
2020-03-13 15:44:24 +05:30
import { handleLocationHash } from '~/lib/utils/common_utils';
2023-05-27 22:25:52 +05:30
import waitForPromises from 'helpers/wait_for_promises';
2019-12-26 22:10:19 +05:30
import Preview from '~/repository/components/preview/index.vue';
2023-05-27 22:25:52 +05:30
const PROPS_DATA = {
blob: {
webPath: 'http://test.com',
name: 'README.md',
},
};
const MOCK_README_DATA = {
__typename: 'ReadmeFile',
html: '<div class="blob">test</div>',
};
2020-03-13 15:44:24 +05:30
jest.mock('~/lib/utils/common_utils');
2023-05-27 22:25:52 +05:30
Vue.use(VueApollo);
let wrapper;
let mockApollo;
let mockReadmeData;
2019-12-26 22:10:19 +05:30
2023-05-27 22:25:52 +05:30
const mockResolvers = {
Query: {
readme: () => mockReadmeData(),
},
};
2019-12-26 22:10:19 +05:30
2023-05-27 22:25:52 +05:30
function createComponent() {
mockApollo = createMockApollo([], mockResolvers);
return shallowMount(Preview, {
propsData: PROPS_DATA,
apolloProvider: mockApollo,
2019-12-26 22:10:19 +05:30
});
}
describe('Repository file preview component', () => {
2023-05-27 22:25:52 +05:30
beforeEach(() => {
mockReadmeData = jest.fn();
wrapper = createComponent();
mockReadmeData.mockResolvedValue(MOCK_README_DATA);
2020-03-13 15:44:24 +05:30
});
2022-04-04 11:22:00 +05:30
it('handles hash after render', async () => {
2023-05-27 22:25:52 +05:30
await waitForPromises();
2022-04-04 11:22:00 +05:30
expect(handleLocationHash).toHaveBeenCalled();
2019-12-26 22:10:19 +05:30
});
2023-06-20 00:43:36 +05:30
it('renders loading icon', () => {
2023-05-27 22:25:52 +05:30
expect(wrapper.findComponent(GlLoadingIcon).exists()).toBe(true);
2019-12-26 22:10:19 +05:30
});
});