debian-mirror-gitlab/spec/frontend/blob/components/blob_header_filepath_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

88 lines
2.6 KiB
JavaScript
Raw Normal View History

2022-03-02 08:16:31 +05:30
import { GlBadge } from '@gitlab/ui';
2020-03-13 15:44:24 +05:30
import { shallowMount } from '@vue/test-utils';
import BlobHeaderFilepath from '~/blob/components/blob_header_filepath.vue';
2021-03-11 19:13:27 +05:30
import { numberToHumanSize } from '~/lib/utils/number_utils';
2020-03-13 15:44:24 +05:30
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
import { Blob as MockBlob } from './mock_data';
jest.mock('~/lib/utils/number_utils', () => ({
2020-06-23 00:09:42 +05:30
numberToHumanSize: jest.fn(() => 'a lot'),
2020-03-13 15:44:24 +05:30
}));
describe('Blob Header Filepath', () => {
let wrapper;
function createComponent(blobProps = {}, options = {}) {
wrapper = shallowMount(BlobHeaderFilepath, {
propsData: {
2020-05-24 23:13:21 +05:30
blob: { ...MockBlob, ...blobProps },
2020-03-13 15:44:24 +05:30
},
...options,
});
}
afterEach(() => {
wrapper.destroy();
});
2022-08-27 11:52:29 +05:30
const findBadge = () => wrapper.findComponent(GlBadge);
2022-03-02 08:16:31 +05:30
2020-03-13 15:44:24 +05:30
describe('rendering', () => {
it('matches the snapshot', () => {
createComponent();
expect(wrapper.element).toMatchSnapshot();
});
it('renders regular name', () => {
createComponent();
2021-03-08 18:12:59 +05:30
expect(wrapper.find('.js-blob-header-filepath').text().trim()).toBe(MockBlob.path);
2020-03-13 15:44:24 +05:30
});
it('does not fail if the name is empty', () => {
2020-05-24 23:13:21 +05:30
const emptyPath = '';
createComponent({ path: emptyPath });
2020-03-13 15:44:24 +05:30
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-27 11:52:29 +05:30
const btn = wrapper.findComponent(ClipboardButton);
2020-03-13 15:44:24 +05:30
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-06-23 00:09:42 +05:30
expect(wrapper.vm.blobSize).toBe('a lot');
2020-03-13 15:44:24 +05:30
});
2022-03-02 08:16:31 +05:30
it('renders LFS badge if LFS if enabled', () => {
createComponent({ storedExternally: true, externalStorage: 'lfs' });
expect(findBadge().text()).toBe('LFS');
});
2020-03-13 15:44:24 +05:30
it('renders a slot and prepends its contents to the existing one', () => {
const slotContent = 'Foo Bar';
createComponent(
{},
{
scopedSlots: {
2021-01-29 00:20:46 +05:30
'filepath-prepend': `<span>${slotContent}</span>`,
2020-03-13 15:44:24 +05:30
},
},
);
expect(wrapper.text()).toContain(slotContent);
2021-03-08 18:12:59 +05:30
expect(wrapper.text().trim().substring(0, slotContent.length)).toBe(slotContent);
2020-03-13 15:44:24 +05:30
});
});
describe('functionality', () => {
it('sets gfm value correctly on the clipboard-button', () => {
createComponent();
2020-05-24 23:13:21 +05:30
expect(wrapper.vm.gfmCopyText).toBe(`\`${MockBlob.path}\``);
2020-03-13 15:44:24 +05:30
});
});
});