diff options
Diffstat (limited to 'spec/frontend/lib/utils')
-rw-r--r-- | spec/frontend/lib/utils/common_utils_spec.js | 5 | ||||
-rw-r--r-- | spec/frontend/lib/utils/text_utility_spec.js | 23 |
2 files changed, 26 insertions, 2 deletions
diff --git a/spec/frontend/lib/utils/common_utils_spec.js b/spec/frontend/lib/utils/common_utils_spec.js index 09eb362c77e..433fb368f55 100644 --- a/spec/frontend/lib/utils/common_utils_spec.js +++ b/spec/frontend/lib/utils/common_utils_spec.js @@ -220,6 +220,7 @@ describe('common_utils', () => { beforeEach(() => { elem = document.createElement('div'); window.innerHeight = windowHeight; + window.mrTabs = { currentAction: 'show' }; jest.spyOn($.fn, 'animate'); jest.spyOn($.fn, 'offset').mockReturnValue({ top: elemTop }); }); @@ -525,8 +526,8 @@ describe('common_utils', () => { }); it('should set svg className when passed', () => { - expect(commonUtils.spriteIcon('test', 'fa fa-test')).toEqual( - '<svg class="fa fa-test"><use xlink:href="icons.svg#test" /></svg>', + expect(commonUtils.spriteIcon('test', 'first-icon-class second-icon-class')).toEqual( + '<svg class="first-icon-class second-icon-class"><use xlink:href="icons.svg#test" /></svg>', ); }); }); diff --git a/spec/frontend/lib/utils/text_utility_spec.js b/spec/frontend/lib/utils/text_utility_spec.js index d7cedb939d2..9c50bf577dc 100644 --- a/spec/frontend/lib/utils/text_utility_spec.js +++ b/spec/frontend/lib/utils/text_utility_spec.js @@ -340,4 +340,27 @@ describe('text_utility', () => { expect(textUtils.isValidSha1Hash(hash)).toBe(valid); }); }); + + describe('insertFinalNewline', () => { + 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(textUtils.insertFinalNewline(input)).toBe(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(textUtils.insertFinalNewline(input, '\r\n')).toBe(output); + }); + }); }); |