Skip to content

Commit 4fb243a

Browse files
test: add test case for popup error display
Adds a new test case to `tests/popup.test.js` to verify that the popup correctly displays an error message and updates the button text when `sendWebhook` fails. This covers a previously untested code path in the `catch` block of the webhook button click handler. Co-authored-by: cmuench <211294+cmuench@users.noreply.github.com>
1 parent f39b983 commit 4fb243a

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

tests/popup.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,30 @@ describe('popup script', () => {
121121
expect(btns.length).toBe(1);
122122
expect(btns[0].textContent).toBe('A');
123123
});
124+
125+
test('displays error message when webhook fails', async () => {
126+
const hook = { id: '1', label: 'Fail', url: 'https://fail.test' };
127+
browser.storage.sync.get.mockResolvedValue({ webhooks: [hook] });
128+
browser.tabs.query.mockResolvedValue([{ title: 't', url: 'https://example.com', id: 1, windowId: 1, index: 0, pinned: false, audible: false, mutedInfo: null, incognito: false, status: 'complete' }]);
129+
130+
// Mock sendWebhook to fail
131+
const errorMsg = 'Network Error';
132+
window.sendWebhook.mockRejectedValue(new Error(errorMsg));
133+
134+
require('../popup/popup.js');
135+
document.dispatchEvent(new dom.window.Event('DOMContentLoaded'));
136+
await new Promise(setImmediate);
137+
138+
const btn = document.querySelector('button.webhook-btn');
139+
expect(btn).not.toBeNull();
140+
btn.dispatchEvent(new dom.window.Event('click', { bubbles: true }));
141+
142+
// Wait for async operations
143+
await new Promise(setImmediate);
144+
145+
const statusMessage = document.getElementById('status-message');
146+
expect(statusMessage.textContent).toBe(`popupStatusErrorPrefix ${errorMsg}`);
147+
expect(statusMessage.classList.contains('error')).toBe(true);
148+
expect(btn.textContent).toBe('popupBtnTextFailed');
149+
});
124150
});

0 commit comments

Comments
 (0)