2020-10-24 23:57:45 +05:30
|
|
|
import { GlFormInput, GlButton } from '@gitlab/ui';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2020-04-08 14:13:33 +05:30
|
|
|
import BlobEditHeader from '~/blob/components/blob_edit_header.vue';
|
|
|
|
|
|
|
|
describe('Blob Header Editing', () => {
|
|
|
|
let wrapper;
|
|
|
|
const value = 'foo.md';
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
const createComponent = (props = {}) => {
|
2020-04-08 14:13:33 +05:30
|
|
|
wrapper = shallowMount(BlobEditHeader, {
|
|
|
|
propsData: {
|
|
|
|
value,
|
2020-10-24 23:57:45 +05:30
|
|
|
...props,
|
2020-04-08 14:13:33 +05:30
|
|
|
},
|
|
|
|
});
|
2020-10-24 23:57:45 +05:30
|
|
|
};
|
|
|
|
const findDeleteButton = () =>
|
2021-03-08 18:12:59 +05:30
|
|
|
wrapper.findAll(GlButton).wrappers.find((x) => x.text() === 'Delete file');
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('rendering', () => {
|
|
|
|
it('matches the snapshot', () => {
|
|
|
|
expect(wrapper.element).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('contains a form input field', () => {
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(wrapper.find(GlFormInput).exists()).toBe(true);
|
2020-04-08 14:13:33 +05:30
|
|
|
});
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
it('does not show delete button', () => {
|
|
|
|
expect(findDeleteButton()).toBeUndefined();
|
|
|
|
});
|
2020-04-08 14:13:33 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('functionality', () => {
|
|
|
|
it('emits input event when the blob name is changed', () => {
|
|
|
|
const inputComponent = wrapper.find(GlFormInput);
|
|
|
|
const newValue = 'bar.txt';
|
|
|
|
|
|
|
|
wrapper.setData({
|
|
|
|
name: newValue,
|
|
|
|
});
|
|
|
|
inputComponent.vm.$emit('change');
|
|
|
|
|
|
|
|
return wrapper.vm.$nextTick().then(() => {
|
|
|
|
expect(wrapper.emitted().input[0]).toEqual([newValue]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
describe.each`
|
|
|
|
props | expectedDisabled
|
|
|
|
${{ showDelete: true }} | ${false}
|
|
|
|
${{ showDelete: true, canDelete: false }} | ${true}
|
|
|
|
`('with $props', ({ props, expectedDisabled }) => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent(props);
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`shows delete button (disabled=${expectedDisabled})`, () => {
|
|
|
|
const deleteButton = findDeleteButton();
|
|
|
|
|
|
|
|
expect(deleteButton.exists()).toBe(true);
|
|
|
|
expect(deleteButton.props('disabled')).toBe(expectedDisabled);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with delete button', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({ showDelete: true, canDelete: true });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('emits delete when clicked', () => {
|
|
|
|
expect(wrapper.emitted().delete).toBeUndefined();
|
|
|
|
|
|
|
|
findDeleteButton().vm.$emit('click');
|
|
|
|
|
|
|
|
expect(wrapper.emitted().delete).toEqual([[]]);
|
|
|
|
});
|
|
|
|
});
|
2020-04-08 14:13:33 +05:30
|
|
|
});
|