diff options
Diffstat (limited to 'spec/frontend/diffs/utils/sort_errors_by_file_spec.js')
-rw-r--r-- | spec/frontend/diffs/utils/sort_errors_by_file_spec.js | 52 |
1 files changed, 52 insertions, 0 deletions
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); + }); +}); |