debian-mirror-gitlab/spec/frontend/sidebar/confidential_issue_sidebar_spec.js

160 lines
4.5 KiB
JavaScript
Raw Normal View History

2019-12-21 20:55:43 +05:30
import { shallowMount } from '@vue/test-utils';
import { mockTracking, triggerEvent } from 'helpers/tracking_helper';
2020-10-24 23:57:45 +05:30
import { useMockLocationHelper } from 'helpers/mock_window_location_helper';
2020-01-01 13:55:28 +05:30
import ConfidentialIssueSidebar from '~/sidebar/components/confidential/confidential_issue_sidebar.vue';
2019-12-21 20:55:43 +05:30
import EditForm from '~/sidebar/components/confidential/edit_form.vue';
2020-05-24 23:13:21 +05:30
import createStore from '~/notes/stores';
2020-10-24 23:57:45 +05:30
import * as types from '~/notes/stores/mutation_types';
2019-12-21 20:55:43 +05:30
jest.mock('~/flash');
jest.mock('~/sidebar/services/sidebar_service');
describe('Confidential Issue Sidebar Block', () => {
2020-06-23 00:09:42 +05:30
useMockLocationHelper();
2019-12-21 20:55:43 +05:30
let wrapper;
2020-07-28 23:09:34 +05:30
const mutate = jest
.fn()
.mockResolvedValue({ data: { issueSetConfidential: { issue: { confidential: true } } } });
2019-12-21 20:55:43 +05:30
2020-07-28 23:09:34 +05:30
const createComponent = ({ propsData, data = {} }) => {
2020-05-24 23:13:21 +05:30
const store = createStore();
2019-12-21 20:55:43 +05:30
wrapper = shallowMount(ConfidentialIssueSidebar, {
2020-05-24 23:13:21 +05:30
store,
2020-07-28 23:09:34 +05:30
data() {
return data;
},
2019-12-21 20:55:43 +05:30
propsData: {
2020-07-28 23:09:34 +05:30
iid: '',
fullPath: '',
2019-12-21 20:55:43 +05:30
...propsData,
},
2020-07-28 23:09:34 +05:30
mocks: {
$apollo: {
mutate,
},
},
2019-12-21 20:55:43 +05:30
});
};
afterEach(() => {
wrapper.destroy();
});
it.each`
2020-05-24 23:13:21 +05:30
confidential | isEditable
${false} | ${false}
${false} | ${true}
${true} | ${false}
${true} | ${true}
2019-12-21 20:55:43 +05:30
`(
2020-05-24 23:13:21 +05:30
'renders for confidential = $confidential and isEditable = $isEditable',
({ confidential, isEditable }) => {
2019-12-21 20:55:43 +05:30
createComponent({
2020-07-28 23:09:34 +05:30
propsData: {
isEditable,
},
2019-12-21 20:55:43 +05:30
});
2020-05-24 23:13:21 +05:30
wrapper.vm.$store.state.noteableData.confidential = confidential;
2019-12-21 20:55:43 +05:30
2020-05-24 23:13:21 +05:30
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.element).toMatchSnapshot();
});
2019-12-21 20:55:43 +05:30
},
);
describe('if editable', () => {
beforeEach(() => {
createComponent({
2020-07-28 23:09:34 +05:30
propsData: {
isEditable: true,
},
2019-12-21 20:55:43 +05:30
});
2020-05-24 23:13:21 +05:30
wrapper.vm.$store.state.noteableData.confidential = true;
2019-12-21 20:55:43 +05:30
});
it('displays the edit form when editable', () => {
wrapper.setData({ edit: false });
2020-03-13 15:44:24 +05:30
return wrapper.vm
.$nextTick()
.then(() => {
wrapper.find({ ref: 'editLink' }).trigger('click');
return wrapper.vm.$nextTick();
})
.then(() => {
expect(wrapper.find(EditForm).exists()).toBe(true);
});
2019-12-21 20:55:43 +05:30
});
it('displays the edit form when opened from collapsed state', () => {
wrapper.setData({ edit: false });
2020-03-13 15:44:24 +05:30
return wrapper.vm
.$nextTick()
.then(() => {
wrapper.find({ ref: 'collapseIcon' }).trigger('click');
return wrapper.vm.$nextTick();
})
.then(() => {
expect(wrapper.find(EditForm).exists()).toBe(true);
});
2019-12-21 20:55:43 +05:30
});
it('tracks the event when "Edit" is clicked', () => {
const spy = mockTracking('_category_', wrapper.element, jest.spyOn);
const editLink = wrapper.find({ ref: 'editLink' });
triggerEvent(editLink.element);
expect(spy).toHaveBeenCalledWith('_category_', 'click_edit_button', {
label: 'right_sidebar',
property: 'confidentiality',
});
});
2020-10-24 23:57:45 +05:30
});
describe('computed confidential', () => {
beforeEach(() => {
createComponent({
propsData: {
isEditable: true,
},
2019-12-21 20:55:43 +05:30
});
2020-10-24 23:57:45 +05:30
});
2019-12-21 20:55:43 +05:30
2020-10-24 23:57:45 +05:30
it('returns false when noteableData is not present', () => {
wrapper.vm.$store.commit(types.SET_NOTEABLE_DATA, null);
2019-12-21 20:55:43 +05:30
2020-10-24 23:57:45 +05:30
expect(wrapper.vm.confidential).toBe(false);
2019-12-21 20:55:43 +05:30
});
2020-10-24 23:57:45 +05:30
it('returns true when noteableData has confidential attr as true', () => {
wrapper.vm.$store.commit(types.SET_NOTEABLE_DATA, {});
wrapper.vm.$store.commit(types.SET_ISSUE_CONFIDENTIAL, true);
2019-12-21 20:55:43 +05:30
2020-10-24 23:57:45 +05:30
expect(wrapper.vm.confidential).toBe(true);
2019-12-21 20:55:43 +05:30
});
2020-10-24 23:57:45 +05:30
it('returns false when noteableData has confidential attr as false', () => {
wrapper.vm.$store.commit(types.SET_NOTEABLE_DATA, {});
wrapper.vm.$store.commit(types.SET_ISSUE_CONFIDENTIAL, false);
expect(wrapper.vm.confidential).toBe(false);
});
2019-12-21 20:55:43 +05:30
2020-10-24 23:57:45 +05:30
it('returns true when confidential attr is true', () => {
wrapper.vm.$store.commit(types.SET_NOTEABLE_DATA, {});
wrapper.vm.$store.commit(types.SET_ISSUE_CONFIDENTIAL, true);
2019-12-21 20:55:43 +05:30
2020-10-24 23:57:45 +05:30
expect(wrapper.vm.confidential).toBe(true);
});
2019-12-21 20:55:43 +05:30
2020-10-24 23:57:45 +05:30
it('returns false when confidential attr is false', () => {
wrapper.vm.$store.commit(types.SET_NOTEABLE_DATA, {});
wrapper.vm.$store.commit(types.SET_ISSUE_CONFIDENTIAL, false);
2019-12-21 20:55:43 +05:30
2020-10-24 23:57:45 +05:30
expect(wrapper.vm.confidential).toBe(false);
2019-12-21 20:55:43 +05:30
});
});
});