2021-06-08 01:23:25 +05:30
|
|
|
import Vue from 'vue';
|
|
|
|
import Vuex from 'vuex';
|
|
|
|
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
|
|
|
|
import PreviewDropdown from '~/batch_comments/components/preview_dropdown.vue';
|
|
|
|
|
|
|
|
Vue.use(Vuex);
|
|
|
|
|
|
|
|
let wrapper;
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
const setCurrentFileHash = jest.fn();
|
2021-06-08 01:23:25 +05:30
|
|
|
const scrollToDraft = jest.fn();
|
|
|
|
|
|
|
|
function factory({ viewDiffsFileByFile = false, draftsCount = 1, sortedDrafts = [] } = {}) {
|
|
|
|
const store = new Vuex.Store({
|
|
|
|
modules: {
|
|
|
|
diffs: {
|
|
|
|
namespaced: true,
|
|
|
|
actions: {
|
2021-12-11 22:18:48 +05:30
|
|
|
setCurrentFileHash,
|
2021-06-08 01:23:25 +05:30
|
|
|
},
|
|
|
|
state: {
|
|
|
|
viewDiffsFileByFile,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
batchComments: {
|
|
|
|
namespaced: true,
|
|
|
|
actions: { scrollToDraft },
|
|
|
|
getters: { draftsCount: () => draftsCount, sortedDrafts: () => sortedDrafts },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper = shallowMountExtended(PreviewDropdown, {
|
|
|
|
store,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('Batch comments preview dropdown', () => {
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('clicking draft', () => {
|
|
|
|
it('it toggles active file when viewDiffsFileByFile is true', async () => {
|
|
|
|
factory({
|
|
|
|
viewDiffsFileByFile: true,
|
|
|
|
sortedDrafts: [{ id: 1, file_hash: 'hash' }],
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper.findByTestId('preview-item').vm.$emit('click');
|
|
|
|
|
|
|
|
await Vue.nextTick();
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
expect(setCurrentFileHash).toHaveBeenCalledWith(expect.anything(), 'hash');
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(scrollToDraft).toHaveBeenCalledWith(expect.anything(), { id: 1, file_hash: 'hash' });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls scrollToDraft', async () => {
|
|
|
|
factory({
|
|
|
|
viewDiffsFileByFile: false,
|
|
|
|
sortedDrafts: [{ id: 1 }],
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper.findByTestId('preview-item').vm.$emit('click');
|
|
|
|
|
|
|
|
await Vue.nextTick();
|
|
|
|
|
|
|
|
expect(scrollToDraft).toHaveBeenCalledWith(expect.anything(), { id: 1 });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|