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>2020-01-10 18:07:47 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-10 18:07:47 +0300
commit8b1228b0d409d7751f01d9fb72ebfbbf62399486 (patch)
tree1b4126fe48d7666a90c0d7ee26230cf8379b6410 /spec/frontend
parent96b0c1245c93585a8b0fe23e22306d32ff4e4905 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
-rw-r--r--spec/frontend/ide/stores/actions/file_spec.js68
-rw-r--r--spec/frontend/ide/stores/mutations/file_spec.js59
-rw-r--r--spec/frontend/repository/utils/readme_spec.js43
3 files changed, 126 insertions, 44 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');
});
});
diff --git a/spec/frontend/repository/utils/readme_spec.js b/spec/frontend/repository/utils/readme_spec.js
index 6b7876c8947..1b275de86c3 100644
--- a/spec/frontend/repository/utils/readme_spec.js
+++ b/spec/frontend/repository/utils/readme_spec.js
@@ -1,33 +1,38 @@
import { readmeFile } from '~/repository/utils/readme';
describe('readmeFile', () => {
- describe('markdown files', () => {
- it('returns markdown file', () => {
- expect(readmeFile([{ name: 'README' }, { name: 'README.md' }])).toEqual({
- name: 'README.md',
- });
+ it('prefers README with markup over plain text README', () => {
+ expect(readmeFile([{ name: 'README' }, { name: 'README.md' }])).toEqual({
+ name: 'README.md',
+ });
+ });
- expect(readmeFile([{ name: 'README' }, { name: 'index.md' }])).toEqual({
- name: 'index.md',
- });
+ it('is case insensitive', () => {
+ expect(readmeFile([{ name: 'README' }, { name: 'readme.rdoc' }])).toEqual({
+ name: 'readme.rdoc',
});
});
- describe('plain files', () => {
- it('returns plain file', () => {
- expect(readmeFile([{ name: 'README' }, { name: 'TEST.md' }])).toEqual({
- name: 'README',
- });
+ it('returns the first README found', () => {
+ expect(readmeFile([{ name: 'INDEX.adoc' }, { name: 'README.md' }])).toEqual({
+ name: 'INDEX.adoc',
+ });
+ });
- expect(readmeFile([{ name: 'readme' }, { name: 'TEST.md' }])).toEqual({
- name: 'readme',
- });
+ it('expects extension to be separated by dot', () => {
+ expect(readmeFile([{ name: 'readmeXorg' }, { name: 'index.org' }])).toEqual({
+ name: 'index.org',
});
});
- describe('non-previewable file', () => {
- it('returns undefined', () => {
- expect(readmeFile([{ name: 'index.js' }, { name: 'TEST.md' }])).toBe(undefined);
+ it('returns plain text README when there is no README with markup', () => {
+ expect(readmeFile([{ name: 'README' }, { name: 'NOT_README.md' }])).toEqual({
+ name: 'README',
});
});
+
+ it('returns undefined when there are no appropriate files', () => {
+ expect(readmeFile([{ name: 'index.js' }, { name: 'md.README' }])).toBe(undefined);
+ expect(readmeFile([])).toBe(undefined);
+ });
});