2018-11-08 19:23:39 +05:30
|
|
|
import Vue from 'vue';
|
2020-01-01 13:55:28 +05:30
|
|
|
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
|
2018-11-08 19:23:39 +05:30
|
|
|
import createStore from '~/notes/stores';
|
|
|
|
import DiscussionCounter from '~/notes/components/discussion_counter.vue';
|
|
|
|
import { noteableDataMock, discussionMock, notesDataMock } from '../mock_data';
|
|
|
|
|
|
|
|
describe('DiscussionCounter component', () => {
|
|
|
|
let store;
|
|
|
|
let vm;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
window.mrTabs = {};
|
|
|
|
|
|
|
|
const Component = Vue.extend(DiscussionCounter);
|
|
|
|
|
|
|
|
store = createStore();
|
|
|
|
store.dispatch('setNoteableData', noteableDataMock);
|
|
|
|
store.dispatch('setNotesData', notesDataMock);
|
|
|
|
|
|
|
|
vm = createComponentWithStore(Component, store);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('methods', () => {
|
|
|
|
describe('jumpToFirstUnresolvedDiscussion', () => {
|
|
|
|
it('expands unresolved discussion', () => {
|
2020-01-01 13:55:28 +05:30
|
|
|
window.mrTabs.currentAction = 'show';
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
spyOn(vm, 'expandDiscussion').and.stub();
|
|
|
|
const discussions = [
|
|
|
|
{
|
|
|
|
...discussionMock,
|
|
|
|
id: discussionMock.id,
|
|
|
|
notes: [{ ...discussionMock.notes[0], resolvable: true, resolved: true }],
|
2019-03-02 22:35:43 +05:30
|
|
|
resolved: true,
|
2018-11-08 19:23:39 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
...discussionMock,
|
|
|
|
id: discussionMock.id + 1,
|
|
|
|
notes: [{ ...discussionMock.notes[0], resolvable: true, resolved: false }],
|
2019-03-02 22:35:43 +05:30
|
|
|
resolved: false,
|
2018-11-08 19:23:39 +05:30
|
|
|
},
|
|
|
|
];
|
|
|
|
const firstDiscussionId = discussionMock.id + 1;
|
|
|
|
store.replaceState({
|
|
|
|
...store.state,
|
|
|
|
discussions,
|
|
|
|
});
|
|
|
|
vm.jumpToFirstUnresolvedDiscussion();
|
|
|
|
|
|
|
|
expect(vm.expandDiscussion).toHaveBeenCalledWith({ discussionId: firstDiscussionId });
|
|
|
|
});
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
it('jumps to first unresolved discussion from diff tab if all diff discussions are resolved', () => {
|
|
|
|
window.mrTabs.currentAction = 'diff';
|
|
|
|
spyOn(vm, 'switchToDiscussionsTabAndJumpTo').and.stub();
|
|
|
|
|
|
|
|
const unresolvedId = discussionMock.id + 1;
|
|
|
|
const discussions = [
|
|
|
|
{
|
|
|
|
...discussionMock,
|
|
|
|
id: discussionMock.id,
|
|
|
|
diff_discussion: true,
|
|
|
|
notes: [{ ...discussionMock.notes[0], resolvable: true, resolved: true }],
|
|
|
|
resolved: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
...discussionMock,
|
|
|
|
id: unresolvedId,
|
|
|
|
notes: [{ ...discussionMock.notes[0], resolvable: true, resolved: false }],
|
|
|
|
resolved: false,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
store.replaceState({
|
|
|
|
...store.state,
|
|
|
|
discussions,
|
|
|
|
});
|
|
|
|
vm.jumpToFirstUnresolvedDiscussion();
|
|
|
|
|
|
|
|
expect(vm.switchToDiscussionsTabAndJumpTo).toHaveBeenCalledWith(unresolvedId);
|
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|