diff options
Diffstat (limited to 'spec/frontend/diffs/utils')
-rw-r--r-- | spec/frontend/diffs/utils/merge_request_spec.js | 16 | ||||
-rw-r--r-- | spec/frontend/diffs/utils/sort_errors_by_file_spec.js | 52 |
2 files changed, 68 insertions, 0 deletions
diff --git a/spec/frontend/diffs/utils/merge_request_spec.js b/spec/frontend/diffs/utils/merge_request_spec.js index 11c0efb9a9c..f5145b3c4c7 100644 --- a/spec/frontend/diffs/utils/merge_request_spec.js +++ b/spec/frontend/diffs/utils/merge_request_spec.js @@ -1,6 +1,7 @@ import { updateChangesTabCount, getDerivedMergeRequestInformation, + extractFileHash, } from '~/diffs/utils/merge_request'; import { ZERO_CHANGES_ALT_DISPLAY } from '~/diffs/constants'; import { diffMetadata } from '../mock_data/diff_metadata'; @@ -128,4 +129,19 @@ describe('Merge Request utilities', () => { }); }); }); + + describe('extractFileHash', () => { + const sha1Like = 'abcdef1234567890abcdef1234567890abcdef12'; + const sha1LikeToo = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'; + + it('returns undefined when a SHA1-like string cannot be found in the input', () => { + expect(extractFileHash({ input: 'something' })).toBe(undefined); + }); + + it('returns the first matching string of SHA1-like characters in the input', () => { + const fullString = `#${sha1Like}_34_42--${sha1LikeToo}`; + + expect(extractFileHash({ input: fullString })).toBe(sha1Like); + }); + }); }); diff --git a/spec/frontend/diffs/utils/sort_errors_by_file_spec.js b/spec/frontend/diffs/utils/sort_errors_by_file_spec.js new file mode 100644 index 00000000000..ca8a8ec3516 --- /dev/null +++ b/spec/frontend/diffs/utils/sort_errors_by_file_spec.js @@ -0,0 +1,52 @@ +import { sortFindingsByFile } from '~/diffs/utils/sort_findings_by_file'; + +describe('sort_findings_by_file utilities', () => { + const mockDescription = 'mockDescription'; + const mockSeverity = 'mockseverity'; + const mockLine = '00'; + const mockFile1 = 'file1.js'; + const mockFile2 = 'file2.rb'; + const emptyResponse = { + files: {}, + }; + + const unsortedFindings = [ + { + severity: mockSeverity, + filePath: mockFile1, + line: mockLine, + description: mockDescription, + }, + { + severity: mockSeverity, + filePath: mockFile2, + line: mockLine, + description: mockDescription, + }, + ]; + const sortedFindings = { + files: { + [mockFile1]: [ + { + line: mockLine, + description: mockDescription, + severity: mockSeverity, + }, + ], + [mockFile2]: [ + { + line: mockLine, + description: mockDescription, + severity: mockSeverity, + }, + ], + }, + }; + + it('sorts Findings correctly', () => { + expect(sortFindingsByFile(unsortedFindings)).toEqual(sortedFindings); + }); + it('does not throw error when given no input', () => { + expect(sortFindingsByFile()).toEqual(emptyResponse); + }); +}); |