-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2266 from thostetler/fix-date-parsing-issue
- Loading branch information
Showing
6 changed files
with
121 additions
and
99 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
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
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 |
---|---|---|
@@ -1,20 +1,56 @@ | ||
define([ | ||
'js/mixins/papers_utils' | ||
], | ||
function( | ||
PapersUtils | ||
){ | ||
|
||
describe("Papers Utils Mixin (mixins/papers_utils.spec.js)", function(){ | ||
|
||
it("should know to format dates", function() { | ||
expect(PapersUtils.formatDate('2011-01-01T00:00:00Z', {format: 'mm/yy'})).to.be.eql('01/2011'); | ||
|
||
expect(PapersUtils.formatDate('2011-12-01', {format: 'mm/yy', missing: {day: 'mm/yy', month: '--/yy'}})).to.be.eql('12/2011'); | ||
expect(PapersUtils.formatDate('2011-12-00', {format: 'mm/yy', missing: {day: 'mm/yy', month: '--/yy'}})).to.be.eql('12/2011'); | ||
expect(PapersUtils.formatDate('2011-00-00', {format: 'mm/yy', missing: {day: 'mm/yy', month: '--/yy'}})).to.be.eql('--/2011'); | ||
|
||
expect(function() {PapersUtils.formatDate('2011-12-0x', {format: 'mm/yy', missing: {day: 'mm/yy', month: '--/yy'}})}).to.throw.Exception; | ||
}); | ||
}) | ||
}); | ||
define(['js/mixins/papers_utils'], function(Utils) { | ||
describe('Papers Utils Mixin (mixins/papers_utils.spec.js)', function() { | ||
it('returns formatted date with complete input', () => { | ||
const dateString = '2023-05-22'; | ||
const format = 'YYYY/MM/DD'; | ||
|
||
const result = Utils.formatDate(dateString, { format }); | ||
|
||
expect(result).to.equal('2023/05/22'); | ||
}); | ||
|
||
it('returns formatted date with missing month', () => { | ||
const dateString = '2023-00-22'; | ||
const missing = { month: 'YYYY', day: 'YYYY/MM' }; | ||
|
||
const result = Utils.formatDate(dateString, { missing }); | ||
|
||
expect(result).to.equal('2023'); | ||
}); | ||
|
||
it('returns formatted date with missing day', () => { | ||
const dateString = '2023-05-00'; | ||
const missing = { day: 'YYYY/MM', month: 'YYYY' }; | ||
|
||
const result = Utils.formatDate(dateString, { missing }); | ||
|
||
expect(result).to.equal('2023/05'); | ||
}); | ||
|
||
it('returns formatted date with missing month and day', () => { | ||
const dateString = '2023-00-00'; | ||
const missing = { dayAndMonth: 'YYYY' }; | ||
|
||
const result = Utils.formatDate(dateString, { missing }); | ||
|
||
expect(result).to.equal('2023'); | ||
}); | ||
|
||
it('returns year if parsed date is invalid', () => { | ||
const dateString = '2023-13-45'; | ||
const format = 'YYYY/MM'; | ||
|
||
const result = Utils.formatDate(dateString, { format }); | ||
|
||
expect(result).to.equal('2023'); | ||
}); | ||
|
||
it('returns null if input does not match regex', () => { | ||
const dateString = 'invalid-date'; | ||
|
||
const result = Utils.formatDate(dateString); | ||
|
||
expect(result).to.equal(null); | ||
}); | ||
}); | ||
}); |