2019-12-26 22:10:19 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import { GlLoadingIcon } from '@gitlab/ui';
|
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();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders file HTML', () => {
|
|
|
|
factory({
|
2020-10-24 23:57:45 +05:30
|
|
|
webPath: 'http://test.com',
|
2019-12-26 22:10:19 +05:30
|
|
|
name: 'README.md',
|
|
|
|
});
|
|
|
|
|
|
|
|
vm.setData({ readme: { html: '<div class="blob">test</div>' } });
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
return vm.vm.$nextTick(() => {
|
|
|
|
expect(vm.element).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('handles hash after render', () => {
|
|
|
|
factory({
|
2020-10-24 23:57:45 +05:30
|
|
|
webPath: 'http://test.com',
|
2020-03-13 15:44:24 +05:30
|
|
|
name: 'README.md',
|
|
|
|
});
|
|
|
|
|
|
|
|
vm.setData({ readme: { html: '<div class="blob">test</div>' } });
|
|
|
|
|
|
|
|
return vm.vm
|
|
|
|
.$nextTick()
|
|
|
|
.then(vm.vm.$nextTick())
|
|
|
|
.then(() => {
|
|
|
|
expect(handleLocationHash).toHaveBeenCalled();
|
|
|
|
});
|
2019-12-26 22:10:19 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders loading icon', () => {
|
|
|
|
factory({
|
2020-10-24 23:57:45 +05:30
|
|
|
webPath: 'http://test.com',
|
2019-12-26 22:10:19 +05:30
|
|
|
name: 'README.md',
|
|
|
|
});
|
|
|
|
|
|
|
|
vm.setData({ loading: 1 });
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
return vm.vm.$nextTick(() => {
|
|
|
|
expect(vm.find(GlLoadingIcon).exists()).toBe(true);
|
|
|
|
});
|
2019-12-26 22:10:19 +05:30
|
|
|
});
|
|
|
|
});
|