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>2023-06-08 00:08:30 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-06-08 00:08:30 +0300
commite0d38e233de6113b51f784452d0f1f805356adaa (patch)
treee7e087fc5413c3b6176793a6f63f0b398640f99a /spec/frontend/diffs
parent9ee2305f46a2b3d1d1e8a1f1182512599a74dbe1 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/diffs')
-rw-r--r--spec/frontend/diffs/components/diff_content_spec.js14
-rw-r--r--spec/frontend/diffs/components/diff_file_header_spec.js27
-rw-r--r--spec/frontend/diffs/components/diff_file_spec.js65
-rw-r--r--spec/frontend/diffs/mock_data/diff_file.js1
-rw-r--r--spec/frontend/diffs/store/actions_spec.js24
-rw-r--r--spec/frontend/diffs/store/getters_spec.js27
-rw-r--r--spec/frontend/diffs/store/mutations_spec.js68
7 files changed, 223 insertions, 3 deletions
diff --git a/spec/frontend/diffs/components/diff_content_spec.js b/spec/frontend/diffs/components/diff_content_spec.js
index fb271433762..39d9255aaf9 100644
--- a/spec/frontend/diffs/components/diff_content_spec.js
+++ b/spec/frontend/diffs/components/diff_content_spec.js
@@ -176,7 +176,12 @@ describe('DiffContent', () => {
getCommentFormForDiffFileGetterMock.mockReturnValue(() => true);
createComponent({
props: {
- diffFile: { ...imageDiffFile, discussions: [{ name: 'discussion-stub ' }] },
+ diffFile: {
+ ...imageDiffFile,
+ discussions: [
+ { name: 'discussion-stub', position: { position_type: IMAGE_DIFF_POSITION_TYPE } },
+ ],
+ },
},
});
@@ -186,7 +191,12 @@ describe('DiffContent', () => {
it('emits saveDiffDiscussion when note-form emits `handleFormUpdate`', () => {
const noteStub = {};
getCommentFormForDiffFileGetterMock.mockReturnValue(() => true);
- const currentDiffFile = { ...imageDiffFile, discussions: [{ name: 'discussion-stub ' }] };
+ const currentDiffFile = {
+ ...imageDiffFile,
+ discussions: [
+ { name: 'discussion-stub', position: { position_type: IMAGE_DIFF_POSITION_TYPE } },
+ ],
+ };
createComponent({
props: {
diffFile: currentDiffFile,
diff --git a/spec/frontend/diffs/components/diff_file_header_spec.js b/spec/frontend/diffs/components/diff_file_header_spec.js
index 900aa8d1469..3f75b086368 100644
--- a/spec/frontend/diffs/components/diff_file_header_spec.js
+++ b/spec/frontend/diffs/components/diff_file_header_spec.js
@@ -18,7 +18,10 @@ import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
import testAction from '../../__helpers__/vuex_action_helper';
import diffDiscussionsMockData from '../mock_data/diff_discussions';
-jest.mock('~/lib/utils/common_utils');
+jest.mock('~/lib/utils/common_utils', () => ({
+ scrollToElement: jest.fn(),
+ isLoggedIn: () => true,
+}));
const diffFile = Object.freeze(
Object.assign(diffDiscussionsMockData.diff_file, {
@@ -47,6 +50,9 @@ describe('DiffFileHeader component', () => {
const diffHasDiscussionsResultMock = jest.fn();
const defaultMockStoreConfig = {
state: {},
+ getters: {
+ getNoteableData: () => ({ current_user: { can_create_note: true } }),
+ },
modules: {
diffs: {
namespaced: true,
@@ -637,4 +643,23 @@ describe('DiffFileHeader component', () => {
},
);
});
+
+ it.each`
+ commentOnFiles | exists | existsText
+ ${false} | ${false} | ${'does not'}
+ ${true} | ${true} | ${'does'}
+ `(
+ '$existsText render comment on files button when commentOnFiles is $commentOnFiles',
+ ({ commentOnFiles, exists }) => {
+ window.gon = { current_user_id: 1 };
+ createComponent({
+ props: {
+ addMergeRequestButtons: true,
+ },
+ options: { provide: { glFeatures: { commentOnFiles } } },
+ });
+
+ expect(wrapper.find('[data-testid="comment-files-button"]').exists()).toEqual(exists);
+ },
+ );
});
diff --git a/spec/frontend/diffs/components/diff_file_spec.js b/spec/frontend/diffs/components/diff_file_spec.js
index 389b192a515..d9c57ed1470 100644
--- a/spec/frontend/diffs/components/diff_file_spec.js
+++ b/spec/frontend/diffs/components/diff_file_spec.js
@@ -553,4 +553,69 @@ describe('DiffFile', () => {
expect(wrapper.find('[data-testid="conflictsAlert"]').exists()).toBe(true);
});
});
+
+ describe('file discussions', () => {
+ it.each`
+ extraProps | exists | existsText
+ ${{}} | ${false} | ${'does not'}
+ ${{ hasCommentForm: false }} | ${false} | ${'does not'}
+ ${{ hasCommentForm: true }} | ${true} | ${'does'}
+ ${{ discussions: [{ id: 1, position: { position_type: 'file' } }] }} | ${true} | ${'does'}
+ ${{ drafts: [{ id: 1 }] }} | ${true} | ${'does'}
+ `(
+ 'discussions wrapper $existsText exist for file with $extraProps',
+ ({ extraProps, exists }) => {
+ const file = {
+ ...getReadableFile(),
+ ...extraProps,
+ };
+
+ ({ wrapper, store } = createComponent({
+ file,
+ options: { provide: { glFeatures: { commentOnFiles: true } } },
+ }));
+
+ expect(wrapper.find('[data-testid="file-discussions"]').exists()).toEqual(exists);
+ },
+ );
+
+ it.each`
+ hasCommentForm | exists | existsText
+ ${false} | ${false} | ${'does not'}
+ ${true} | ${true} | ${'does'}
+ `(
+ 'comment form $existsText exist for hasCommentForm with $hasCommentForm',
+ ({ hasCommentForm, exists }) => {
+ const file = {
+ ...getReadableFile(),
+ hasCommentForm,
+ };
+
+ ({ wrapper, store } = createComponent({
+ file,
+ options: { provide: { glFeatures: { commentOnFiles: true } } },
+ }));
+
+ expect(wrapper.find('[data-testid="file-note-form"]').exists()).toEqual(exists);
+ },
+ );
+
+ it.each`
+ discussions | exists | existsText
+ ${[]} | ${false} | ${'does not'}
+ ${[{ id: 1, position: { position_type: 'file' } }]} | ${true} | ${'does'}
+ `('discussions $existsText exist for $discussions', ({ discussions, exists }) => {
+ const file = {
+ ...getReadableFile(),
+ discussions,
+ };
+
+ ({ wrapper, store } = createComponent({
+ file,
+ options: { provide: { glFeatures: { commentOnFiles: true } } },
+ }));
+
+ expect(wrapper.find('[data-testid="diff-file-discussions"]').exists()).toEqual(exists);
+ });
+ });
});
diff --git a/spec/frontend/diffs/mock_data/diff_file.js b/spec/frontend/diffs/mock_data/diff_file.js
index e0e5778e0d5..eef68100378 100644
--- a/spec/frontend/diffs/mock_data/diff_file.js
+++ b/spec/frontend/diffs/mock_data/diff_file.js
@@ -334,5 +334,6 @@ export const getDiffFileMock = () => ({
},
],
discussions: [],
+ drafts: [],
renderingLines: false,
});
diff --git a/spec/frontend/diffs/store/actions_spec.js b/spec/frontend/diffs/store/actions_spec.js
index f0061ad88d7..7534fe741e7 100644
--- a/spec/frontend/diffs/store/actions_spec.js
+++ b/spec/frontend/diffs/store/actions_spec.js
@@ -1889,4 +1889,28 @@ describe('DiffsStoreActions', () => {
},
);
});
+
+ describe('toggleFileCommentForm', () => {
+ it('commits TOGGLE_FILE_COMMENT_FORM', () => {
+ return testAction(
+ diffActions.toggleFileCommentForm,
+ 'path',
+ {},
+ [{ type: types.TOGGLE_FILE_COMMENT_FORM, payload: 'path' }],
+ [],
+ );
+ });
+ });
+
+ describe('addDraftToFile', () => {
+ it('commits ADD_DRAFT_TO_FILE', () => {
+ return testAction(
+ diffActions.addDraftToFile,
+ { filePath: 'path', draft: 'draft' },
+ {},
+ [{ type: types.ADD_DRAFT_TO_FILE, payload: { filePath: 'path', draft: 'draft' } }],
+ [],
+ );
+ });
+ });
});
diff --git a/spec/frontend/diffs/store/getters_spec.js b/spec/frontend/diffs/store/getters_spec.js
index ed7b6699e2c..8097f0976f6 100644
--- a/spec/frontend/diffs/store/getters_spec.js
+++ b/spec/frontend/diffs/store/getters_spec.js
@@ -188,6 +188,24 @@ describe('Diffs Module Getters', () => {
expect(getters.diffHasExpandedDiscussions(localState)(diffFile)).toEqual(true);
});
+ it('returns true when file discussion is expanded', () => {
+ const diffFile = {
+ discussions: [{ ...discussionMock, expanded: true }],
+ highlighted_diff_lines: [],
+ };
+
+ expect(getters.diffHasExpandedDiscussions(localState)(diffFile)).toEqual(true);
+ });
+
+ it('returns false when file discussion is expanded', () => {
+ const diffFile = {
+ discussions: [{ ...discussionMock, expanded: false }],
+ highlighted_diff_lines: [],
+ };
+
+ expect(getters.diffHasExpandedDiscussions(localState)(diffFile)).toEqual(false);
+ });
+
it('returns false when there are no discussions', () => {
const diffFile = {
parallel_diff_lines: [],
@@ -231,6 +249,15 @@ describe('Diffs Module Getters', () => {
expect(getters.diffHasDiscussions(localState)(diffFile)).toEqual(true);
});
+ it('returns true when file has discussions', () => {
+ const diffFile = {
+ discussions: [discussionMock, discussionMock],
+ highlighted_diff_lines: [],
+ };
+
+ expect(getters.diffHasDiscussions(localState)(diffFile)).toEqual(true);
+ });
+
it('returns false when getDiffFileDiscussions returns no discussions', () => {
const diffFile = {
parallel_diff_lines: [],
diff --git a/spec/frontend/diffs/store/mutations_spec.js b/spec/frontend/diffs/store/mutations_spec.js
index ed8d7397bbc..b089cf22b14 100644
--- a/spec/frontend/diffs/store/mutations_spec.js
+++ b/spec/frontend/diffs/store/mutations_spec.js
@@ -269,6 +269,53 @@ describe('DiffsStoreMutations', () => {
expect(state.diffFiles[0][INLINE_DIFF_LINES_KEY][0].discussions[0].id).toEqual(1);
});
+ it('should add discussions to the given file', () => {
+ const diffPosition = {
+ base_sha: 'ed13df29948c41ba367caa757ab3ec4892509910',
+ head_sha: 'b921914f9a834ac47e6fd9420f78db0f83559130',
+ new_line: null,
+ new_path: '500-lines-4.txt',
+ old_line: 5,
+ old_path: '500-lines-4.txt',
+ start_sha: 'ed13df29948c41ba367caa757ab3ec4892509910',
+ type: 'file',
+ };
+
+ const state = {
+ latestDiff: true,
+ diffFiles: [
+ {
+ file_hash: 'ABC',
+ [INLINE_DIFF_LINES_KEY]: [],
+ discussions: [],
+ },
+ ],
+ };
+ const discussion = {
+ id: 1,
+ line_code: 'ABC_1',
+ diff_discussion: true,
+ resolvable: true,
+ original_position: diffPosition,
+ position: diffPosition,
+ diff_file: {
+ file_hash: state.diffFiles[0].file_hash,
+ },
+ };
+
+ const diffPositionByLineCode = {
+ ABC_1: diffPosition,
+ };
+
+ mutations[types.SET_LINE_DISCUSSIONS_FOR_FILE](state, {
+ discussion,
+ diffPositionByLineCode,
+ });
+
+ expect(state.diffFiles[0].discussions.length).toEqual(1);
+ expect(state.diffFiles[0].discussions[0].id).toEqual(1);
+ });
+
it('should not duplicate discussions on line', () => {
const diffPosition = {
base_sha: 'ed13df29948c41ba367caa757ab3ec4892509910',
@@ -957,4 +1004,25 @@ describe('DiffsStoreMutations', () => {
expect(state.mrReviews).toStrictEqual(newReviews);
});
});
+
+ describe('TOGGLE_FILE_COMMENT_FORM', () => {
+ it('toggles diff files hasCommentForm', () => {
+ const state = { diffFiles: [{ file_path: 'path', hasCommentForm: false }] };
+
+ mutations[types.TOGGLE_FILE_COMMENT_FORM](state, 'path');
+
+ expect(state.diffFiles[0].hasCommentForm).toEqual(true);
+ });
+ });
+
+ describe('ADD_DRAFT_TO_FILE', () => {
+ it('adds draft to diff file', () => {
+ const state = { diffFiles: [{ file_path: 'path', drafts: [] }] };
+
+ mutations[types.ADD_DRAFT_TO_FILE](state, { filePath: 'path', draft: 'test' });
+
+ expect(state.diffFiles[0].drafts.length).toEqual(1);
+ expect(state.diffFiles[0].drafts[0]).toEqual('test');
+ });
+ });
});