2020-10-24 23:57:45 +05:30
|
|
|
import { GlLoadingIcon } from '@gitlab/ui';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2020-03-13 15:44:24 +05:30
|
|
|
import BlobContent from '~/blob/components/blob_content.vue';
|
|
|
|
import BlobContentError from '~/blob/components/blob_content_error.vue';
|
|
|
|
import {
|
2020-05-24 23:13:21 +05:30
|
|
|
BLOB_RENDER_EVENT_LOAD,
|
|
|
|
BLOB_RENDER_EVENT_SHOW_SOURCE,
|
|
|
|
BLOB_RENDER_ERRORS,
|
|
|
|
} from '~/blob/components/constants';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { RichViewer, SimpleViewer } from '~/vue_shared/components/blob_viewers';
|
2020-05-24 23:13:21 +05:30
|
|
|
import {
|
|
|
|
Blob,
|
2020-03-13 15:44:24 +05:30
|
|
|
RichViewerMock,
|
|
|
|
SimpleViewerMock,
|
|
|
|
RichBlobContentMock,
|
|
|
|
SimpleBlobContentMock,
|
|
|
|
} from './mock_data';
|
|
|
|
|
|
|
|
describe('Blob Content component', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
function createComponent(propsData = {}, activeViewer = SimpleViewerMock) {
|
|
|
|
wrapper = shallowMount(BlobContent, {
|
|
|
|
propsData: {
|
|
|
|
loading: false,
|
|
|
|
activeViewer,
|
|
|
|
...propsData,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('rendering', () => {
|
|
|
|
it('renders loader if `loading: true`', () => {
|
|
|
|
createComponent({ loading: true });
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(wrapper.findComponent(GlLoadingIcon).exists()).toBe(true);
|
|
|
|
expect(wrapper.findComponent(BlobContentError).exists()).toBe(false);
|
|
|
|
expect(wrapper.findComponent(RichViewer).exists()).toBe(false);
|
|
|
|
expect(wrapper.findComponent(SimpleViewer).exists()).toBe(false);
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders error if there is any in the viewer', () => {
|
|
|
|
const renderError = 'Oops';
|
2020-05-24 23:13:21 +05:30
|
|
|
const viewer = { ...SimpleViewerMock, renderError };
|
2020-03-13 15:44:24 +05:30
|
|
|
createComponent({}, viewer);
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(wrapper.findComponent(GlLoadingIcon).exists()).toBe(false);
|
|
|
|
expect(wrapper.findComponent(BlobContentError).exists()).toBe(true);
|
|
|
|
expect(wrapper.findComponent(RichViewer).exists()).toBe(false);
|
|
|
|
expect(wrapper.findComponent(SimpleViewer).exists()).toBe(false);
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it.each`
|
|
|
|
type | mock | viewer
|
|
|
|
${'simple'} | ${SimpleViewerMock} | ${SimpleViewer}
|
|
|
|
${'rich'} | ${RichViewerMock} | ${RichViewer}
|
|
|
|
`(
|
|
|
|
'renders $type viewer when activeViewer is $type and no loading or error detected',
|
|
|
|
({ mock, viewer }) => {
|
|
|
|
createComponent({}, mock);
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(wrapper.findComponent(viewer).exists()).toBe(true);
|
2020-03-13 15:44:24 +05:30
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
it.each`
|
|
|
|
content | mock | viewer
|
|
|
|
${SimpleBlobContentMock.plainData} | ${SimpleViewerMock} | ${SimpleViewer}
|
|
|
|
${RichBlobContentMock.richData} | ${RichViewerMock} | ${RichViewer}
|
|
|
|
`('renders correct content that is passed to the component', ({ content, mock, viewer }) => {
|
|
|
|
createComponent({ content }, mock);
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(wrapper.findComponent(viewer).html()).toContain(content);
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
|
|
|
});
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
describe('functionality', () => {
|
|
|
|
describe('render error', () => {
|
2022-08-27 11:52:29 +05:30
|
|
|
const findErrorEl = () => wrapper.findComponent(BlobContentError);
|
2020-05-24 23:13:21 +05:30
|
|
|
const renderError = BLOB_RENDER_ERRORS.REASONS.COLLAPSED.id;
|
|
|
|
const viewer = { ...SimpleViewerMock, renderError };
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({ blob: Blob }, viewer);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('correctly sets blob on the blob-content-error component', () => {
|
|
|
|
expect(findErrorEl().props('blob')).toEqual(Blob);
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`properly proxies ${BLOB_RENDER_EVENT_LOAD} event`, () => {
|
|
|
|
expect(wrapper.emitted(BLOB_RENDER_EVENT_LOAD)).toBeUndefined();
|
|
|
|
findErrorEl().vm.$emit(BLOB_RENDER_EVENT_LOAD);
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(wrapper.emitted(BLOB_RENDER_EVENT_LOAD)).toHaveLength(1);
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it(`properly proxies ${BLOB_RENDER_EVENT_SHOW_SOURCE} event`, () => {
|
|
|
|
expect(wrapper.emitted(BLOB_RENDER_EVENT_SHOW_SOURCE)).toBeUndefined();
|
|
|
|
findErrorEl().vm.$emit(BLOB_RENDER_EVENT_SHOW_SOURCE);
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(wrapper.emitted(BLOB_RENDER_EVENT_SHOW_SOURCE)).toHaveLength(1);
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|