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-07-19 00:10:47 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-07-19 00:10:47 +0300
commit355a4a17ebbeb246e48954462163577ae77f45c0 (patch)
tree81aac8e172af511d87fcb9541508f69508bede84 /spec/frontend/diffs
parent7488eeff6fdf82ee7b926d684a201212b0509cbb (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/diffs')
-rw-r--r--spec/frontend/diffs/components/diff_code_quality_spec.js45
-rw-r--r--spec/frontend/diffs/components/diff_file_spec.js18
-rw-r--r--spec/frontend/diffs/components/diff_inline_findings_spec.js33
-rw-r--r--spec/frontend/diffs/mock_data/diff_code_quality.js12
-rw-r--r--spec/frontend/diffs/store/actions_spec.js54
-rw-r--r--spec/frontend/diffs/store/mutations_spec.js1
-rw-r--r--spec/frontend/diffs/store/utils_spec.js6
7 files changed, 72 insertions, 97 deletions
diff --git a/spec/frontend/diffs/components/diff_code_quality_spec.js b/spec/frontend/diffs/components/diff_code_quality_spec.js
index dda71f362b0..73976ebd713 100644
--- a/spec/frontend/diffs/components/diff_code_quality_spec.js
+++ b/spec/frontend/diffs/components/diff_code_quality_spec.js
@@ -1,22 +1,20 @@
-import { mountExtended, shallowMountExtended } from 'helpers/vue_test_utils_helper';
+import { mountExtended } from 'helpers/vue_test_utils_helper';
import DiffCodeQuality from '~/diffs/components/diff_code_quality.vue';
-import DiffCodeQualityItem from '~/diffs/components/diff_code_quality_item.vue';
+import DiffInlineFindings from '~/diffs/components/diff_inline_findings.vue';
import { NEW_CODE_QUALITY_FINDINGS, NEW_SAST_FINDINGS } from '~/diffs/i18n';
import {
multipleCodeQualityNoSast,
multipleSastNoCodeQuality,
- multipleFindingsArrSastScale,
} from '../mock_data/diff_code_quality';
let wrapper;
-const diffItems = () => wrapper.findAllComponents(DiffCodeQualityItem);
-const findCodeQualityHeading = () => wrapper.findByTestId(`diff-codequality-findings-heading`);
-const findSastHeading = () => wrapper.findByTestId(`diff-sast-findings-heading`);
+const diffInlineFindings = () => wrapper.findComponent(DiffInlineFindings);
+const allDiffInlineFindings = () => wrapper.findAllComponents(DiffInlineFindings);
describe('DiffCodeQuality', () => {
- const createWrapper = (findings, mountFunction = mountExtended) => {
- return mountFunction(DiffCodeQuality, {
+ const createWrapper = (findings) => {
+ return mountExtended(DiffCodeQuality, {
propsData: {
expandedLines: [],
codeQuality: findings.codeQuality,
@@ -30,33 +28,34 @@ describe('DiffCodeQuality', () => {
expect(wrapper.findByTestId('diff-codequality').exists()).toBe(true);
await wrapper.findByTestId('diff-codequality-close').trigger('click');
- expect(wrapper.emitted('hideCodeQualityFindings').length).toBe(1);
+ expect(wrapper.emitted('hideCodeQualityFindings')).toHaveLength(1);
});
- it('renders heading and correct amount of list items for codequality array and their description', () => {
- wrapper = createWrapper(multipleCodeQualityNoSast, shallowMountExtended);
-
- expect(findCodeQualityHeading().text()).toEqual(NEW_CODE_QUALITY_FINDINGS);
+ it('renders diff inline findings component with correct props for codequality array', () => {
+ wrapper = createWrapper(multipleCodeQualityNoSast);
- expect(diffItems()).toHaveLength(multipleCodeQualityNoSast.codeQuality.length);
- expect(diffItems().at(0).props().finding).toEqual(multipleCodeQualityNoSast.codeQuality[0]);
+ expect(diffInlineFindings().props('title')).toBe(NEW_CODE_QUALITY_FINDINGS);
+ expect(diffInlineFindings().props('findings')).toBe(multipleCodeQualityNoSast.codeQuality);
});
it('does not render codeQuality section when codeQuality array is empty', () => {
- wrapper = createWrapper(multipleSastNoCodeQuality, shallowMountExtended);
- expect(findCodeQualityHeading().exists()).toBe(false);
+ wrapper = createWrapper(multipleSastNoCodeQuality);
+
+ expect(diffInlineFindings().props('title')).toBe(NEW_SAST_FINDINGS);
+ expect(allDiffInlineFindings()).toHaveLength(1);
});
it('renders heading and correct amount of list items for sast array and their description', () => {
- wrapper = createWrapper(multipleSastNoCodeQuality, shallowMountExtended);
+ wrapper = createWrapper(multipleSastNoCodeQuality);
- expect(findSastHeading().text()).toEqual(NEW_SAST_FINDINGS);
- expect(diffItems()).toHaveLength(multipleSastNoCodeQuality.sast.length);
- expect(diffItems().at(0).props().finding).toEqual(multipleFindingsArrSastScale[0]);
+ expect(diffInlineFindings().props('title')).toBe(NEW_SAST_FINDINGS);
+ expect(diffInlineFindings().props('findings')).toBe(multipleSastNoCodeQuality.sast);
});
it('does not render sast section when sast array is empty', () => {
- wrapper = createWrapper(multipleCodeQualityNoSast, shallowMountExtended);
- expect(findSastHeading().exists()).toBe(false);
+ wrapper = createWrapper(multipleCodeQualityNoSast);
+
+ expect(diffInlineFindings().props('title')).toBe(NEW_CODE_QUALITY_FINDINGS);
+ expect(allDiffInlineFindings()).toHaveLength(1);
});
});
diff --git a/spec/frontend/diffs/components/diff_file_spec.js b/spec/frontend/diffs/components/diff_file_spec.js
index 9b9a1a84b1d..db6cde883f3 100644
--- a/spec/frontend/diffs/components/diff_file_spec.js
+++ b/spec/frontend/diffs/components/diff_file_spec.js
@@ -546,24 +546,6 @@ describe('DiffFile', () => {
});
});
- it('loads collapsed file on mounted when single file mode is enabled', async () => {
- const file = {
- ...getReadableFile(),
- load_collapsed_diff_url: '/diff_for_path',
- highlighted_diff_lines: [],
- parallel_diff_lines: [],
- viewer: { name: 'collapsed', automaticallyCollapsed: true },
- };
-
- axiosMock.onGet(file.load_collapsed_diff_url).reply(HTTP_STATUS_OK, getReadableFile());
-
- ({ wrapper, store } = createComponent({ file, props: { viewDiffsFileByFile: true } }));
-
- await nextTick();
-
- expect(findLoader(wrapper).exists()).toBe(true);
- });
-
describe('merge conflicts', () => {
it('does not render conflict alert', () => {
const file = {
diff --git a/spec/frontend/diffs/components/diff_inline_findings_spec.js b/spec/frontend/diffs/components/diff_inline_findings_spec.js
new file mode 100644
index 00000000000..9ccfb2a613d
--- /dev/null
+++ b/spec/frontend/diffs/components/diff_inline_findings_spec.js
@@ -0,0 +1,33 @@
+import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
+import DiffInlineFindings from '~/diffs/components/diff_inline_findings.vue';
+import DiffCodeQualityItem from '~/diffs/components/diff_code_quality_item.vue';
+import { NEW_CODE_QUALITY_FINDINGS } from '~/diffs/i18n';
+import { multipleCodeQualityNoSast } from '../mock_data/diff_code_quality';
+
+let wrapper;
+const heading = () => wrapper.findByTestId('diff-inline-findings-heading');
+const diffCodeQualityItems = () => wrapper.findAllComponents(DiffCodeQualityItem);
+
+describe('DiffInlineFindings', () => {
+ const createWrapper = () => {
+ return shallowMountExtended(DiffInlineFindings, {
+ propsData: {
+ title: NEW_CODE_QUALITY_FINDINGS,
+ findings: multipleCodeQualityNoSast.codeQuality,
+ },
+ });
+ };
+
+ it('renders the title correctly', () => {
+ wrapper = createWrapper();
+ expect(heading().text()).toBe(NEW_CODE_QUALITY_FINDINGS);
+ });
+
+ it('renders the correct number of DiffCodeQualityItem components with correct props', () => {
+ wrapper = createWrapper();
+ expect(diffCodeQualityItems()).toHaveLength(multipleCodeQualityNoSast.codeQuality.length);
+ expect(diffCodeQualityItems().wrappers[0].props('finding')).toEqual(
+ wrapper.props('findings')[0],
+ );
+ });
+});
diff --git a/spec/frontend/diffs/mock_data/diff_code_quality.js b/spec/frontend/diffs/mock_data/diff_code_quality.js
index 83fc5707e5b..5b9ed538e01 100644
--- a/spec/frontend/diffs/mock_data/diff_code_quality.js
+++ b/spec/frontend/diffs/mock_data/diff_code_quality.js
@@ -3,31 +3,37 @@ export const multipleFindingsArrCodeQualityScale = [
severity: 'minor',
description: 'mocked minor Issue',
line: 2,
+ scale: 'codeQuality',
},
{
severity: 'major',
description: 'mocked major Issue',
line: 3,
+ scale: 'codeQuality',
},
{
severity: 'info',
description: 'mocked info Issue',
line: 3,
+ scale: 'codeQuality',
},
{
severity: 'critical',
description: 'mocked critical Issue',
line: 3,
+ scale: 'codeQuality',
},
{
severity: 'blocker',
description: 'mocked blocker Issue',
line: 3,
+ scale: 'codeQuality',
},
{
severity: 'unknown',
description: 'mocked unknown Issue',
line: 3,
+ scale: 'codeQuality',
},
];
@@ -36,31 +42,37 @@ export const multipleFindingsArrSastScale = [
severity: 'low',
description: 'mocked low Issue',
line: 2,
+ scale: 'sast',
},
{
severity: 'medium',
description: 'mocked medium Issue',
line: 3,
+ scale: 'sast',
},
{
severity: 'info',
description: 'mocked info Issue',
line: 3,
+ scale: 'sast',
},
{
severity: 'high',
description: 'mocked high Issue',
line: 3,
+ scale: 'sast',
},
{
severity: 'critical',
description: 'mocked critical Issue',
line: 3,
+ scale: 'sast',
},
{
severity: 'unknown',
description: 'mocked unknown Issue',
line: 3,
+ scale: 'sast',
},
];
diff --git a/spec/frontend/diffs/store/actions_spec.js b/spec/frontend/diffs/store/actions_spec.js
index 963346a34b6..bbe748b8e1f 100644
--- a/spec/frontend/diffs/store/actions_spec.js
+++ b/spec/frontend/diffs/store/actions_spec.js
@@ -365,7 +365,7 @@ describe('DiffsStoreActions', () => {
{ type: types.SET_RETRIEVING_BATCHES, payload: false },
{ type: types.SET_BATCH_LOADING_STATE, payload: 'error' },
],
- [{ type: 'startRenderDiffsQueue' }, { type: 'startRenderDiffsQueue' }],
+ [],
);
});
});
@@ -664,41 +664,6 @@ describe('DiffsStoreActions', () => {
});
});
- describe('startRenderDiffsQueue', () => {
- it('should set all files to RENDER_FILE', () => {
- const state = {
- diffFiles: [
- {
- id: 1,
- renderIt: false,
- viewer: {
- automaticallyCollapsed: false,
- },
- },
- {
- id: 2,
- renderIt: false,
- viewer: {
- automaticallyCollapsed: false,
- },
- },
- ],
- };
-
- const pseudoCommit = (commitType, file) => {
- expect(commitType).toBe(types.RENDER_FILE);
- Object.assign(file, {
- renderIt: true,
- });
- };
-
- diffActions.startRenderDiffsQueue({ state, commit: pseudoCommit });
-
- expect(state.diffFiles[0].renderIt).toBe(true);
- expect(state.diffFiles[1].renderIt).toBe(true);
- });
- });
-
describe('setInlineDiffViewType', () => {
it('should set diff view type to inline and also set the cookie properly', async () => {
await testAction(
@@ -1286,12 +1251,11 @@ describe('DiffsStoreActions', () => {
$emit = jest.spyOn(eventHub, '$emit');
});
- it('renders and expands file for the given discussion id', () => {
+ it('expands the file for the given discussion id', () => {
const localState = state({ collapsed: true, renderIt: false });
diffActions.renderFileForDiscussionId({ rootState, state: localState, commit }, '123');
- expect(commit).toHaveBeenCalledWith('RENDER_FILE', localState.diffFiles[0]);
expect($emit).toHaveBeenCalledTimes(1);
expect(commonUtils.scrollToElement).toHaveBeenCalledTimes(1);
});
@@ -1378,18 +1342,6 @@ describe('DiffsStoreActions', () => {
});
});
- describe('setRenderIt', () => {
- it('commits RENDER_FILE', () => {
- return testAction(
- diffActions.setRenderIt,
- 'file',
- {},
- [{ type: types.RENDER_FILE, payload: 'file' }],
- [],
- );
- });
- });
-
describe('receiveFullDiffError', () => {
it('updates state with the file that did not load', () => {
return testAction(
@@ -1514,7 +1466,7 @@ describe('DiffsStoreActions', () => {
payload: { filePath: testFilePath, lines: [preparedLine, preparedLine] },
},
],
- [{ type: 'startRenderDiffsQueue' }],
+ [],
);
},
);
diff --git a/spec/frontend/diffs/store/mutations_spec.js b/spec/frontend/diffs/store/mutations_spec.js
index 4f9534ed5db..274cb40dac8 100644
--- a/spec/frontend/diffs/store/mutations_spec.js
+++ b/spec/frontend/diffs/store/mutations_spec.js
@@ -105,7 +105,6 @@ describe('DiffsStoreMutations', () => {
mutations[types.SET_DIFF_DATA_BATCH](state, diffMock);
- expect(state.diffFiles[0].renderIt).toEqual(true);
expect(state.diffFiles[0].collapsed).toEqual(false);
expect(state.treeEntries[mockFile.file_path].diffLoaded).toBe(true);
});
diff --git a/spec/frontend/diffs/store/utils_spec.js b/spec/frontend/diffs/store/utils_spec.js
index 888df06d6b9..117ed56e347 100644
--- a/spec/frontend/diffs/store/utils_spec.js
+++ b/spec/frontend/diffs/store/utils_spec.js
@@ -437,7 +437,7 @@ describe('DiffsStoreUtils', () => {
});
});
- it('sets the renderIt and collapsed attribute on files', () => {
+ it('sets the collapsed attribute on files', () => {
const checkLine = preparedDiff.diff_files[0][INLINE_DIFF_LINES_KEY][0];
expect(checkLine.discussions.length).toBe(0);
@@ -448,7 +448,6 @@ describe('DiffsStoreUtils', () => {
expect(firstChar).not.toBe('+');
expect(firstChar).not.toBe('-');
- expect(preparedDiff.diff_files[0].renderIt).toBe(true);
expect(preparedDiff.diff_files[0].collapsed).toBe(false);
});
@@ -529,8 +528,7 @@ describe('DiffsStoreUtils', () => {
preparedDiffFiles = utils.prepareDiffData({ diff: mock, meta: true });
});
- it('sets the renderIt and collapsed attribute on files', () => {
- expect(preparedDiffFiles[0].renderIt).toBe(true);
+ it('sets the collapsed attribute on files', () => {
expect(preparedDiffFiles[0].collapsed).toBeUndefined();
});