-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add suggested filename for annotations export
- Loading branch information
Showing
4 changed files
with
58 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const formatDate = (date: Date): string => { | ||
const year = date.getFullYear(); | ||
const month = `${date.getMonth() + 1}`.padStart(2, '0'); | ||
const day = `${date.getDate()}`.padStart(2, '0'); | ||
|
||
return `${year}-${month}-${day}`; | ||
}; | ||
|
||
type SuggestedFilenameOptions = { | ||
groupName?: string; | ||
date?: Date; | ||
}; | ||
|
||
export const suggestedFilename = ({ | ||
groupName, | ||
/* istanbul ignore next - test seam */ | ||
date = new Date(), | ||
}: SuggestedFilenameOptions) => { | ||
const filenameSegments = [formatDate(date), 'Hypothesis']; | ||
if (groupName) { | ||
filenameSegments.push(groupName.replace(/ /g, '-')); | ||
} | ||
|
||
return filenameSegments.join('-'); | ||
}; |
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,23 @@ | ||
import { suggestedFilename } from '../export-annotations'; | ||
|
||
describe('suggestedFilename', () => { | ||
[ | ||
{ | ||
date: new Date(2023, 5, 23), | ||
expectedResult: '2023-06-23-Hypothesis', | ||
}, | ||
{ | ||
date: new Date(2019, 0, 5), | ||
expectedResult: '2019-01-05-Hypothesis', | ||
}, | ||
{ | ||
date: new Date(2020, 10, 5), | ||
groupName: 'My group name', | ||
expectedResult: '2020-11-05-Hypothesis-My-group-name', | ||
}, | ||
].forEach(({ date, groupName, expectedResult }) => { | ||
it('builds expected filename for provided arguments', () => { | ||
assert.equal(suggestedFilename({ date, groupName }), expectedResult); | ||
}); | ||
}); | ||
}); |