diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-01 15:08:28 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-01 15:08:28 +0300 |
commit | 65f197cdb6f7732e6c56433483a17f50d98b48f0 (patch) | |
tree | 2e016797b8383a126a8d341f5897743af406bd57 /spec/frontend/ide/utils_spec.js | |
parent | c6e6762bbf9fa3e38f37a886237c6e920f6c409c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/ide/utils_spec.js')
-rw-r--r-- | spec/frontend/ide/utils_spec.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/spec/frontend/ide/utils_spec.js b/spec/frontend/ide/utils_spec.js index 0b46e2cc02f..15baeca7f36 100644 --- a/spec/frontend/ide/utils_spec.js +++ b/spec/frontend/ide/utils_spec.js @@ -5,6 +5,8 @@ import { insertFinalNewline, trimTrailingWhitespace, getPathParents, + getPathParent, + readFileAsDataURL, } from '~/ide/utils'; import { languages } from 'monaco-editor'; @@ -203,5 +205,38 @@ describe('WebIDE utils', () => { `('gets all parent directory names for path: $path', ({ path, parents }) => { expect(getPathParents(path)).toEqual(parents); }); + + it.each` + path | depth | parents + ${'foo/bar/baz/index.md'} | ${0} | ${[]} + ${'foo/bar/baz/index.md'} | ${1} | ${['foo/bar/baz']} + ${'foo/bar/baz/index.md'} | ${2} | ${['foo/bar/baz', 'foo/bar']} + ${'foo/bar/baz/index.md'} | ${3} | ${['foo/bar/baz', 'foo/bar', 'foo']} + ${'foo/bar/baz/index.md'} | ${4} | ${['foo/bar/baz', 'foo/bar', 'foo']} + `('gets only the immediate $depth parents if when depth=$depth', ({ path, depth, parents }) => { + expect(getPathParents(path, depth)).toEqual(parents); + }); + }); + + describe('getPathParent', () => { + it.each` + path | parents + ${'foo/bar/baz/index.md'} | ${'foo/bar/baz'} + ${'foo/bar/baz'} | ${'foo/bar'} + ${'index.md'} | ${undefined} + ${'path with/spaces to/something.md'} | ${'path with/spaces to'} + `('gets the immediate parent for path: $path', ({ path, parents }) => { + expect(getPathParent(path)).toEqual(parents); + }); + }); + + describe('readFileAsDataURL', () => { + it('reads a file and returns its output as a data url', () => { + const file = new File(['foo'], 'foo.png', { type: 'image/png' }); + + return readFileAsDataURL(file).then(contents => { + expect(contents).toBe('data:image/png;base64,Zm9v'); + }); + }); }); }); |