Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-05-07 18:10:39 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-05-07 18:10:39 +0300
commit05b83be3ee097da8e71c8655d8f9f2c179cc3f7c (patch)
treedb08678678565e8e072eeff47bf51c78f6c3d7b0 /spec/frontend/batch_comments/components/preview_dropdown_spec.js
parent53f456b167f19877d663ee6ed510673cebee0f91 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/batch_comments/components/preview_dropdown_spec.js')
-rw-r--r--spec/frontend/batch_comments/components/preview_dropdown_spec.js71
1 files changed, 71 insertions, 0 deletions
diff --git a/spec/frontend/batch_comments/components/preview_dropdown_spec.js b/spec/frontend/batch_comments/components/preview_dropdown_spec.js
new file mode 100644
index 00000000000..41be04d0b7e
--- /dev/null
+++ b/spec/frontend/batch_comments/components/preview_dropdown_spec.js
@@ -0,0 +1,71 @@
+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;
+
+const toggleActiveFileByHash = jest.fn();
+const scrollToDraft = jest.fn();
+
+function factory({ viewDiffsFileByFile = false, draftsCount = 1, sortedDrafts = [] } = {}) {
+ const store = new Vuex.Store({
+ modules: {
+ diffs: {
+ namespaced: true,
+ actions: {
+ toggleActiveFileByHash,
+ },
+ 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();
+
+ expect(toggleActiveFileByHash).toHaveBeenCalledWith(expect.anything(), 'hash');
+ 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 });
+ });
+ });
+});