2021-01-29 00:20:46 +05:30
|
|
|
import { GlButton } from '@gitlab/ui';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2020-05-24 23:13:21 +05:30
|
|
|
import UploadButton from '~/design_management/components/upload/button.vue';
|
|
|
|
|
|
|
|
describe('Design management upload button component', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
function createComponent({ isSaving = false, isInverted = false } = {}) {
|
2020-05-24 23:13:21 +05:30
|
|
|
wrapper = shallowMount(UploadButton, {
|
|
|
|
propsData: {
|
|
|
|
isSaving,
|
|
|
|
isInverted,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
it('renders upload design button', () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
expect(wrapper.element).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders inverted upload design button', () => {
|
2021-01-29 00:20:46 +05:30
|
|
|
createComponent({ isInverted: true });
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
expect(wrapper.element).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
describe('when `isSaving` prop is `true`', () => {
|
|
|
|
it('Button `loading` prop is `true`', () => {
|
|
|
|
createComponent({ isSaving: true });
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
const button = wrapper.findComponent(GlButton);
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(button.exists()).toBe(true);
|
|
|
|
expect(button.props('loading')).toBe(true);
|
|
|
|
});
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('onFileUploadChange', () => {
|
|
|
|
it('emits upload event', () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
wrapper.vm.onFileUploadChange({ target: { files: 'test' } });
|
|
|
|
|
|
|
|
expect(wrapper.emitted().upload[0]).toEqual(['test']);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('openFileUpload', () => {
|
|
|
|
it('triggers click on input', () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
const clickSpy = jest.spyOn(wrapper.find('input').element, 'click');
|
|
|
|
|
|
|
|
wrapper.vm.openFileUpload();
|
|
|
|
|
|
|
|
expect(clickSpy).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|