2019-09-27 12:06:07 +00:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2019-09-26 06:06:27 +00:00
|
|
|
import { mockTracking, triggerEvent } from 'helpers/tracking_helper';
|
2019-12-09 12:07:58 +00:00
|
|
|
import ConfidentialIssueSidebar from '~/sidebar/components/confidential/confidential_issue_sidebar.vue';
|
2019-09-27 12:06:07 +00:00
|
|
|
import EditForm from '~/sidebar/components/confidential/edit_form.vue';
|
2019-10-01 15:06:05 +00:00
|
|
|
import SidebarService from '~/sidebar/services/sidebar_service';
|
2020-05-08 15:09:28 +00:00
|
|
|
import createStore from '~/notes/stores';
|
2020-06-16 12:09:00 +00:00
|
|
|
import { useMockLocationHelper } from 'helpers/mock_window_location_helper';
|
2019-10-01 15:06:05 +00:00
|
|
|
|
|
|
|
jest.mock('~/flash');
|
|
|
|
jest.mock('~/sidebar/services/sidebar_service');
|
2017-08-07 23:56:16 +00:00
|
|
|
|
|
|
|
describe('Confidential Issue Sidebar Block', () => {
|
2020-06-16 12:09:00 +00:00
|
|
|
useMockLocationHelper();
|
|
|
|
|
2019-09-27 12:06:07 +00:00
|
|
|
let wrapper;
|
2020-06-25 15:08:37 +00:00
|
|
|
const mutate = jest
|
|
|
|
.fn()
|
|
|
|
.mockResolvedValue({ data: { issueSetConfidential: { issue: { confidential: true } } } });
|
2017-08-07 23:56:16 +00:00
|
|
|
|
2020-06-25 15:08:37 +00:00
|
|
|
const createComponent = ({ propsData, data = {} }) => {
|
2020-05-08 15:09:28 +00:00
|
|
|
const store = createStore();
|
2019-10-01 15:06:05 +00:00
|
|
|
const service = new SidebarService();
|
2019-09-27 12:06:07 +00:00
|
|
|
wrapper = shallowMount(ConfidentialIssueSidebar, {
|
2020-05-08 15:09:28 +00:00
|
|
|
store,
|
2020-06-25 15:08:37 +00:00
|
|
|
data() {
|
|
|
|
return data;
|
|
|
|
},
|
2017-08-07 23:56:16 +00:00
|
|
|
propsData: {
|
|
|
|
service,
|
2020-06-25 15:08:37 +00:00
|
|
|
iid: '',
|
|
|
|
fullPath: '',
|
2019-09-27 12:06:07 +00:00
|
|
|
...propsData,
|
2017-08-07 23:56:16 +00:00
|
|
|
},
|
2020-06-25 15:08:37 +00:00
|
|
|
mocks: {
|
|
|
|
$apollo: {
|
|
|
|
mutate,
|
|
|
|
},
|
|
|
|
},
|
2019-09-27 12:06:07 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2019-10-01 15:06:05 +00:00
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
2019-09-27 12:06:07 +00:00
|
|
|
it.each`
|
2020-05-08 15:09:28 +00:00
|
|
|
confidential | isEditable
|
|
|
|
${false} | ${false}
|
|
|
|
${false} | ${true}
|
|
|
|
${true} | ${false}
|
|
|
|
${true} | ${true}
|
2019-09-27 12:06:07 +00:00
|
|
|
`(
|
2020-05-08 15:09:28 +00:00
|
|
|
'renders for confidential = $confidential and isEditable = $isEditable',
|
|
|
|
({ confidential, isEditable }) => {
|
2019-09-27 12:06:07 +00:00
|
|
|
createComponent({
|
2020-06-25 15:08:37 +00:00
|
|
|
propsData: {
|
|
|
|
isEditable,
|
|
|
|
},
|
2019-09-27 12:06:07 +00:00
|
|
|
});
|
2020-05-08 15:09:28 +00:00
|
|
|
wrapper.vm.$store.state.noteableData.confidential = confidential;
|
2019-09-27 12:06:07 +00:00
|
|
|
|
2020-05-08 15:09:28 +00:00
|
|
|
return wrapper.vm.$nextTick().then(() => {
|
|
|
|
expect(wrapper.element).toMatchSnapshot();
|
|
|
|
});
|
2019-09-27 12:06:07 +00:00
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
describe('if editable', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({
|
2020-06-25 15:08:37 +00:00
|
|
|
propsData: {
|
|
|
|
isEditable: true,
|
|
|
|
},
|
2019-09-27 12:06:07 +00:00
|
|
|
});
|
2020-05-08 15:09:28 +00:00
|
|
|
wrapper.vm.$store.state.noteableData.confidential = true;
|
2019-09-27 12:06:07 +00:00
|
|
|
});
|
2017-08-07 23:56:16 +00:00
|
|
|
|
2019-09-27 12:06:07 +00:00
|
|
|
it('displays the edit form when editable', () => {
|
|
|
|
wrapper.setData({ edit: false });
|
2017-08-07 23:56:16 +00:00
|
|
|
|
2020-01-01 06:09:01 +00:00
|
|
|
return wrapper.vm
|
|
|
|
.$nextTick()
|
|
|
|
.then(() => {
|
|
|
|
wrapper.find({ ref: 'editLink' }).trigger('click');
|
|
|
|
return wrapper.vm.$nextTick();
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
expect(wrapper.find(EditForm).exists()).toBe(true);
|
|
|
|
});
|
2017-08-07 23:56:16 +00:00
|
|
|
});
|
2018-04-02 18:46:50 +00:00
|
|
|
|
2019-09-27 12:06:07 +00:00
|
|
|
it('displays the edit form when opened from collapsed state', () => {
|
|
|
|
wrapper.setData({ edit: false });
|
2018-04-02 18:46:50 +00:00
|
|
|
|
2020-01-01 06:09:01 +00:00
|
|
|
return wrapper.vm
|
|
|
|
.$nextTick()
|
|
|
|
.then(() => {
|
|
|
|
wrapper.find({ ref: 'collapseIcon' }).trigger('click');
|
|
|
|
return wrapper.vm.$nextTick();
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
expect(wrapper.find(EditForm).exists()).toBe(true);
|
|
|
|
});
|
2018-04-02 18:46:50 +00:00
|
|
|
});
|
2019-08-21 19:12:11 +00:00
|
|
|
|
2019-09-27 12:06:07 +00:00
|
|
|
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);
|
2019-08-21 19:12:11 +00:00
|
|
|
|
2019-09-27 12:06:07 +00:00
|
|
|
expect(spy).toHaveBeenCalledWith('_category_', 'click_edit_button', {
|
|
|
|
label: 'right_sidebar',
|
|
|
|
property: 'confidentiality',
|
|
|
|
});
|
2019-09-19 21:06:29 +00:00
|
|
|
});
|
2019-08-21 19:12:11 +00:00
|
|
|
});
|
2017-08-07 23:56:16 +00:00
|
|
|
});
|