debian-mirror-gitlab/spec/frontend/sidebar/confidential/edit_form_buttons_spec.js

148 lines
3.8 KiB
JavaScript
Raw Normal View History

2020-05-24 23:13:21 +05:30
import { shallowMount } from '@vue/test-utils';
2020-07-28 23:09:34 +05:30
import { GlLoadingIcon } from '@gitlab/ui';
2020-10-24 23:57:45 +05:30
import waitForPromises from 'helpers/wait_for_promises';
2020-05-24 23:13:21 +05:30
import EditFormButtons from '~/sidebar/components/confidential/edit_form_buttons.vue';
2020-07-28 23:09:34 +05:30
import eventHub from '~/sidebar/event_hub';
import createStore from '~/notes/stores';
2020-10-24 23:57:45 +05:30
import { deprecatedCreateFlash as flash } from '~/flash';
2020-07-28 23:09:34 +05:30
jest.mock('~/sidebar/event_hub', () => ({ $emit: jest.fn() }));
jest.mock('~/flash');
2020-05-24 23:13:21 +05:30
describe('Edit Form Buttons', () => {
let wrapper;
2020-07-28 23:09:34 +05:30
let store;
2020-05-24 23:13:21 +05:30
const findConfidentialToggle = () => wrapper.find('[data-testid="confidential-toggle"]');
2020-10-24 23:57:45 +05:30
const createComponent = ({ props = {}, data = {}, resolved = true }) => {
2020-07-28 23:09:34 +05:30
store = createStore();
if (resolved) {
jest.spyOn(store, 'dispatch').mockResolvedValue();
} else {
jest.spyOn(store, 'dispatch').mockRejectedValue();
}
2020-05-24 23:13:21 +05:30
wrapper = shallowMount(EditFormButtons, {
propsData: {
2020-07-28 23:09:34 +05:30
fullPath: '',
2020-05-24 23:13:21 +05:30
...props,
},
2020-07-28 23:09:34 +05:30
data() {
return {
isLoading: true,
...data,
};
},
store,
2020-05-24 23:13:21 +05:30
});
};
afterEach(() => {
wrapper.destroy();
wrapper = null;
});
2020-07-28 23:09:34 +05:30
describe('when isLoading', () => {
beforeEach(() => {
2020-10-24 23:57:45 +05:30
createComponent({
props: {
confidential: false,
},
});
2020-07-28 23:09:34 +05:30
});
it('renders "Applying" in the toggle button', () => {
expect(findConfidentialToggle().text()).toBe('Applying');
});
it('disables the toggle button', () => {
expect(findConfidentialToggle().attributes('disabled')).toBe('disabled');
});
it('finds the GlLoadingIcon', () => {
expect(wrapper.find(GlLoadingIcon).exists()).toBe(true);
});
});
2020-05-24 23:13:21 +05:30
describe('when not confidential', () => {
2020-07-28 23:09:34 +05:30
it('renders Turn On in the toggle button', () => {
2020-05-24 23:13:21 +05:30
createComponent({
2020-07-28 23:09:34 +05:30
data: {
isLoading: false,
},
2020-10-24 23:57:45 +05:30
props: {
confidential: false,
},
2020-05-24 23:13:21 +05:30
});
expect(findConfidentialToggle().text()).toBe('Turn On');
});
});
describe('when confidential', () => {
2020-07-28 23:09:34 +05:30
beforeEach(() => {
2020-05-24 23:13:21 +05:30
createComponent({
2020-07-28 23:09:34 +05:30
data: {
isLoading: false,
},
2020-10-24 23:57:45 +05:30
props: {
confidential: true,
},
2020-05-24 23:13:21 +05:30
});
2020-07-28 23:09:34 +05:30
});
it('renders on or off text based on confidentiality', () => {
2020-05-24 23:13:21 +05:30
expect(findConfidentialToggle().text()).toBe('Turn Off');
});
2020-07-28 23:09:34 +05:30
});
2020-10-24 23:57:45 +05:30
describe('when succeeds', () => {
beforeEach(() => {
createComponent({ data: { isLoading: false }, props: { confidential: true } });
findConfidentialToggle().trigger('click');
});
2020-07-28 23:09:34 +05:30
2020-10-24 23:57:45 +05:30
it('dispatches the correct action', () => {
expect(store.dispatch).toHaveBeenCalledWith('updateConfidentialityOnIssuable', {
confidential: false,
fullPath: '',
2020-07-28 23:09:34 +05:30
});
2020-10-24 23:57:45 +05:30
});
2020-07-28 23:09:34 +05:30
2020-10-24 23:57:45 +05:30
it('resets loading', () => {
return waitForPromises().then(() => {
expect(wrapper.find(GlLoadingIcon).exists()).toBe(false);
2020-07-28 23:09:34 +05:30
});
2020-10-24 23:57:45 +05:30
});
2020-07-28 23:09:34 +05:30
2020-10-24 23:57:45 +05:30
it('emits close form', () => {
return waitForPromises().then(() => {
expect(eventHub.$emit).toHaveBeenCalledWith('closeConfidentialityForm');
2020-07-28 23:09:34 +05:30
});
2020-10-24 23:57:45 +05:30
});
2020-07-28 23:09:34 +05:30
2020-10-24 23:57:45 +05:30
it('emits updateOnConfidentiality event', () => {
return waitForPromises().then(() => {
expect(eventHub.$emit).toHaveBeenCalledWith('updateIssuableConfidentiality', false);
2020-07-28 23:09:34 +05:30
});
});
2020-10-24 23:57:45 +05:30
});
2020-07-28 23:09:34 +05:30
2020-10-24 23:57:45 +05:30
describe('when fails', () => {
beforeEach(() => {
createComponent({
data: { isLoading: false },
props: { confidential: true },
resolved: false,
2020-07-28 23:09:34 +05:30
});
2020-10-24 23:57:45 +05:30
findConfidentialToggle().trigger('click');
});
2020-07-28 23:09:34 +05:30
2020-10-24 23:57:45 +05:30
it('calls flash with the correct message', () => {
expect(flash).toHaveBeenCalledWith(
'Something went wrong trying to change the confidentiality of this issue',
);
2020-07-28 23:09:34 +05:30
});
2020-05-24 23:13:21 +05:30
});
});