From cc050a816e852eb606be30172588dccfcf4c58c9 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 25 Feb 2026 13:02:48 +0000 Subject: [PATCH] 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> --- tests/popup.test.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/popup.test.js b/tests/popup.test.js index 0724a62..eeb8fff 100644 --- a/tests/popup.test.js +++ b/tests/popup.test.js @@ -121,4 +121,30 @@ describe('popup script', () => { expect(btns.length).toBe(1); expect(btns[0].textContent).toBe('A'); }); + + test('displays error message when webhook fails', async () => { + const hook = { id: '1', label: 'Fail', url: 'https://fail.test' }; + browser.storage.sync.get.mockResolvedValue({ webhooks: [hook] }); + 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' }]); + + // Mock sendWebhook to fail + const errorMsg = 'Network Error'; + window.sendWebhook.mockRejectedValue(new Error(errorMsg)); + + require('../popup/popup.js'); + document.dispatchEvent(new dom.window.Event('DOMContentLoaded')); + await new Promise(setImmediate); + + const btn = document.querySelector('button.webhook-btn'); + expect(btn).not.toBeNull(); + btn.dispatchEvent(new dom.window.Event('click', { bubbles: true })); + + // Wait for async operations + await new Promise(setImmediate); + + const statusMessage = document.getElementById('status-message'); + expect(statusMessage.textContent).toBe(`popupStatusErrorPrefix ${errorMsg}`); + expect(statusMessage.classList.contains('error')).toBe(true); + expect(btn.textContent).toBe('popupBtnTextFailed'); + }); });