2020-10-24 23:57:45 +05:30
|
|
|
import { GlButton, GlModal, GlModalDirective } 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 BatchDeleteButton from '~/design_management/components/delete_button.vue';
|
|
|
|
|
|
|
|
describe('Batch delete button component', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
const findButton = () => wrapper.find(GlButton);
|
2020-05-24 23:13:21 +05:30
|
|
|
const findModal = () => wrapper.find(GlModal);
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
function createComponent({ isDeleting = false } = {}, { slots = {} } = {}) {
|
2020-05-24 23:13:21 +05:30
|
|
|
wrapper = shallowMount(BatchDeleteButton, {
|
|
|
|
propsData: {
|
|
|
|
isDeleting,
|
|
|
|
},
|
|
|
|
directives: {
|
|
|
|
GlModalDirective,
|
|
|
|
},
|
2020-11-24 15:15:51 +05:30
|
|
|
slots,
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders non-disabled button by default', () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
expect(findButton().exists()).toBe(true);
|
|
|
|
expect(findButton().attributes('disabled')).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders disabled button when design is deleting', () => {
|
2020-11-24 15:15:51 +05:30
|
|
|
createComponent({ isDeleting: true });
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(findButton().attributes('disabled')).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
it('emits `delete-selected-designs` event on modal ok click', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
createComponent();
|
|
|
|
findButton().vm.$emit('click');
|
|
|
|
return wrapper.vm
|
|
|
|
.$nextTick()
|
|
|
|
.then(() => {
|
|
|
|
findModal().vm.$emit('ok');
|
|
|
|
return wrapper.vm.$nextTick();
|
|
|
|
})
|
|
|
|
.then(() => {
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(wrapper.emitted('delete-selected-designs')).toBeTruthy();
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
|
|
|
});
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
it('renders slot content', () => {
|
|
|
|
const testText = 'Archive selected';
|
|
|
|
createComponent(
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
slots: {
|
|
|
|
default: testText,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(findButton().text()).toBe(testText);
|
|
|
|
});
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|