2022-06-21 17:19:12 +05:30
|
|
|
import { GlButton, GlModal, GlSprintf } from '@gitlab/ui';
|
2022-05-07 20:08:51 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
|
|
|
|
import RemoveAvatar from '~/admin/topics/components/remove_avatar.vue';
|
|
|
|
|
|
|
|
const modalID = 'fake-id';
|
|
|
|
const path = 'topic/path/1';
|
2022-06-21 17:19:12 +05:30
|
|
|
const name = 'Topic 1';
|
2022-05-07 20:08:51 +05:30
|
|
|
|
|
|
|
jest.mock('lodash/uniqueId', () => () => 'fake-id');
|
|
|
|
jest.mock('~/lib/utils/csrf', () => ({ token: 'mock-csrf-token' }));
|
|
|
|
|
|
|
|
describe('RemoveAvatar', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const createComponent = () => {
|
|
|
|
wrapper = shallowMount(RemoveAvatar, {
|
|
|
|
provide: {
|
|
|
|
path,
|
2022-06-21 17:19:12 +05:30
|
|
|
name,
|
2022-05-07 20:08:51 +05:30
|
|
|
},
|
|
|
|
directives: {
|
|
|
|
GlModal: createMockDirective(),
|
|
|
|
},
|
2022-06-21 17:19:12 +05:30
|
|
|
stubs: {
|
|
|
|
GlSprintf,
|
|
|
|
},
|
2022-05-07 20:08:51 +05:30
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const findButton = () => wrapper.findComponent(GlButton);
|
|
|
|
const findModal = () => wrapper.findComponent(GlModal);
|
|
|
|
const findForm = () => wrapper.find('form');
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('the button component', () => {
|
|
|
|
it('displays the remove button', () => {
|
|
|
|
const button = findButton();
|
|
|
|
|
|
|
|
expect(button.exists()).toBe(true);
|
|
|
|
expect(button.text()).toBe('Remove avatar');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('contains the correct modal ID', () => {
|
|
|
|
const buttonModalId = getBinding(findButton().element, 'gl-modal').value;
|
|
|
|
|
|
|
|
expect(buttonModalId).toBe(modalID);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('the modal component', () => {
|
|
|
|
it('displays the modal component', () => {
|
|
|
|
const modal = findModal();
|
|
|
|
|
|
|
|
expect(modal.exists()).toBe(true);
|
2022-06-21 17:19:12 +05:30
|
|
|
expect(modal.props('title')).toBe('Remove topic avatar');
|
|
|
|
expect(modal.text()).toBe(`Topic avatar for ${name} will be removed. This cannot be undone.`);
|
2022-05-07 20:08:51 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('contains the correct modal ID', () => {
|
|
|
|
expect(findModal().props('modalId')).toBe(modalID);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('form', () => {
|
|
|
|
it('matches the snapshot', () => {
|
|
|
|
expect(findForm().element).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('form submission', () => {
|
|
|
|
let formSubmitSpy;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
formSubmitSpy = jest.spyOn(wrapper.vm.$refs.deleteForm, 'submit');
|
|
|
|
findModal().vm.$emit('primary');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('submits the form on the modal primary action', () => {
|
|
|
|
expect(formSubmitSpy).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|