2021-12-22 10:14:10 -05:00
|
|
|
import { GlBadge } from '@gitlab/ui';
|
2020-02-06 19:09:12 -05:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import BlobHeaderFilepath from '~/blob/components/blob_header_filepath.vue';
|
|
|
|
import { numberToHumanSize } from '~/lib/utils/number_utils';
|
2021-02-14 13:09:20 -05:00
|
|
|
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
|
2021-02-01 10:08:56 -05:00
|
|
|
import { Blob as MockBlob } from './mock_data';
|
2020-02-06 19:09:12 -05:00
|
|
|
|
|
|
|
jest.mock('~/lib/utils/number_utils', () => ({
|
2020-05-27 08:08:19 -04:00
|
|
|
numberToHumanSize: jest.fn(() => 'a lot'),
|
2020-02-06 19:09:12 -05:00
|
|
|
}));
|
|
|
|
|
|
|
|
describe('Blob Header Filepath', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
function createComponent(blobProps = {}, options = {}) {
|
|
|
|
wrapper = shallowMount(BlobHeaderFilepath, {
|
|
|
|
propsData: {
|
2020-05-07 17:09:26 -04:00
|
|
|
blob: { ...MockBlob, ...blobProps },
|
2020-02-06 19:09:12 -05:00
|
|
|
},
|
|
|
|
...options,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
2022-08-11 17:09:14 -04:00
|
|
|
const findBadge = () => wrapper.findComponent(GlBadge);
|
2021-12-22 10:14:10 -05:00
|
|
|
|
2020-02-06 19:09:12 -05:00
|
|
|
describe('rendering', () => {
|
|
|
|
it('matches the snapshot', () => {
|
|
|
|
createComponent();
|
|
|
|
expect(wrapper.element).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders regular name', () => {
|
|
|
|
createComponent();
|
2020-12-23 07:10:26 -05:00
|
|
|
expect(wrapper.find('.js-blob-header-filepath').text().trim()).toBe(MockBlob.path);
|
2020-02-06 19:09:12 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('does not fail if the name is empty', () => {
|
2020-04-29 17:09:31 -04:00
|
|
|
const emptyPath = '';
|
|
|
|
createComponent({ path: emptyPath });
|
2020-02-06 19:09:12 -05:00
|
|
|
expect(wrapper.find('.js-blob-header-filepath').exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders copy-to-clipboard icon that copies path of the Blob', () => {
|
|
|
|
createComponent();
|
2022-08-11 17:09:14 -04:00
|
|
|
const btn = wrapper.findComponent(ClipboardButton);
|
2020-02-06 19:09:12 -05:00
|
|
|
expect(btn.exists()).toBe(true);
|
|
|
|
expect(btn.vm.text).toBe(MockBlob.path);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders filesize in a human-friendly format', () => {
|
|
|
|
createComponent();
|
|
|
|
expect(numberToHumanSize).toHaveBeenCalled();
|
2020-05-27 08:08:19 -04:00
|
|
|
expect(wrapper.vm.blobSize).toBe('a lot');
|
2020-02-06 19:09:12 -05:00
|
|
|
});
|
|
|
|
|
2021-12-22 10:14:10 -05:00
|
|
|
it('renders LFS badge if LFS if enabled', () => {
|
|
|
|
createComponent({ storedExternally: true, externalStorage: 'lfs' });
|
|
|
|
expect(findBadge().text()).toBe('LFS');
|
|
|
|
});
|
|
|
|
|
2020-02-06 19:09:12 -05:00
|
|
|
it('renders a slot and prepends its contents to the existing one', () => {
|
|
|
|
const slotContent = 'Foo Bar';
|
|
|
|
createComponent(
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
scopedSlots: {
|
2020-11-13 16:09:31 -05:00
|
|
|
'filepath-prepend': `<span>${slotContent}</span>`,
|
2020-02-06 19:09:12 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(wrapper.text()).toContain(slotContent);
|
2020-12-23 07:10:26 -05:00
|
|
|
expect(wrapper.text().trim().substring(0, slotContent.length)).toBe(slotContent);
|
2020-02-06 19:09:12 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('functionality', () => {
|
|
|
|
it('sets gfm value correctly on the clipboard-button', () => {
|
|
|
|
createComponent();
|
2020-04-29 17:09:31 -04:00
|
|
|
expect(wrapper.vm.gfmCopyText).toBe(`\`${MockBlob.path}\``);
|
2020-02-06 19:09:12 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|