diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-17 12:09:32 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-17 12:09:32 +0300 |
commit | afed1a4be18c74f8b95a0b8e0e359a1339ca1ad1 (patch) | |
tree | 108265d8da2c5856183f9032c16dd9ae63cf9b01 /spec/frontend/ide/utils_spec.js | |
parent | 9e3e71602cac2593f77282b1862fbd163e78233f (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 | 100 |
1 files changed, 59 insertions, 41 deletions
diff --git a/spec/frontend/ide/utils_spec.js b/spec/frontend/ide/utils_spec.js index 4a1e1f3c45e..97dc8217ecc 100644 --- a/spec/frontend/ide/utils_spec.js +++ b/spec/frontend/ide/utils_spec.js @@ -13,60 +13,78 @@ import { describe('WebIDE utils', () => { describe('isTextFile', () => { - it('returns false for known binary types', () => { - expect(isTextFile('file content', 'image/png', 'my.png')).toBeFalsy(); - // mime types are case insensitive - expect(isTextFile('file content', 'IMAGE/PNG', 'my.png')).toBeFalsy(); + it.each` + mimeType | name | type | result + ${'image/png'} | ${'my.png'} | ${'binary'} | ${false} + ${'IMAGE/PNG'} | ${'my.png'} | ${'binary'} | ${false} + ${'text/plain'} | ${'my.txt'} | ${'text'} | ${true} + ${'TEXT/PLAIN'} | ${'my.txt'} | ${'text'} | ${true} + `('returns $result for known $type types', ({ mimeType, name, result }) => { + expect(isTextFile({ content: 'file content', mimeType, name })).toBe(result); }); - it('returns true for known text types', () => { - expect(isTextFile('file content', 'text/plain', 'my.txt')).toBeTruthy(); - // mime types are case insensitive - expect(isTextFile('file content', 'TEXT/PLAIN', 'my.txt')).toBeTruthy(); - }); + it.each` + content | mimeType | name + ${'{"éêė":"value"}'} | ${'application/json'} | ${'my.json'} + ${'{"éêė":"value"}'} | ${'application/json'} | ${'.tsconfig'} + ${'SELECT "éêė" from tablename'} | ${'application/sql'} | ${'my.sql'} + ${'{"éêė":"value"}'} | ${'application/json'} | ${'MY.JSON'} + ${'SELECT "éêė" from tablename'} | ${'application/sql'} | ${'MY.SQL'} + ${'var code = "something"'} | ${'application/javascript'} | ${'Gruntfile'} + ${'MAINTAINER Александр "a21283@me.com"'} | ${'application/octet-stream'} | ${'dockerfile'} + `( + 'returns true for file extensions that Monaco supports syntax highlighting for', + ({ content, mimeType, name }) => { + expect(isTextFile({ content, mimeType, name })).toBe(true); + }, + ); - it('returns true for file extensions that Monaco supports syntax highlighting for', () => { - // test based on both MIME and extension - expect(isTextFile('{"éêė":"value"}', 'application/json', 'my.json')).toBeTruthy(); - expect(isTextFile('{"éêė":"value"}', 'application/json', '.tsconfig')).toBeTruthy(); - expect(isTextFile('SELECT "éêė" from tablename', 'application/sql', 'my.sql')).toBeTruthy(); + it('returns false if filename is same as the expected extension', () => { + expect( + isTextFile({ + name: 'sql', + content: 'SELECT "éêė" from tablename', + mimeType: 'application/sql', + }), + ).toBeFalsy(); }); - it('returns true even irrespective of whether the mimes, extensions or file names are lowercase or upper case', () => { - expect(isTextFile('{"éêė":"value"}', 'application/json', 'MY.JSON')).toBeTruthy(); - expect(isTextFile('SELECT "éêė" from tablename', 'application/sql', 'MY.SQL')).toBeTruthy(); - expect( - isTextFile('var code = "something"', 'application/javascript', 'Gruntfile'), - ).toBeTruthy(); + it('returns true for ASCII only content for unknown types', () => { expect( - isTextFile( - 'MAINTAINER Александр "alexander11354322283@me.com"', - 'application/octet-stream', - 'dockerfile', - ), + isTextFile({ + name: 'hello.mytype', + content: 'plain text', + mimeType: 'application/x-new-type', + }), ).toBeTruthy(); }); - it('returns false if filename is same as the expected extension', () => { - expect(isTextFile('SELECT "éêė" from tablename', 'application/sql', 'sql')).toBeFalsy(); - }); - - it('returns true for ASCII only content for unknown types', () => { - expect(isTextFile('plain text', 'application/x-new-type', 'hello.mytype')).toBeTruthy(); + it('returns false for non-ASCII content for unknown types', () => { + expect( + isTextFile({ + name: 'my.random', + content: '{"éêė":"value"}', + mimeType: 'application/octet-stream', + }), + ).toBeFalsy(); }); - it('returns true for relevant filenames', () => { - expect( - isTextFile( - 'MAINTAINER Александр "alexander11354322283@me.com"', - 'application/octet-stream', - 'Dockerfile', - ), - ).toBeTruthy(); + it.each` + name | result + ${'myfile.txt'} | ${true} + ${'Dockerfile'} | ${true} + ${'img.png'} | ${false} + ${'abc.js'} | ${true} + ${'abc.random'} | ${false} + ${'image.jpeg'} | ${false} + `('returns $result for $filename when no content or mimeType is passed', ({ name, result }) => { + expect(isTextFile({ name })).toBe(result); }); - it('returns false for non-ASCII content for unknown types', () => { - expect(isTextFile('{"éêė":"value"}', 'application/octet-stream', 'my.random')).toBeFalsy(); + it('returns true if content is empty string but false if content is not passed', () => { + expect(isTextFile({ name: 'abc.dat' })).toBe(false); + expect(isTextFile({ name: 'abc.dat', content: '' })).toBe(true); + expect(isTextFile({ name: 'abc.dat', content: ' ' })).toBe(true); }); }); |