debian-mirror-gitlab/spec/javascripts/sidebar/lock/lock_issue_sidebar_spec.js

100 lines
2.4 KiB
JavaScript
Raw Normal View History

2018-03-17 18:26:18 +05:30
import Vue from 'vue';
2019-12-21 20:55:43 +05:30
import { mockTracking, triggerEvent } from 'spec/helpers/tracking_helper';
2020-01-01 13:55:28 +05:30
import lockIssueSidebar from '~/sidebar/components/lock/lock_issue_sidebar.vue';
2018-03-17 18:26:18 +05:30
describe('LockIssueSidebar', () => {
let vm1;
let vm2;
beforeEach(() => {
const Component = Vue.extend(lockIssueSidebar);
const mediator = {
service: {
update: Promise.resolve(true),
},
store: {
isLockDialogOpen: false,
},
};
vm1 = new Component({
propsData: {
isLocked: true,
isEditable: true,
mediator,
issuableType: 'issue',
},
}).$mount();
vm2 = new Component({
propsData: {
isLocked: false,
isEditable: false,
mediator,
issuableType: 'merge_request',
},
}).$mount();
});
it('shows if locked and/or editable', () => {
2018-12-13 13:39:08 +05:30
expect(vm1.$el.innerHTML.includes('Edit')).toBe(true);
2018-03-17 18:26:18 +05:30
2018-12-13 13:39:08 +05:30
expect(vm1.$el.innerHTML.includes('Locked')).toBe(true);
2018-03-17 18:26:18 +05:30
2018-12-13 13:39:08 +05:30
expect(vm2.$el.innerHTML.includes('Unlocked')).toBe(true);
2018-03-17 18:26:18 +05:30
});
2018-12-13 13:39:08 +05:30
it('displays the edit form when editable', done => {
2018-03-17 18:26:18 +05:30
expect(vm1.isLockDialogOpen).toBe(false);
vm1.$el.querySelector('.lock-edit').click();
expect(vm1.isLockDialogOpen).toBe(true);
vm1.$nextTick(() => {
2018-12-13 13:39:08 +05:30
expect(vm1.$el.innerHTML.includes('Unlock this issue?')).toBe(true);
2018-03-17 18:26:18 +05:30
done();
});
});
2018-05-09 12:01:36 +05:30
2019-12-21 20:55:43 +05:30
it('tracks an event when "Edit" is clicked', () => {
const spy = mockTracking('_category_', vm1.$el, spyOn);
triggerEvent('.lock-edit');
2019-12-04 20:38:33 +05:30
2019-12-21 20:55:43 +05:30
expect(spy).toHaveBeenCalledWith('_category_', 'click_edit_button', {
label: 'right_sidebar',
property: 'lock_issue',
});
2019-12-04 20:38:33 +05:30
});
2018-12-13 13:39:08 +05:30
it('displays the edit form when opened from collapsed state', done => {
2018-05-09 12:01:36 +05:30
expect(vm1.isLockDialogOpen).toBe(false);
vm1.$el.querySelector('.sidebar-collapsed-icon').click();
expect(vm1.isLockDialogOpen).toBe(true);
setTimeout(() => {
2018-12-13 13:39:08 +05:30
expect(vm1.$el.innerHTML.includes('Unlock this issue?')).toBe(true);
2018-05-09 12:01:36 +05:30
done();
});
});
2020-04-08 14:13:33 +05:30
it('does not display the edit form when opened from collapsed state if not editable', done => {
expect(vm2.isLockDialogOpen).toBe(false);
vm2.$el.querySelector('.sidebar-collapsed-icon').click();
Vue.nextTick()
.then(() => {
expect(vm2.isLockDialogOpen).toBe(false);
})
.then(done)
.catch(done.fail);
});
2018-03-17 18:26:18 +05:30
});