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';
|
2022-04-04 11:22:00 +05:30
|
|
|
import { nextTick } from 'vue';
|
2020-03-13 15:44:24 +05:30
|
|
|
import { handleLocationHash } from '~/lib/utils/common_utils';
|
2019-12-26 22:10:19 +05:30
|
|
|
import Preview from '~/repository/components/preview/index.vue';
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
jest.mock('~/lib/utils/common_utils');
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('renders file HTML', async () => {
|
2019-12-26 22:10:19 +05:30
|
|
|
factory({
|
2020-10-24 23:57:45 +05:30
|
|
|
webPath: 'http://test.com',
|
2019-12-26 22:10:19 +05:30
|
|
|
name: 'README.md',
|
|
|
|
});
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
|
|
|
|
// eslint-disable-next-line no-restricted-syntax
|
2019-12-26 22:10:19 +05:30
|
|
|
vm.setData({ readme: { html: '<div class="blob">test</div>' } });
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
|
|
|
expect(vm.element).toMatchSnapshot();
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('handles hash after render', async () => {
|
2020-03-13 15:44:24 +05:30
|
|
|
factory({
|
2020-10-24 23:57:45 +05:30
|
|
|
webPath: 'http://test.com',
|
2020-03-13 15:44:24 +05:30
|
|
|
name: 'README.md',
|
|
|
|
});
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
|
|
|
|
// eslint-disable-next-line no-restricted-syntax
|
2020-03-13 15:44:24 +05:30
|
|
|
vm.setData({ readme: { html: '<div class="blob">test</div>' } });
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
|
|
|
expect(handleLocationHash).toHaveBeenCalled();
|
2019-12-26 22:10:19 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('renders loading icon', async () => {
|
2019-12-26 22:10:19 +05:30
|
|
|
factory({
|
2020-10-24 23:57:45 +05:30
|
|
|
webPath: 'http://test.com',
|
2019-12-26 22:10:19 +05:30
|
|
|
name: 'README.md',
|
|
|
|
});
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
|
|
|
|
// eslint-disable-next-line no-restricted-syntax
|
2019-12-26 22:10:19 +05:30
|
|
|
vm.setData({ loading: 1 });
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
|
|
|
expect(vm.find(GlLoadingIcon).exists()).toBe(true);
|
2019-12-26 22:10:19 +05:30
|
|
|
});
|
|
|
|
});
|