2020-03-13 15:44:24 +05:30
|
|
|
import { shallowMount, mount } from '@vue/test-utils';
|
|
|
|
import BlobHeader from '~/blob/components/blob_header.vue';
|
|
|
|
import DefaultActions from '~/blob/components/blob_header_default_actions.vue';
|
|
|
|
import BlobFilepath from '~/blob/components/blob_header_filepath.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import ViewerSwitcher from '~/blob/components/blob_header_viewer_switcher.vue';
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
import { Blob } from './mock_data';
|
|
|
|
|
|
|
|
describe('Blob Header Default Actions', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
function createComponent(blobProps = {}, options = {}, propsData = {}, shouldMount = false) {
|
|
|
|
const method = shouldMount ? mount : shallowMount;
|
2021-01-29 00:20:46 +05:30
|
|
|
const blobHash = 'foo-bar';
|
2020-03-13 15:44:24 +05:30
|
|
|
wrapper = method.call(this, BlobHeader, {
|
2021-01-29 00:20:46 +05:30
|
|
|
provide: {
|
|
|
|
blobHash,
|
|
|
|
},
|
2020-03-13 15:44:24 +05:30
|
|
|
propsData: {
|
2020-05-24 23:13:21 +05:30
|
|
|
blob: { ...Blob, ...blobProps },
|
2020-03-13 15:44:24 +05:30
|
|
|
...propsData,
|
|
|
|
},
|
|
|
|
...options,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('rendering', () => {
|
2021-10-27 15:23:28 +05:30
|
|
|
const findDefaultActions = () => wrapper.find(DefaultActions);
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
const slots = {
|
|
|
|
prepend: 'Foo Prepend',
|
|
|
|
actions: 'Actions Bar',
|
|
|
|
};
|
|
|
|
|
|
|
|
it('matches the snapshot', () => {
|
|
|
|
createComponent();
|
|
|
|
expect(wrapper.element).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders all components', () => {
|
|
|
|
createComponent();
|
|
|
|
expect(wrapper.find(ViewerSwitcher).exists()).toBe(true);
|
2021-10-27 15:23:28 +05:30
|
|
|
expect(findDefaultActions().exists()).toBe(true);
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(wrapper.find(BlobFilepath).exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render viewer switcher if the blob has only the simple viewer', () => {
|
|
|
|
createComponent({
|
|
|
|
richViewer: null,
|
|
|
|
});
|
|
|
|
expect(wrapper.find(ViewerSwitcher).exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render viewer switcher if a corresponding prop is passed', () => {
|
|
|
|
createComponent(
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
hideViewerSwitcher: true,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
expect(wrapper.find(ViewerSwitcher).exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render default actions is corresponding prop is passed', () => {
|
|
|
|
createComponent(
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
hideDefaultActions: true,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
expect(wrapper.find(DefaultActions).exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
Object.keys(slots).forEach((slot) => {
|
2020-03-13 15:44:24 +05:30
|
|
|
it('renders the slots', () => {
|
|
|
|
const slotContent = slots[slot];
|
|
|
|
createComponent(
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
scopedSlots: {
|
|
|
|
[slot]: `<span>${slotContent}</span>`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
expect(wrapper.text()).toContain(slotContent);
|
|
|
|
});
|
|
|
|
});
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
it('passes information about render error down to default actions', () => {
|
|
|
|
createComponent(
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
hasRenderError: true,
|
|
|
|
},
|
|
|
|
);
|
2021-10-27 15:23:28 +05:30
|
|
|
expect(findDefaultActions().props('hasRenderError')).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('passes the correct isBinary value to default actions when viewing a binary file', () => {
|
|
|
|
createComponent({}, {}, { isBinary: true });
|
|
|
|
|
|
|
|
expect(findDefaultActions().props('isBinary')).toBe(true);
|
2020-06-23 00:09:42 +05:30
|
|
|
});
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('functionality', () => {
|
|
|
|
const newViewer = 'Foo Bar';
|
|
|
|
const activeViewerType = 'Alpha Beta';
|
|
|
|
|
|
|
|
const factory = (hideViewerSwitcher = false) => {
|
|
|
|
createComponent(
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
activeViewerType,
|
|
|
|
hideViewerSwitcher,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
it('by default sets viewer data based on activeViewerType', () => {
|
|
|
|
factory();
|
|
|
|
expect(wrapper.vm.viewer).toBe(activeViewerType);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets viewer to null if the viewer switcher should be hidden', () => {
|
|
|
|
factory(true);
|
|
|
|
expect(wrapper.vm.viewer).toBe(null);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('watches the changes in viewer data and emits event when the change is registered', () => {
|
|
|
|
factory();
|
|
|
|
jest.spyOn(wrapper.vm, '$emit');
|
|
|
|
wrapper.vm.viewer = newViewer;
|
|
|
|
|
|
|
|
return wrapper.vm.$nextTick().then(() => {
|
|
|
|
expect(wrapper.vm.$emit).toHaveBeenCalledWith('viewer-changed', newViewer);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not emit event if the switcher is not rendered', () => {
|
|
|
|
factory(true);
|
|
|
|
|
|
|
|
expect(wrapper.vm.showViewerSwitcher).toBe(false);
|
|
|
|
jest.spyOn(wrapper.vm, '$emit');
|
|
|
|
wrapper.vm.viewer = newViewer;
|
|
|
|
|
|
|
|
return wrapper.vm.$nextTick().then(() => {
|
|
|
|
expect(wrapper.vm.$emit).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|