Commit 6edea27f authored by Tim Zallmann's avatar Tim Zallmann

Merge branch 'winh-vue-test-utils-confidential_issue_sidebar_spec' into 'master'

Migrate confidential_issue_sidebar_spec.js to Vue test utils

See merge request gitlab-org/gitlab!17552
parents 2db115c6 7413f957
...@@ -66,6 +66,7 @@ export default { ...@@ -66,6 +66,7 @@ export default {
<template> <template>
<div class="block issuable-sidebar-item confidentiality"> <div class="block issuable-sidebar-item confidentiality">
<div <div
ref="collapseIcon"
v-tooltip v-tooltip
:title="tooltipLabel" :title="tooltipLabel"
class="sidebar-collapsed-icon" class="sidebar-collapsed-icon"
...@@ -80,6 +81,7 @@ export default { ...@@ -80,6 +81,7 @@ export default {
{{ __('Confidentiality') }} {{ __('Confidentiality') }}
<a <a
v-if="isEditable" v-if="isEditable"
ref="editLink"
class="float-right confidential-edit" class="float-right confidential-edit"
href="#" href="#"
data-track-event="click_edit_button" data-track-event="click_edit_button"
......
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Confidential Issue Sidebar Block renders for isConfidential = false and isEditable = false 1`] = `
<div
class="block issuable-sidebar-item confidentiality"
>
<div
class="sidebar-collapsed-icon"
data-boundary="viewport"
data-container="body"
data-original-title="Not confidential"
data-placement="left"
title=""
>
<icon-stub
aria-hidden="true"
cssclasses=""
name="eye"
size="16"
/>
</div>
<div
class="title hide-collapsed"
>
Confidentiality
<!---->
</div>
<div
class="value sidebar-item-value hide-collapsed"
>
<!---->
<div
class="no-value sidebar-item-value"
>
<icon-stub
aria-hidden="true"
class="sidebar-item-icon inline"
cssclasses=""
name="eye"
size="16"
/>
Not confidential
</div>
</div>
</div>
`;
exports[`Confidential Issue Sidebar Block renders for isConfidential = false and isEditable = true 1`] = `
<div
class="block issuable-sidebar-item confidentiality"
>
<div
class="sidebar-collapsed-icon"
data-boundary="viewport"
data-container="body"
data-original-title="Not confidential"
data-placement="left"
title=""
>
<icon-stub
aria-hidden="true"
cssclasses=""
name="eye"
size="16"
/>
</div>
<div
class="title hide-collapsed"
>
Confidentiality
<a
class="float-right confidential-edit"
data-track-event="click_edit_button"
data-track-label="right_sidebar"
data-track-property="confidentiality"
href="#"
>
Edit
</a>
</div>
<div
class="value sidebar-item-value hide-collapsed"
>
<!---->
<div
class="no-value sidebar-item-value"
>
<icon-stub
aria-hidden="true"
class="sidebar-item-icon inline"
cssclasses=""
name="eye"
size="16"
/>
Not confidential
</div>
</div>
</div>
`;
exports[`Confidential Issue Sidebar Block renders for isConfidential = true and isEditable = false 1`] = `
<div
class="block issuable-sidebar-item confidentiality"
>
<div
class="sidebar-collapsed-icon"
data-boundary="viewport"
data-container="body"
data-original-title="Confidential"
data-placement="left"
title=""
>
<icon-stub
aria-hidden="true"
cssclasses=""
name="eye-slash"
size="16"
/>
</div>
<div
class="title hide-collapsed"
>
Confidentiality
<!---->
</div>
<div
class="value sidebar-item-value hide-collapsed"
>
<!---->
<div
class="value sidebar-item-value hide-collapsed"
>
<icon-stub
aria-hidden="true"
class="sidebar-item-icon inline is-active"
cssclasses=""
name="eye-slash"
size="16"
/>
This issue is confidential
</div>
</div>
</div>
`;
exports[`Confidential Issue Sidebar Block renders for isConfidential = true and isEditable = true 1`] = `
<div
class="block issuable-sidebar-item confidentiality"
>
<div
class="sidebar-collapsed-icon"
data-boundary="viewport"
data-container="body"
data-original-title="Confidential"
data-placement="left"
title=""
>
<icon-stub
aria-hidden="true"
cssclasses=""
name="eye-slash"
size="16"
/>
</div>
<div
class="title hide-collapsed"
>
Confidentiality
<a
class="float-right confidential-edit"
data-track-event="click_edit_button"
data-track-label="right_sidebar"
data-track-property="confidentiality"
href="#"
>
Edit
</a>
</div>
<div
class="value sidebar-item-value hide-collapsed"
>
<!---->
<div
class="value sidebar-item-value hide-collapsed"
>
<icon-stub
aria-hidden="true"
class="sidebar-item-icon inline is-active"
cssclasses=""
name="eye-slash"
size="16"
/>
This issue is confidential
</div>
</div>
</div>
`;
import Vue from 'vue'; import { shallowMount } from '@vue/test-utils';
import confidentialIssueSidebar from '~/sidebar/components/confidential/confidential_issue_sidebar.vue'; import ConfidentialIssueSidebar from '~/sidebar/components/confidential/confidential_issue_sidebar.vue';
import { mockTracking, triggerEvent } from 'helpers/tracking_helper'; import { mockTracking, triggerEvent } from 'helpers/tracking_helper';
import EditForm from '~/sidebar/components/confidential/edit_form.vue';
describe('Confidential Issue Sidebar Block', () => { describe('Confidential Issue Sidebar Block', () => {
let vm1; let wrapper;
let vm2;
beforeEach(() => { const createComponent = propsData => {
const Component = Vue.extend(confidentialIssueSidebar);
const service = { const service = {
update: () => Promise.resolve(true), update: () => Promise.resolve(true),
}; };
vm1 = new Component({ wrapper = shallowMount(ConfidentialIssueSidebar, {
propsData: { propsData: {
isConfidential: true,
isEditable: true,
service, service,
...propsData,
}, },
}).$mount(); sync: false,
});
vm2 = new Component({ };
propsData: {
isConfidential: false, it.each`
isEditable: false, isConfidential | isEditable
service, ${false} | ${false}
}, ${false} | ${true}
}).$mount(); ${true} | ${false}
}); ${true} | ${true}
`(
it('shows if confidential and/or editable', () => { 'renders for isConfidential = $isConfidential and isEditable = $isEditable',
expect(vm1.$el.innerHTML.includes('Edit')).toBe(true); ({ isConfidential, isEditable }) => {
createComponent({
expect(vm1.$el.innerHTML.includes('This issue is confidential')).toBe(true); isConfidential,
isEditable,
expect(vm2.$el.innerHTML.includes('Not confidential')).toBe(true); });
expect(wrapper.element).toMatchSnapshot();
},
);
afterEach(() => {
wrapper.destroy();
}); });
it('displays the edit form when editable', () => { describe('if editable', () => {
expect(vm1.edit).toBe(false); beforeEach(() => {
createComponent({
isConfidential: true,
isEditable: true,
});
});
vm1.$el.querySelector('.confidential-edit').click(); it('displays the edit form when editable', () => {
wrapper.setData({ edit: false });
expect(vm1.edit).toBe(true); wrapper.find({ ref: 'editLink' }).trigger('click');
return Vue.nextTick().then(() => { return wrapper.vm.$nextTick().then(() => {
expect(vm1.$el.innerHTML.includes('You are going to turn off the confidentiality.')).toBe( expect(wrapper.find(EditForm).exists()).toBe(true);
true, });
);
}); });
});
it('displays the edit form when opened from collapsed state', () => {
expect(vm1.edit).toBe(false);
vm1.$el.querySelector('.sidebar-collapsed-icon').click(); it('displays the edit form when opened from collapsed state', () => {
wrapper.setData({ edit: false });
expect(vm1.edit).toBe(true); wrapper.find({ ref: 'collapseIcon' }).trigger('click');
return Vue.nextTick().then(() => { return wrapper.vm.$nextTick().then(() => {
expect(vm1.$el.innerHTML.includes('You are going to turn off the confidentiality.')).toBe( expect(wrapper.find(EditForm).exists()).toBe(true);
true, });
);
}); });
});
it('tracks the event when "Edit" is clicked', () => { it('tracks the event when "Edit" is clicked', () => {
const spy = mockTracking('_category_', vm1.$el, jest.spyOn); const spy = mockTracking('_category_', wrapper.element, jest.spyOn);
triggerEvent('.confidential-edit');
const editLink = wrapper.find({ ref: 'editLink' });
triggerEvent(editLink.element);
expect(spy).toHaveBeenCalledWith('_category_', 'click_edit_button', { expect(spy).toHaveBeenCalledWith('_category_', 'click_edit_button', {
label: 'right_sidebar', label: 'right_sidebar',
property: 'confidentiality', property: 'confidentiality',
});
}); });
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment