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/store')
-rw-r--r--spec/frontend/diffs/store/actions_spec.js38
-rw-r--r--spec/frontend/diffs/store/utils_spec.js54
2 files changed, 74 insertions, 18 deletions
diff --git a/spec/frontend/diffs/store/actions_spec.js b/spec/frontend/diffs/store/actions_spec.js
index bf75f956d7f..87366cdbfc5 100644
--- a/spec/frontend/diffs/store/actions_spec.js
+++ b/spec/frontend/diffs/store/actions_spec.js
@@ -183,11 +183,11 @@ describe('DiffsStoreActions', () => {
beforeEach(() => {
delete noFilesData.diff_files;
-
- mock.onGet(endpointMetadata).reply(200, diffMetadata);
});
it('should fetch diff meta information', () => {
+ mock.onGet(endpointMetadata).reply(200, diffMetadata);
+
return testAction(
diffActions.fetchDiffFilesMeta,
{},
@@ -206,6 +206,40 @@ describe('DiffsStoreActions', () => {
[],
);
});
+
+ it('should show a warning on 404 reponse', async () => {
+ mock.onGet(endpointMetadata).reply(404);
+
+ await testAction(
+ diffActions.fetchDiffFilesMeta,
+ {},
+ { endpointMetadata, diffViewType: 'inline', showWhitespace: true },
+ [{ type: types.SET_LOADING, payload: true }],
+ [],
+ );
+
+ expect(createAlert).toHaveBeenCalledTimes(1);
+ expect(createAlert).toHaveBeenCalledWith({
+ message: expect.stringMatching(
+ 'Building your merge request. Wait a few moments, then refresh this page.',
+ ),
+ variant: 'warning',
+ });
+ });
+
+ it('should show no warning on any other status code', async () => {
+ mock.onGet(endpointMetadata).reply(500);
+
+ await testAction(
+ diffActions.fetchDiffFilesMeta,
+ {},
+ { endpointMetadata, diffViewType: 'inline', showWhitespace: true },
+ [{ type: types.SET_LOADING, payload: true }],
+ [],
+ );
+
+ expect(createAlert).not.toHaveBeenCalled();
+ });
});
describe('fetchCoverageFiles', () => {
diff --git a/spec/frontend/diffs/store/utils_spec.js b/spec/frontend/diffs/store/utils_spec.js
index 3f870a98396..b5c44b084d8 100644
--- a/spec/frontend/diffs/store/utils_spec.js
+++ b/spec/frontend/diffs/store/utils_spec.js
@@ -311,9 +311,14 @@ describe('DiffsStoreUtils', () => {
describe('prepareLineForRenamedFile', () => {
const diffFile = {
file_hash: 'file-hash',
+ brokenSymlink: false,
+ renamed_file: false,
+ added_lines: 1,
+ removed_lines: 1,
};
const lineIndex = 4;
const sourceLine = {
+ line_code: 'abc',
foo: 'test',
rich_text: ' <p>rich</p>', // Note the leading space
};
@@ -328,6 +333,12 @@ describe('DiffsStoreUtils', () => {
hasForm: false,
text: undefined,
alreadyPrepared: true,
+ commentsDisabled: false,
+ problems: {
+ brokenLineCode: false,
+ brokenSymlink: false,
+ fileOnlyMoved: false,
+ },
};
let preppedLine;
@@ -360,24 +371,35 @@ describe('DiffsStoreUtils', () => {
});
it.each`
- brokenSymlink
- ${false}
- ${{}}
- ${'anything except `false`'}
+ brokenSymlink | renamed | added | removed | lineCode | commentsDisabled
+ ${false} | ${false} | ${0} | ${0} | ${'a'} | ${false}
+ ${{}} | ${false} | ${1} | ${1} | ${'a'} | ${true}
+ ${'truthy'} | ${false} | ${1} | ${1} | ${'a'} | ${true}
+ ${false} | ${true} | ${1} | ${1} | ${'a'} | ${false}
+ ${false} | ${true} | ${1} | ${0} | ${'a'} | ${false}
+ ${false} | ${true} | ${0} | ${1} | ${'a'} | ${false}
+ ${false} | ${true} | ${0} | ${0} | ${'a'} | ${true}
`(
- "properly assigns each line's `commentsDisabled` as the same value as the parent file's `brokenSymlink` value (`$brokenSymlink`)",
- ({ brokenSymlink }) => {
- preppedLine = utils.prepareLineForRenamedFile({
- diffViewType: INLINE_DIFF_VIEW_TYPE,
- line: sourceLine,
+ "properly sets a line's `commentsDisabled` to '$commentsDisabled' for file and line settings { brokenSymlink: $brokenSymlink, renamed: $renamed, added: $added, removed: $removed, line_code: $lineCode }",
+ ({ brokenSymlink, renamed, added, removed, lineCode, commentsDisabled }) => {
+ const line = {
+ ...sourceLine,
+ line_code: lineCode,
+ };
+ const file = {
+ ...diffFile,
+ brokenSymlink,
+ renamed_file: renamed,
+ added_lines: added,
+ removed_lines: removed,
+ };
+ const preparedLine = utils.prepareLineForRenamedFile({
index: lineIndex,
- diffFile: {
- ...diffFile,
- brokenSymlink,
- },
+ diffFile: file,
+ line,
});
- expect(preppedLine.commentsDisabled).toStrictEqual(brokenSymlink);
+ expect(preparedLine.commentsDisabled).toBe(commentsDisabled);
},
);
});
@@ -477,7 +499,7 @@ describe('DiffsStoreUtils', () => {
it('adds the `.brokenSymlink` property to each diff file', () => {
preparedDiff.diff_files.forEach((file) => {
- expect(file).toEqual(expect.objectContaining({ brokenSymlink: false }));
+ expect(file).toHaveProperty('brokenSymlink', false);
});
});
@@ -490,7 +512,7 @@ describe('DiffsStoreUtils', () => {
].flatMap((file) => [...file[INLINE_DIFF_LINES_KEY]]);
lines.forEach((line) => {
- expect(line.commentsDisabled).toBe(false);
+ expect(line.problems.brokenSymlink).toBe(false);
});
});
});