debian-mirror-gitlab/spec/javascripts/diffs/components/diff_discussions_spec.js

91 lines
2.8 KiB
JavaScript
Raw Normal View History

2018-11-08 19:23:39 +05:30
import Vue from 'vue';
import DiffDiscussions from '~/diffs/components/diff_discussions.vue';
2018-12-13 13:39:08 +05:30
import { createStore } from '~/mr_notes/stores';
2018-11-08 19:23:39 +05:30
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
2018-12-13 13:39:08 +05:30
import '~/behaviors/markdown/render_gfm';
2018-11-08 19:23:39 +05:30
import discussionsMockData from '../mock_data/diff_discussions';
describe('DiffDiscussions', () => {
2018-12-13 13:39:08 +05:30
let vm;
2018-11-08 19:23:39 +05:30
const getDiscussionsMockData = () => [Object.assign({}, discussionsMockData)];
2018-12-13 13:39:08 +05:30
function createComponent(props = {}) {
const store = createStore();
vm = createComponentWithStore(Vue.extend(DiffDiscussions), store, {
2018-11-08 19:23:39 +05:30
discussions: getDiscussionsMockData(),
2018-12-13 13:39:08 +05:30
...props,
2018-11-08 19:23:39 +05:30
}).$mount();
2018-12-13 13:39:08 +05:30
}
afterEach(() => {
vm.$destroy();
2018-11-08 19:23:39 +05:30
});
describe('template', () => {
it('should have notes list', () => {
2018-12-13 13:39:08 +05:30
createComponent();
expect(vm.$el.querySelectorAll('.discussion .note.timeline-entry').length).toEqual(5);
});
});
describe('image commenting', () => {
it('renders collapsible discussion button', () => {
createComponent({ shouldCollapseDiscussions: true });
expect(vm.$el.querySelector('.js-diff-notes-toggle')).not.toBe(null);
expect(vm.$el.querySelector('.js-diff-notes-toggle svg')).not.toBe(null);
expect(vm.$el.querySelector('.js-diff-notes-toggle').classList).toContain(
'diff-notes-collapse',
);
});
it('dispatches toggleDiscussion when clicking collapse button', () => {
createComponent({ shouldCollapseDiscussions: true });
spyOn(vm.$store, 'dispatch').and.stub();
vm.$el.querySelector('.js-diff-notes-toggle').click();
expect(vm.$store.dispatch).toHaveBeenCalledWith('toggleDiscussion', {
discussionId: vm.discussions[0].id,
});
});
it('renders expand button when discussion is collapsed', done => {
createComponent({ shouldCollapseDiscussions: true });
vm.discussions[0].expanded = false;
vm.$nextTick(() => {
expect(vm.$el.querySelector('.js-diff-notes-toggle').textContent.trim()).toBe('1');
expect(vm.$el.querySelector('.js-diff-notes-toggle').className).toContain(
'btn-transparent badge badge-pill',
);
done();
});
});
it('hides discussion when collapsed', done => {
createComponent({ shouldCollapseDiscussions: true });
vm.discussions[0].expanded = false;
vm.$nextTick(() => {
expect(vm.$el.querySelector('.note-discussion').style.display).toBe('none');
done();
});
});
it('renders badge on avatar', () => {
createComponent({ renderAvatarBadge: true, discussions: [{ ...discussionsMockData }] });
2018-11-08 19:23:39 +05:30
2018-12-13 13:39:08 +05:30
expect(vm.$el.querySelector('.user-avatar-link .badge-pill')).not.toBe(null);
expect(vm.$el.querySelector('.user-avatar-link .badge-pill').textContent.trim()).toBe('1');
2018-11-08 19:23:39 +05:30
});
});
});