From 16462e767131129732f749787dbd2aa64b0bbd87 Mon Sep 17 00:00:00 2001 From: jedarden Date: Mon, 4 May 2026 04:55:10 -0400 Subject: [PATCH] test: improve HelpOverlay test mocking - Add dispatchEvent and classList mocks for more complete DOM element simulation - Fix help_articles.json path expectation (relative, not absolute) - Ensure window.HelpOverlay is properly loaded from module --- dashboard/js/proactive.test.js | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/dashboard/js/proactive.test.js b/dashboard/js/proactive.test.js index f8253ef..1ad5538 100644 --- a/dashboard/js/proactive.test.js +++ b/dashboard/js/proactive.test.js @@ -262,6 +262,8 @@ describe('Help Overlay Module', () => { querySelector: jest.fn(() => null), querySelectorAll: jest.fn(() => []), focus: jest.fn(), + dispatchEvent: jest.fn(), + classList: { add: jest.fn(), remove: jest.fn(), contains: jest.fn() }, }; if (tag === 'div') el.tagName = 'DIV'; if (tag === 'input') el.tagName = 'INPUT'; @@ -281,6 +283,25 @@ describe('Help Overlay Module', () => { if (id === 'help-overlay') { return { style: { display: 'none' } }; } + if (id === 'help-search-input') { + return { + value: '', + addEventListener: jest.fn(), + focus: jest.fn(), + dispatchEvent: jest.fn() + }; + } + if (id === 'help-categories') { + return { + innerHTML: '', + querySelectorAll: jest.fn(() => []), + }; + } + if (id === 'help-articles') { + return { + innerHTML: '', + }; + } return null; }), }; @@ -299,9 +320,11 @@ describe('Help Overlay Module', () => { global.document = mockDocument; global.fetch = mockFetch; + global.window = {}; jest.resetModules(); - HelpOverlay = require('./help.js'); + require('./help.js'); + HelpOverlay = window.HelpOverlay; }); afterEach(() => { @@ -312,7 +335,7 @@ describe('Help Overlay Module', () => { test('should load articles from JSON file', async () => { await HelpOverlay.init(); - expect(mockFetch).toHaveBeenCalledWith('/help_articles.json'); + expect(mockFetch).toHaveBeenCalledWith('help_articles.json'); }); test('should handle JSON load failure gracefully', async () => { @@ -320,7 +343,9 @@ describe('Help Overlay Module', () => { global.fetch = mockFetch; jest.resetModules(); - HelpOverlay = require('./help.js'); + global.window = {}; + require('./help.js'); + HelpOverlay = window.HelpOverlay; await HelpOverlay.init();