Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(reports): add unit tests for parsers
Adds unit tests to the parser functions in the BaseReports file.
- Loading branch information
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* global inject, expect */ | ||
/* eslint no-unused-expressions:off */ | ||
describe('BaseReportService', () => { | ||
// shared services | ||
let SavedReports; | ||
|
||
// load bhima.services | ||
beforeEach(module( | ||
'pascalprecht.translate', | ||
'tmh.dynamicLocale', | ||
'ngStorage', | ||
'angularMoment', | ||
'ui.bootstrap', | ||
'bhima.services', | ||
)); | ||
|
||
|
||
let parseExtension; | ||
let parseIcon; | ||
beforeEach(inject((_BaseReportService_) => { | ||
SavedReports = _BaseReportService_; | ||
parseExtension = SavedReports.parseFileUrlToExtension; | ||
parseIcon = SavedReports.parseFileUrlToIcon; | ||
})); | ||
|
||
describe('#parseUrlToExtension()', () => { | ||
it('correctly parses simple paths', () => { | ||
expect(parseExtension('image.jpg')).to.equal('jpg'); | ||
expect(parseExtension('image.svg')).to.equal('svg'); | ||
expect(parseExtension('doc.docx')).to.equal('docx'); | ||
|
||
expect(parseExtension('/this/is/some/path.pdf')).to.equal('pdf'); | ||
expect(parseExtension('https://github.com/cool.gif')).to.equal('gif'); | ||
|
||
}); | ||
|
||
it('handles error cases', () => { | ||
expect(parseExtension('')).to.equal(''); | ||
expect(parseExtension()).to.equal(''); | ||
}); | ||
|
||
it('correctly parses complex paths', () => { | ||
expect(parseExtension('a.file.with.decimals.pdf')).to.equal('pdf'); | ||
expect(parseExtension('/more/complex/file.with/decimals.gz')).to.equal('gz'); | ||
}); | ||
}); | ||
|
||
describe('#parseUrlToIcon()', () => { | ||
it('correctly parses paths to guess their icons', () => { | ||
expect(parseIcon('icon.png')).to.equal('fa-file-image-o'); | ||
expect(parseIcon('icon.svg')).to.equal('fa-file-image-o'); | ||
|
||
expect(parseIcon('document.doc')).to.equal('fa-file-word-o'); | ||
expect(parseIcon('document.docx')).to.equal('fa-file-word-o'); | ||
|
||
expect(parseIcon('msexcel.xls')).to.equal('fa-file-excel-o'); | ||
expect(parseIcon('msexcel.xlsx')).to.equal('fa-file-excel-o'); | ||
|
||
expect(parseIcon('unknown.what')).to.equal('fa-file-o'); | ||
|
||
|
||
expect(parseIcon('report.pdf')).to.equal('fa-file-pdf-o'); | ||
}); | ||
}); | ||
|
||
}); |