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-05-22 12:08:09 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-05-22 12:08:09 +0300
commit4a3ba3e5f261eb09e6b2b4fd44373e7a1c454a72 (patch)
tree1a94467252ebcc5575c7de6a3590360ce05b9967 /spec/frontend/ide
parent707c0eca50cf9a5290806ce637be30f4c7288def (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/ide')
-rw-r--r--spec/frontend/ide/components/repo_editor_spec.js28
-rw-r--r--spec/frontend/ide/stores/utils_spec.js25
-rw-r--r--spec/frontend/ide/utils_spec.js43
3 files changed, 61 insertions, 35 deletions
diff --git a/spec/frontend/ide/components/repo_editor_spec.js b/spec/frontend/ide/components/repo_editor_spec.js
index af29e172332..913c4f3747d 100644
--- a/spec/frontend/ide/components/repo_editor_spec.js
+++ b/spec/frontend/ide/components/repo_editor_spec.js
@@ -283,15 +283,25 @@ describe('RepoEditor', () => {
expect(vm.model.events.size).toBe(2);
});
- it('updates state when model content changed', done => {
- vm.model.setValue('testing 123\n');
-
- setImmediate(() => {
- expect(vm.file.content).toBe('testing 123\n');
-
- done();
- });
- });
+ it.each`
+ insertFinalNewline | input | eol | output
+ ${true} | ${'testing 123\n'} | ${'\n'} | ${'testing 123\n'}
+ ${true} | ${'testing 123'} | ${'\n'} | ${'testing 123\n'}
+ ${false} | ${'testing 123'} | ${'\n'} | ${'testing 123'}
+ ${true} | ${'testing 123'} | ${'\r\n'} | ${'testing 123\r\n'}
+ ${false} | ${'testing 123'} | ${'\r\n'} | ${'testing 123'}
+ `(
+ 'updates state with "$output" if `this.insertFinalNewline` is $insertFinalNewline',
+ ({ insertFinalNewline, input, eol, output }) => {
+ jest.spyOn(vm.model.getModel(), 'getEOL').mockReturnValue(eol);
+
+ vm.addFinalNewline = insertFinalNewline;
+
+ vm.model.setValue(input);
+
+ expect(vm.file.content).toBe(output);
+ },
+ );
it('sets head model as staged file', () => {
jest.spyOn(vm.editor, 'createModel');
diff --git a/spec/frontend/ide/stores/utils_spec.js b/spec/frontend/ide/stores/utils_spec.js
index b87f6c1f05a..da9ce916017 100644
--- a/spec/frontend/ide/stores/utils_spec.js
+++ b/spec/frontend/ide/stores/utils_spec.js
@@ -661,31 +661,6 @@ describe('Multi-file store utils', () => {
});
});
- describe('addFinalNewlineIfNeeded', () => {
- it('adds a newline if it doesnt already exist', () => {
- [
- {
- input: 'some text',
- output: 'some text\n',
- },
- {
- input: 'some text\n',
- output: 'some text\n',
- },
- {
- input: 'some text\n\n',
- output: 'some text\n\n',
- },
- {
- input: 'some\n text',
- output: 'some\n text\n',
- },
- ].forEach(({ input, output }) => {
- expect(utils.addFinalNewlineIfNeeded(input)).toEqual(output);
- });
- });
- });
-
describe('extractMarkdownImagesFromEntries', () => {
let mdFile;
let entries;
diff --git a/spec/frontend/ide/utils_spec.js b/spec/frontend/ide/utils_spec.js
index f689314567a..4ae440ff09e 100644
--- a/spec/frontend/ide/utils_spec.js
+++ b/spec/frontend/ide/utils_spec.js
@@ -1,4 +1,10 @@
-import { isTextFile, registerLanguages, trimPathComponents } from '~/ide/utils';
+import {
+ isTextFile,
+ registerLanguages,
+ trimPathComponents,
+ addFinalNewline,
+ getPathParents,
+} from '~/ide/utils';
import { languages } from 'monaco-editor';
describe('WebIDE utils', () => {
@@ -148,4 +154,39 @@ describe('WebIDE utils', () => {
]);
});
});
+
+ describe('addFinalNewline', () => {
+ it.each`
+ input | output
+ ${'some text'} | ${'some text\n'}
+ ${'some text\n'} | ${'some text\n'}
+ ${'some text\n\n'} | ${'some text\n\n'}
+ ${'some\n text'} | ${'some\n text\n'}
+ `('adds a newline if it doesnt already exist for input: $input', ({ input, output }) => {
+ expect(addFinalNewline(input)).toEqual(output);
+ });
+
+ it.each`
+ input | output
+ ${'some text'} | ${'some text\r\n'}
+ ${'some text\r\n'} | ${'some text\r\n'}
+ ${'some text\n'} | ${'some text\n\r\n'}
+ ${'some text\r\n\r\n'} | ${'some text\r\n\r\n'}
+ ${'some\r\n text'} | ${'some\r\n text\r\n'}
+ `('works with CRLF newline style; input: $input', ({ input, output }) => {
+ expect(addFinalNewline(input, '\r\n')).toEqual(output);
+ });
+ });
+
+ describe('getPathParents', () => {
+ it.each`
+ path | parents
+ ${'foo/bar/baz/index.md'} | ${['foo/bar/baz', 'foo/bar', 'foo']}
+ ${'foo/bar/baz'} | ${['foo/bar', 'foo']}
+ ${'index.md'} | ${[]}
+ ${'path with/spaces to/something.md'} | ${['path with/spaces to', 'path with']}
+ `('gets all parent directory names for path: $path', ({ path, parents }) => {
+ expect(getPathParents(path)).toEqual(parents);
+ });
+ });
});