Skip to content

Commit

Permalink
Merge pull request #33 from marph91/fix-no-mails-exported
Browse files Browse the repository at this point in the history
Fix no mails exported
  • Loading branch information
marph91 authored May 30, 2024
2 parents 51f5801 + c150705 commit 145352d
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 25 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ What to do when the export failed?

## Changelog

### 0.0.7

- Bugfix: Make export working again when mail body is not displayed (<https://github.com/marph91/thunderbird-joplin-export/pull/33>).

### 0.0.6

- Add `author` and `user_created_date` metadata.
Expand Down
5 changes: 4 additions & 1 deletion __mocks__/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ export const browser = {
browser.browserAction.icon = icon.path;
},
},
mailTabs: {
getSelectedMessages: jest.fn(async (_tabId) => <any>{ messages: [] }),
},
menus: {
create: jest.fn(),
onClicked: { addListener: jest.fn() },
},
messageDisplay: {
getDisplayedMessages: jest.fn(),
getDisplayedMessages: jest.fn(async (_tabId) => <Array<any>>[]),
},
messages: {
getFull: jest.fn(async () => {
Expand Down
99 changes: 92 additions & 7 deletions __tests__/test_background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
getAndProcessMessages,
handleContextMenu,
handleHotkey,
handleMenuButton,
onlyWhitespace,
processMail,
renderString,
Expand Down Expand Up @@ -208,7 +209,7 @@ describe("handle button / hotkey / context menu", () => {
expectConsole({
log: 1,
warn: 0,
error: ["Failed to create note: Invalid token"],
error: ["[Joplin Export] Failed to create note: Invalid token"],
});
});

Expand Down Expand Up @@ -274,9 +275,25 @@ describe("handle button / hotkey / context menu", () => {
}
);

test("export by menu button", async () => {
messenger.tabs.query.mockResolvedValueOnce([{ id: 1 }]);
browser.messageDisplay.getDisplayedMessages.mockResolvedValueOnce([
{ id: 1 },
]);

await handleMenuButton({ id: 1 }, { menuItemId: "export_to_joplin" });

expect(requests.length).toBe(1);
expectConsole({
log: 1,
warn: 0,
error: 0,
});
});

test("export by hotkey", async () => {
messenger.tabs.query.mockResolvedValueOnce([{ id: 1 }]);
browser.messageDisplay.getDisplayedMessages.mockReturnValueOnce([
browser.messageDisplay.getDisplayedMessages.mockResolvedValueOnce([
{ id: 1 },
]);

Expand All @@ -292,7 +309,7 @@ describe("handle button / hotkey / context menu", () => {

test("export by context menu", async () => {
messenger.tabs.query.mockResolvedValueOnce([{ id: 1 }]);
browser.messageDisplay.getDisplayedMessages.mockReturnValueOnce([
browser.messageDisplay.getDisplayedMessages.mockResolvedValueOnce([
{ id: 1 },
]);

Expand All @@ -307,6 +324,74 @@ describe("handle button / hotkey / context menu", () => {
});
});

describe("handle displayed and selected mails", () => {
test("one selected mail", async () => {
messenger.tabs.query.mockResolvedValueOnce([{ id: 1 }]);
browser.mailTabs.getSelectedMessages.mockResolvedValueOnce({
messages: [{ id: 1 }],
});

await getAndProcessMessages({ id: 1 }, {});

expect(requests.length).toBe(1);
expectConsole({
log: 1,
warn: 0,
error: 0,
});
});

test("no selected mail, one displayed mail", async () => {
messenger.tabs.query.mockResolvedValueOnce([{ id: 1 }]);
browser.messageDisplay.getDisplayedMessages.mockResolvedValueOnce([
{ id: 1 },
]);

await getAndProcessMessages({ id: 1 }, {});

expect(requests.length).toBe(1);
expectConsole({
log: 1,
warn: 0,
error: 0,
});
});

test("error at selected mail, one displayed mail", async () => {
messenger.tabs.query.mockResolvedValueOnce([{ id: 1 }]);
// This error gets thrown when querying the selected messages at a tab
// where are no messages selected.
browser.mailTabs.getSelectedMessages.mockImplementation(() => {
throw new Error();
});
browser.messageDisplay.getDisplayedMessages.mockResolvedValueOnce([
{ id: 1 },
]);

await getAndProcessMessages({ id: 1 }, {});

expect(requests.length).toBe(1);
expectConsole({
log: 1,
warn: 0,
error: 0,
});
});

test("no selectedmail, no displayed mail", async () => {
messenger.tabs.query.mockResolvedValueOnce([{ id: 1 }]);

await getAndProcessMessages({ id: 1 }, {});

expect(requests.length).toBe(0);
expectConsole({
log: 0,
warn: 1,
error: 0,
});
});
});

describe("process mail", () => {
test("empty header", async () => {
const result = await processMail(undefined);
Expand Down Expand Up @@ -466,8 +551,8 @@ describe("process mail", () => {
// Finally check the console output.
const message =
resultFormat === "text/html"
? "Sending complete email in HTML format."
: "Sending complete email in plain format.";
? "[Joplin Export] Sending complete email in HTML format."
: "[Joplin Export] Sending complete email in plain format.";
expectConsole({
log: [message],
warn: 0,
Expand Down Expand Up @@ -503,7 +588,7 @@ describe("process mail", () => {
});

expectConsole({
log: ["Sending selection in plain format."],
log: ["[Joplin Export] Sending selection in plain format."],
warn: 0,
error: 0,
});
Expand Down Expand Up @@ -692,7 +777,7 @@ describe("process tag", () => {

expectConsole({
log: 1,
warn: ['Too many matching tags for "multipleTags": a, b'],
warn: ['[Joplin Export] Too many matching tags for "multipleTags": a, b'],
error: 0,
});
});
Expand Down
16 changes: 16 additions & 0 deletions doc/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,19 @@
4. Submit the add-on at <https://addons.thunderbird.net/de/developers/addon/joplin-export/versions/submit/>.

NB: [List of valid Thunderbird versions](https://addons.thunderbird.net/en-US/thunderbird/pages/appversions/)

## How to test a release

The automated tests should be successful. Additionally, the following cases should be tested manually:

Export via:

- Menu button
- Context menu
- Hotkey

Tabs:

- Mail tab with mail body
- Mail tab without mail body
- Mail in a separate tab
Loading

0 comments on commit 145352d

Please # to comment.