debian-mirror-gitlab/spec/frontend/design_management/components/delete_button_spec.js

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

65 lines
1.6 KiB
JavaScript
Raw Normal View History

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';
2022-04-04 11:22:00 +05:30
import { nextTick } from 'vue';
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();
});
2022-04-04 11:22:00 +05:30
it('emits `delete-selected-designs` event on modal ok click', async () => {
2020-05-24 23:13:21 +05:30
createComponent();
findButton().vm.$emit('click');
2022-04-04 11:22:00 +05:30
await nextTick();
findModal().vm.$emit('ok');
await nextTick();
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
});