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')
-rw-r--r--spec/frontend/diffs/components/commit_item_spec.js4
-rw-r--r--spec/frontend/diffs/components/diff_table_cell_spec.js15
-rw-r--r--spec/frontend/diffs/store/actions_spec.js1
-rw-r--r--spec/frontend/diffs/store/getters_versions_dropdowns_spec.js99
-rw-r--r--spec/frontend/diffs/store/mutations_spec.js67
5 files changed, 152 insertions, 34 deletions
diff --git a/spec/frontend/diffs/components/commit_item_spec.js b/spec/frontend/diffs/components/commit_item_spec.js
index 517d050eb54..6bb3a0dcf21 100644
--- a/spec/frontend/diffs/components/commit_item_spec.js
+++ b/spec/frontend/diffs/components/commit_item_spec.js
@@ -59,9 +59,7 @@ describe('diffs/components/commit_item', () => {
expect(titleElement.text()).toBe(commit.title_html);
});
- // https://gitlab.com/gitlab-org/gitlab/-/issues/209776
- // eslint-disable-next-line jest/no-disabled-tests
- it.skip('renders commit description', () => {
+ it('renders commit description', () => {
const descElement = getDescElement();
const descExpandElement = getDescExpandElement();
diff --git a/spec/frontend/diffs/components/diff_table_cell_spec.js b/spec/frontend/diffs/components/diff_table_cell_spec.js
index 1af0746f3bd..e871d86d901 100644
--- a/spec/frontend/diffs/components/diff_table_cell_spec.js
+++ b/spec/frontend/diffs/components/diff_table_cell_spec.js
@@ -85,15 +85,18 @@ describe('DiffTableCell', () => {
describe('comment button', () => {
it.each`
- showCommentButton | userData | query | expectation
- ${true} | ${TEST_USER} | ${'diff_head=false'} | ${true}
- ${true} | ${TEST_USER} | ${'diff_head=true'} | ${false}
- ${false} | ${TEST_USER} | ${'bogus'} | ${false}
- ${true} | ${null} | ${''} | ${false}
+ showCommentButton | userData | query | mergeRefHeadComments | expectation
+ ${true} | ${TEST_USER} | ${'diff_head=false'} | ${false} | ${true}
+ ${true} | ${TEST_USER} | ${'diff_head=true'} | ${true} | ${true}
+ ${true} | ${TEST_USER} | ${'diff_head=true'} | ${false} | ${false}
+ ${false} | ${TEST_USER} | ${'diff_head=true'} | ${true} | ${false}
+ ${false} | ${TEST_USER} | ${'bogus'} | ${true} | ${false}
+ ${true} | ${null} | ${''} | ${true} | ${false}
`(
'exists is $expectation - with showCommentButton ($showCommentButton) userData ($userData) query ($query)',
- ({ showCommentButton, userData, query, expectation }) => {
+ ({ showCommentButton, userData, query, mergeRefHeadComments, expectation }) => {
store.state.notes.userData = userData;
+ gon.features = { mergeRefHeadComments };
setWindowLocation({ href: `${TEST_HOST}?${query}` });
createComponent({ showCommentButton });
diff --git a/spec/frontend/diffs/store/actions_spec.js b/spec/frontend/diffs/store/actions_spec.js
index 8a1c3e56e5a..ceccce6312f 100644
--- a/spec/frontend/diffs/store/actions_spec.js
+++ b/spec/frontend/diffs/store/actions_spec.js
@@ -466,6 +466,7 @@ describe('DiffsStoreActions', () => {
old_path: 'file2',
line_code: 'ABC_1_1',
position_type: 'text',
+ line_range: null,
},
},
hash: 'ABC_123',
diff --git a/spec/frontend/diffs/store/getters_versions_dropdowns_spec.js b/spec/frontend/diffs/store/getters_versions_dropdowns_spec.js
index 3e5ba66d5e4..0343ef75732 100644
--- a/spec/frontend/diffs/store/getters_versions_dropdowns_spec.js
+++ b/spec/frontend/diffs/store/getters_versions_dropdowns_spec.js
@@ -1,6 +1,9 @@
import * as getters from '~/diffs/store/getters';
import state from '~/diffs/store/modules/diff_state';
-import { DIFF_COMPARE_BASE_VERSION_INDEX } from '~/diffs/constants';
+import {
+ DIFF_COMPARE_BASE_VERSION_INDEX,
+ DIFF_COMPARE_HEAD_VERSION_INDEX,
+} from '~/diffs/constants';
import diffsMockData from '../mock_data/merge_request_diffs';
describe('Compare diff version dropdowns', () => {
@@ -37,47 +40,93 @@ describe('Compare diff version dropdowns', () => {
describe('diffCompareDropdownTargetVersions', () => {
// diffCompareDropdownTargetVersions slices the array at the first position
- // and appends a "base" version which is why we use diffsMockData[1] below
- // This is to display "base" at the end of the target dropdown
- const expectedFirstVersion = {
- ...diffsMockData[1],
- href: expect.any(String),
- versionName: expect.any(String),
+ // and appends a "base" and "head" version at the end of the list so that
+ // "base" and "head" appear at the bottom of the dropdown
+ // this is also why we use diffsMockData[1] for the "first" version
+
+ let expectedFirstVersion;
+ let expectedBaseVersion;
+ let expectedHeadVersion;
+ const originalLocation = window.location;
+
+ const setupTest = includeDiffHeadParam => {
+ const diffHeadParam = includeDiffHeadParam ? '?diff_head=true' : '';
+
+ Object.defineProperty(window, 'location', {
+ writable: true,
+ value: { href: `https://example.gitlab.com${diffHeadParam}` },
+ });
+
+ expectedFirstVersion = {
+ ...diffsMockData[1],
+ href: expect.any(String),
+ versionName: expect.any(String),
+ selected: false,
+ };
+
+ expectedBaseVersion = {
+ versionName: 'baseVersion',
+ version_index: DIFF_COMPARE_BASE_VERSION_INDEX,
+ href: 'basePath',
+ isBase: true,
+ selected: false,
+ };
+
+ expectedHeadVersion = {
+ versionName: 'baseVersion',
+ version_index: DIFF_COMPARE_HEAD_VERSION_INDEX,
+ href: 'headPath',
+ isHead: true,
+ selected: false,
+ };
};
- const expectedBaseVersion = {
- versionName: 'baseVersion',
- version_index: DIFF_COMPARE_BASE_VERSION_INDEX,
- href: 'basePath',
- isBase: true,
+ const assertVersions = targetVersions => {
+ // base and head should be the last two versions in that order
+ const targetBaseVersion = targetVersions[targetVersions.length - 2];
+ const targetHeadVersion = targetVersions[targetVersions.length - 1];
+ expect(targetVersions[0]).toEqual(expectedFirstVersion);
+ expect(targetBaseVersion).toEqual(expectedBaseVersion);
+ expect(targetHeadVersion).toEqual(expectedHeadVersion);
};
+ afterEach(() => {
+ window.location = originalLocation;
+ });
+
it('base version selected', () => {
- expectedFirstVersion.selected = false;
+ setupTest();
expectedBaseVersion.selected = true;
- const targetVersions = getters.diffCompareDropdownTargetVersions(localState, {
- selectedTargetIndex: DIFF_COMPARE_BASE_VERSION_INDEX,
- });
+ const targetVersions = getters.diffCompareDropdownTargetVersions(localState, getters);
+ assertVersions(targetVersions);
+ });
- const lastVersion = targetVersions[targetVersions.length - 1];
- expect(targetVersions[0]).toEqual(expectedFirstVersion);
- expect(lastVersion).toEqual(expectedBaseVersion);
+ it('head version selected', () => {
+ setupTest(true);
+
+ expectedHeadVersion.selected = true;
+
+ const targetVersions = getters.diffCompareDropdownTargetVersions(localState, getters);
+ assertVersions(targetVersions);
});
it('first version selected', () => {
- expectedFirstVersion.selected = true;
- expectedBaseVersion.selected = false;
+ // NOTE: It should not be possible to have both "diff_head=true" and
+ // have anything other than the head version selected, but the user could
+ // manually add "?diff_head=true" to the url. In this instance we still
+ // want the actual selected version to display as "selected"
+ // Passing in "true" here asserts that first version is still selected
+ // even if "diff_head" is present in the url
+ setupTest(true);
+ expectedFirstVersion.selected = true;
localState.startVersion = expectedFirstVersion;
const targetVersions = getters.diffCompareDropdownTargetVersions(localState, {
selectedTargetIndex: expectedFirstVersion.version_index,
});
-
- const lastVersion = targetVersions[targetVersions.length - 1];
- expect(targetVersions[0]).toEqual(expectedFirstVersion);
- expect(lastVersion).toEqual(expectedBaseVersion);
+ assertVersions(targetVersions);
});
});
diff --git a/spec/frontend/diffs/store/mutations_spec.js b/spec/frontend/diffs/store/mutations_spec.js
index c44feaf4b63..858ab5be167 100644
--- a/spec/frontend/diffs/store/mutations_spec.js
+++ b/spec/frontend/diffs/store/mutations_spec.js
@@ -615,6 +615,73 @@ describe('DiffsStoreMutations', () => {
expect(state.diffFiles[0].highlighted_diff_lines[0].discussions.length).toEqual(1);
expect(state.diffFiles[0].highlighted_diff_lines[0].discussions[0].id).toEqual(1);
});
+
+ it('should add discussions by line_codes and positions attributes', () => {
+ 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',
+ };
+
+ const state = {
+ latestDiff: true,
+ diffFiles: [
+ {
+ file_hash: 'ABC',
+ parallel_diff_lines: [
+ {
+ left: {
+ line_code: 'ABC_1',
+ discussions: [],
+ },
+ right: {
+ line_code: 'ABC_1',
+ discussions: [],
+ },
+ },
+ ],
+ highlighted_diff_lines: [
+ {
+ line_code: 'ABC_1',
+ discussions: [],
+ },
+ ],
+ },
+ ],
+ };
+ const discussion = {
+ id: 1,
+ line_code: 'ABC_2',
+ line_codes: ['ABC_1'],
+ diff_discussion: true,
+ resolvable: true,
+ original_position: {},
+ position: {},
+ positions: [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].parallel_diff_lines[0].left.discussions).toHaveLength(1);
+ expect(state.diffFiles[0].parallel_diff_lines[0].left.discussions[0].id).toBe(1);
+
+ expect(state.diffFiles[0].highlighted_diff_lines[0].discussions).toHaveLength(1);
+ expect(state.diffFiles[0].highlighted_diff_lines[0].discussions[0].id).toBe(1);
+ });
});
describe('REMOVE_LINE_DISCUSSIONS', () => {