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;
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
function factory(blob, loading) {
|
2019-12-26 22:10:19 +05:30
|
|
|
$apollo = {
|
2023-04-23 21:23:45 +05:30
|
|
|
queries: {
|
|
|
|
readme: {
|
|
|
|
query: jest.fn().mockReturnValue(Promise.resolve({})),
|
|
|
|
loading,
|
|
|
|
},
|
|
|
|
},
|
2019-12-26 22:10:19 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
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 () => {
|
2023-04-23 21:23:45 +05:30
|
|
|
factory(
|
|
|
|
{
|
|
|
|
webPath: 'http://test.com',
|
|
|
|
name: 'README.md',
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
);
|
2019-12-26 22:10:19 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2022-10-11 01:57:18 +05:30
|
|
|
expect(vm.findComponent(GlLoadingIcon).exists()).toBe(true);
|
2019-12-26 22:10:19 +05:30
|
|
|
});
|
|
|
|
});
|