-
Notifications
You must be signed in to change notification settings - Fork 5
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 #16 from marph91/custom-author-date
Custom author and date
- Loading branch information
Showing
6 changed files
with
113 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,6 +156,8 @@ beforeEach(() => { | |
joplinShowNotifications: "onFailure", | ||
|
||
joplinSubjectTrimRegex: "", | ||
joplinAuthorTrimRegex: "", | ||
joplinDateFormat: "", | ||
joplinNoteTitleTemplate: "{{subject}} from {{author}}", | ||
joplinNoteHeaderTemplate: "", | ||
joplinNoteParentFolder: "arbitrary folder", | ||
|
@@ -521,6 +523,73 @@ describe("process mail", () => { | |
}); | ||
} | ||
); | ||
|
||
test.each` | ||
inputAuthor | regexString | expectedAuthor | ||
${"John Doof <[email protected]>"} | ${""} | ${"John Doof <[email protected]>"} | ||
${"John Doof <[email protected]>"} | ${" ?<.*>$"} | ${"John Doof"} | ||
`( | ||
"modify author by regex: $regexString", | ||
async ({ inputAuthor, regexString, expectedAuthor }) => { | ||
const subject = "some subject"; | ||
await browser.storage.local.set({ joplinAuthorTrimRegex: regexString }); | ||
|
||
const result = await processMail({ | ||
id: 1, | ||
subject: subject, | ||
author: inputAuthor, | ||
}); | ||
|
||
expect(result).toBe(null); | ||
expect(requests.length).toBe(1); | ||
expect(requests[0].body).toEqual( | ||
expect.objectContaining({ title: `${subject} from ${expectedAuthor}` }) | ||
); | ||
|
||
expectConsole({ | ||
log: 1, | ||
warn: 0, | ||
error: 0, | ||
}); | ||
} | ||
); | ||
|
||
test.each` | ||
inputDate | dateFormat | expectedDate | ||
${"06.04.2022"} | ${""} | ${"06.04.2022"} | ||
${new Date("1995-12-17T03:24:00")} | ${"d.L.y T"} | ${"17.12.1995 03:24"} | ||
`( | ||
"apply date format: $dateFormat", | ||
async ({ inputDate, dateFormat, expectedDate }) => { | ||
const author = "author name"; | ||
const subject = "some subject"; | ||
await browser.storage.local.set({ | ||
joplinNoteTitleTemplate: "{{subject}} from {{author}} at {{date}}", | ||
joplinDateFormat: dateFormat, | ||
}); | ||
|
||
const result = await processMail({ | ||
id: 1, | ||
subject: subject, | ||
author: author, | ||
date: inputDate, | ||
}); | ||
|
||
expect(result).toBe(null); | ||
expect(requests.length).toBe(1); | ||
expect(requests[0].body).toEqual( | ||
expect.objectContaining({ | ||
title: `${subject} from ${author} at ${expectedDate}`, | ||
}) | ||
); | ||
|
||
expectConsole({ | ||
log: 1, | ||
warn: 0, | ||
error: 0, | ||
}); | ||
} | ||
); | ||
}); | ||
|
||
describe("process tag", () => { | ||
|
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