summaryrefslogtreecommitdiff
path: root/spec/frontend/ide
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-10 15:07:47 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-10 15:07:47 +0000
commit8b1228b0d409d7751f01d9fb72ebfbbf62399486 (patch)
tree1b4126fe48d7666a90c0d7ee26230cf8379b6410 /spec/frontend/ide
parent96b0c1245c93585a8b0fe23e22306d32ff4e4905 (diff)
downloadgitlab-ce-8b1228b0d409d7751f01d9fb72ebfbbf62399486.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/ide')
-rw-r--r--spec/frontend/ide/stores/actions/file_spec.js68
-rw-r--r--spec/frontend/ide/stores/mutations/file_spec.js59
2 files changed, 102 insertions, 25 deletions
diff --git a/spec/frontend/ide/stores/actions/file_spec.js b/spec/frontend/ide/stores/actions/file_spec.js
index 8ba7b554f43..2d72ae770ab 100644
--- a/spec/frontend/ide/stores/actions/file_spec.js
+++ b/spec/frontend/ide/stores/actions/file_spec.js
@@ -202,6 +202,53 @@ describe('IDE store file actions', () => {
};
});
+ describe('call to service', () => {
+ const callExpectation = serviceCalled => {
+ store.dispatch('getFileData', { path: localFile.path });
+
+ if (serviceCalled) {
+ expect(service.getFileData).toHaveBeenCalled();
+ } else {
+ expect(service.getFileData).not.toHaveBeenCalled();
+ }
+ };
+
+ beforeEach(() => {
+ service.getFileData.mockImplementation(() => new Promise(() => {}));
+ });
+
+ it("isn't called if file.raw exists", () => {
+ localFile.raw = 'raw data';
+
+ callExpectation(false);
+ });
+
+ it("isn't called if file is a tempFile", () => {
+ localFile.raw = '';
+ localFile.tempFile = true;
+
+ callExpectation(false);
+ });
+
+ it('is called if file is a tempFile but also renamed', () => {
+ localFile.raw = '';
+ localFile.tempFile = true;
+ localFile.prevPath = 'old_path';
+
+ callExpectation(true);
+ });
+
+ it('is called if tempFile but file was deleted and readded', () => {
+ localFile.raw = '';
+ localFile.tempFile = true;
+ localFile.prevPath = 'old_path';
+
+ store.state.stagedFiles = [{ ...localFile, deleted: true }];
+
+ callExpectation(true);
+ });
+ });
+
describe('success', () => {
beforeEach(() => {
mock.onGet(`${RELATIVE_URL_ROOT}/test/test/7297abc/${localFile.path}`).replyOnce(
@@ -332,10 +379,10 @@ describe('IDE store file actions', () => {
mock.onGet(`${RELATIVE_URL_ROOT}/test/test/7297abc/${localFile.path}`).networkError();
});
- it('dispatches error action', done => {
+ it('dispatches error action', () => {
const dispatch = jest.fn();
- actions
+ return actions
.getFileData(
{ state: store.state, commit() {}, dispatch, getters: store.getters },
{ path: localFile.path },
@@ -350,10 +397,7 @@ describe('IDE store file actions', () => {
makeFileActive: true,
},
});
-
- done();
- })
- .catch(done.fail);
+ });
});
});
});
@@ -446,12 +490,14 @@ describe('IDE store file actions', () => {
mock.onGet(/(.*)/).networkError();
});
- it('dispatches error action', done => {
+ it('dispatches error action', () => {
const dispatch = jest.fn();
- actions
- .getRawFileData({ state: store.state, commit() {}, dispatch }, { path: tmpFile.path })
- .then(done.fail)
+ return actions
+ .getRawFileData(
+ { state: store.state, commit() {}, dispatch, getters: store.getters },
+ { path: tmpFile.path },
+ )
.catch(() => {
expect(dispatch).toHaveBeenCalledWith('setErrorMessage', {
text: 'An error occurred whilst loading the file content.',
@@ -461,8 +507,6 @@ describe('IDE store file actions', () => {
path: tmpFile.path,
},
});
-
- done();
});
});
});
diff --git a/spec/frontend/ide/stores/mutations/file_spec.js b/spec/frontend/ide/stores/mutations/file_spec.js
index 8cb386d27e5..cd308ee9991 100644
--- a/spec/frontend/ide/stores/mutations/file_spec.js
+++ b/spec/frontend/ide/stores/mutations/file_spec.js
@@ -11,7 +11,7 @@ describe('IDE store file mutations', () => {
beforeEach(() => {
localStore = createStore();
localState = localStore.state;
- localFile = { ...file(), type: 'blob' };
+ localFile = { ...file('file'), type: 'blob', content: 'original' };
localState.entries[localFile.path] = localFile;
});
@@ -139,35 +139,68 @@ describe('IDE store file mutations', () => {
});
describe('SET_FILE_RAW_DATA', () => {
- it('sets raw data', () => {
+ const callMutationForFile = f => {
mutations.SET_FILE_RAW_DATA(localState, {
- file: localFile,
+ file: f,
raw: 'testing',
+ fileDeletedAndReadded: localStore.getters.isFileDeletedAndReadded(localFile.path),
});
+ };
+
+ it('sets raw data', () => {
+ callMutationForFile(localFile);
expect(localFile.raw).toBe('testing');
});
+ it('sets raw data to stagedFile if file was deleted and readded', () => {
+ localState.stagedFiles = [{ ...localFile, deleted: true }];
+ localFile.tempFile = true;
+
+ callMutationForFile(localFile);
+
+ expect(localFile.raw).toBeFalsy();
+ expect(localState.stagedFiles[0].raw).toBe('testing');
+ });
+
+ it("sets raw data to a file's content if tempFile is empty", () => {
+ localFile.tempFile = true;
+ localFile.content = '';
+
+ callMutationForFile(localFile);
+
+ expect(localFile.raw).toBeFalsy();
+ expect(localFile.content).toBe('testing');
+ });
+
it('adds raw data to open pending file', () => {
localState.openFiles.push({ ...localFile, pending: true });
- mutations.SET_FILE_RAW_DATA(localState, {
- file: localFile,
- raw: 'testing',
- });
+ callMutationForFile(localFile);
expect(localState.openFiles[0].raw).toBe('testing');
});
- it('does not add raw data to open pending tempFile file', () => {
- localState.openFiles.push({ ...localFile, pending: true, tempFile: true });
+ it('sets raw to content of a renamed tempFile', () => {
+ localFile.tempFile = true;
+ localFile.prevPath = 'old_path';
+ localState.openFiles.push({ ...localFile, pending: true });
- mutations.SET_FILE_RAW_DATA(localState, {
- file: localFile,
- raw: 'testing',
- });
+ callMutationForFile(localFile);
expect(localState.openFiles[0].raw).not.toBe('testing');
+ expect(localState.openFiles[0].content).toBe('testing');
+ });
+
+ it('adds raw data to a staged deleted file if unstaged change has a tempFile of the same name', () => {
+ localFile.tempFile = true;
+ localState.openFiles.push({ ...localFile, pending: true });
+ localState.stagedFiles = [{ ...localFile, deleted: true }];
+
+ callMutationForFile(localFile);
+
+ expect(localFile.raw).toBeFalsy();
+ expect(localState.stagedFiles[0].raw).toBe('testing');
});
});