From f912bb4e0b53b81e09d9b80eab989136b6e53d61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20M=C3=BCnch?= Date: Mon, 14 Jul 2025 09:49:16 +0200 Subject: [PATCH] feat: add optional URL filter for webhooks --- options/options.html | 13 ++++++++- options/options.js | 62 ++++++++++++++++++++++++++++++++++++++++--- popup/popup.js | 11 +++++--- tests/options.test.js | 14 ++++++++-- tests/popup.test.js | 19 ++++++++++++- 5 files changed, 108 insertions(+), 11 deletions(-) diff --git a/options/options.html b/options/options.html index 9f14b54..64412ac 100644 --- a/options/options.html +++ b/options/options.html @@ -55,7 +55,18 @@

__MSG_optionsAddWebhookHeader__

-
+
+ + +
+ +
+
+
-
+
+ +
+ +
@@ -116,6 +124,7 @@ describe('options page', () => { document.getElementById('webhook-label').value = 'Test Webhook'; document.getElementById('webhook-url').value = 'https://example.com/webhook'; document.getElementById('webhook-custom-payload').value = customPayload; + document.getElementById('webhook-url-filter').value = 'example.com'; // Set identifier value document.getElementById('webhook-identifier').value = 'test-identifier'; @@ -169,7 +178,8 @@ describe('options page', () => { { key: 'Authorization', value: 'Bearer token123' } ], identifier: 'test-identifier', - customPayload + customPayload, + urlFilter: 'example.com' }] }); }); diff --git a/tests/popup.test.js b/tests/popup.test.js index 46289cf..7c6bd1c 100644 --- a/tests/popup.test.js +++ b/tests/popup.test.js @@ -22,7 +22,7 @@ describe('popup script', () => { global.browser = { storage: { sync: { get: jest.fn() } }, i18n: { getMessage: jest.fn((key) => key) }, - tabs: { query: jest.fn() }, + tabs: { query: jest.fn().mockResolvedValue([{ title: 't', url: 'https://example.com', id: 1, windowId: 1, index: 0, pinned: false, audible: false, mutedInfo: null, incognito: false, status: 'complete' }]) }, runtime: { openOptionsPage: jest.fn(), getBrowserInfo: jest.fn().mockResolvedValue({}), @@ -105,4 +105,21 @@ describe('popup script', () => { const sentPayload = JSON.parse(fetchOptions.body); expect(sentPayload).toEqual({ message: 'Custom message with Test Page' }); }); + + test('filters webhooks based on urlFilter', async () => { + const hooks = [ + { id: '1', label: 'A', url: 'https://hook1.test', urlFilter: 'example.com' }, + { id: '2', label: 'B', url: 'https://hook2.test', urlFilter: 'other.com' } + ]; + browser.storage.sync.get.mockResolvedValue({ webhooks: hooks }); + 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' }]); + + require('../popup/popup.js'); + document.dispatchEvent(new dom.window.Event('DOMContentLoaded')); + await new Promise(setImmediate); + + const btns = document.querySelectorAll('button.webhook-btn'); + expect(btns.length).toBe(1); + expect(btns[0].textContent).toBe('A'); + }); });