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:
Diffstat (limited to 'spec/frontend/diffs/components/diff_view_spec.js')
-rw-r--r--spec/frontend/diffs/components/diff_view_spec.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/spec/frontend/diffs/components/diff_view_spec.js b/spec/frontend/diffs/components/diff_view_spec.js
index cfc80e61b30..8778683c135 100644
--- a/spec/frontend/diffs/components/diff_view_spec.js
+++ b/spec/frontend/diffs/components/diff_view_spec.js
@@ -1,10 +1,14 @@
import { shallowMount } from '@vue/test-utils';
import Vue, { nextTick } from 'vue';
import Vuex from 'vuex';
+import { throttle } from 'lodash';
import DiffView from '~/diffs/components/diff_view.vue';
import DiffLine from '~/diffs/components/diff_line.vue';
import { diffCodeQuality } from '../mock_data/diff_code_quality';
+jest.mock('lodash/throttle', () => jest.fn((fn) => fn));
+const lodash = jest.requireActual('lodash');
+
describe('DiffView', () => {
const DiffExpansionCell = { template: `<div/>` };
const DiffRow = { template: `<div/>` };
@@ -51,6 +55,14 @@ describe('DiffView', () => {
return shallowMount(DiffView, { propsData, store, stubs });
};
+ beforeEach(() => {
+ throttle.mockImplementation(lodash.throttle);
+ });
+
+ afterEach(() => {
+ throttle.mockReset();
+ });
+
it('does not render a diff-line component when there is no finding', () => {
const wrapper = createWrapper();
expect(wrapper.findComponent(DiffLine).exists()).toBe(false);
@@ -138,5 +150,18 @@ describe('DiffView', () => {
expect(wrapper.vm.idState.dragStart).toBeNull();
expect(showCommentForm).toHaveBeenCalled();
});
+
+ it('throttles multiple calls to enterdragging', () => {
+ const wrapper = createWrapper({ diffLines: [{}] });
+ const diffRow = getDiffRow(wrapper);
+
+ diffRow.$emit('startdragging', { line: { chunk: 1, index: 1 } });
+ diffRow.$emit('enterdragging', { chunk: 1, index: 2 });
+ diffRow.$emit('enterdragging', { chunk: 1, index: 2 });
+
+ jest.runOnlyPendingTimers();
+
+ expect(setSelectedCommentPosition).toHaveBeenCalledTimes(1);
+ });
});
});