2022-04-04 11:22:00 +05:30
|
|
|
import Vue, { nextTick } from 'vue';
|
2021-06-08 01:23:25 +05:30
|
|
|
import Vuex from 'vuex';
|
2023-05-27 22:25:52 +05:30
|
|
|
import { mount } from '@vue/test-utils';
|
2022-08-13 15:12:31 +05:30
|
|
|
import { TEST_HOST } from 'helpers/test_constants';
|
|
|
|
import { visitUrl } from '~/lib/utils/url_utility';
|
2021-06-08 01:23:25 +05:30
|
|
|
import PreviewDropdown from '~/batch_comments/components/preview_dropdown.vue';
|
2023-04-23 21:23:45 +05:30
|
|
|
import PreviewItem from '~/batch_comments/components/preview_item.vue';
|
2021-06-08 01:23:25 +05:30
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
jest.mock('~/lib/utils/url_utility', () => ({
|
|
|
|
visitUrl: jest.fn(),
|
|
|
|
setUrlParams: jest.requireActual('~/lib/utils/url_utility').setUrlParams,
|
|
|
|
}));
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
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();
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
const findPreviewItem = () => wrapper.findComponent(PreviewItem);
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
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 },
|
|
|
|
},
|
2022-08-13 15:12:31 +05:30
|
|
|
notes: {
|
|
|
|
getters: {
|
|
|
|
getNoteableData: () => ({ diff_head_sha: '123' }),
|
|
|
|
},
|
|
|
|
},
|
2021-06-08 01:23:25 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
wrapper = mount(PreviewDropdown, {
|
2021-06-08 01:23:25 +05:30
|
|
|
store,
|
2023-05-27 22:25:52 +05:30
|
|
|
stubs: {
|
|
|
|
PreviewItem: true,
|
|
|
|
},
|
2021-06-08 01:23:25 +05:30
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('Batch comments preview dropdown', () => {
|
|
|
|
describe('clicking draft', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
it('toggles active file when viewDiffsFileByFile is true', async () => {
|
2021-06-08 01:23:25 +05:30
|
|
|
factory({
|
|
|
|
viewDiffsFileByFile: true,
|
|
|
|
sortedDrafts: [{ id: 1, file_hash: 'hash' }],
|
|
|
|
});
|
2023-05-27 22:25:52 +05:30
|
|
|
findPreviewItem().trigger('click');
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2021-06-08 01:23:25 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
expect(setCurrentFileHash).toHaveBeenCalledWith(expect.anything(), 'hash');
|
2023-05-27 22:25:52 +05:30
|
|
|
|
|
|
|
await nextTick();
|
2023-04-23 21:23:45 +05:30
|
|
|
expect(scrollToDraft).toHaveBeenCalledWith(
|
|
|
|
expect.anything(),
|
|
|
|
expect.objectContaining({ id: 1, file_hash: 'hash' }),
|
|
|
|
);
|
2021-06-08 01:23:25 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('calls scrollToDraft', async () => {
|
|
|
|
factory({
|
|
|
|
viewDiffsFileByFile: false,
|
|
|
|
sortedDrafts: [{ id: 1 }],
|
|
|
|
});
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
findPreviewItem().trigger('click');
|
2021-06-08 01:23:25 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2021-06-08 01:23:25 +05:30
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
expect(scrollToDraft).toHaveBeenCalledWith(
|
|
|
|
expect.anything(),
|
|
|
|
expect.objectContaining({ id: 1 }),
|
|
|
|
);
|
2021-06-08 01:23:25 +05:30
|
|
|
});
|
2022-08-13 15:12:31 +05:30
|
|
|
|
|
|
|
it('changes window location to navigate to commit', async () => {
|
|
|
|
factory({
|
|
|
|
viewDiffsFileByFile: false,
|
|
|
|
sortedDrafts: [{ id: 1, position: { head_sha: '1234' } }],
|
|
|
|
});
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
findPreviewItem().trigger('click');
|
2022-08-13 15:12:31 +05:30
|
|
|
|
|
|
|
await nextTick();
|
|
|
|
|
|
|
|
expect(scrollToDraft).not.toHaveBeenCalled();
|
|
|
|
expect(visitUrl).toHaveBeenCalledWith(`${TEST_HOST}/?commit_id=1234#note_1`);
|
|
|
|
});
|
2021-06-08 01:23:25 +05:30
|
|
|
});
|
|
|
|
});
|