/** @jest-environment jsdom */ const path = require('path'); // Load sanitizer and alerts modules (IIFE attaches to window) require(path.join(__dirname, '..', 'sanitizer.js')); require(path.join(__dirname, '..', 'alerts.js')); // Polyfill requestAnimationFrame for jsdom beforeAll(() => { if (!global.requestAnimationFrame) { global.requestAnimationFrame = (cb) => setTimeout(cb, 0); } }); beforeEach(() => { document.body.innerHTML = ''; }); describe('alerts.show UI behavior', () => { it('creates a container and renders a notification', () => { const wrapper = window.alerts.show('Hello world', 'info', { duration: 0 }); const container = document.getElementById('notification-container'); expect(container).toBeTruthy(); expect(container.contains(wrapper)).toBe(true); expect(wrapper.className).toMatch(/alert-notification/); }); it('applies styling based on type and aliases', () => { const s = window.alerts.show('ok', 'success', { duration: 0 }); const e = window.alerts.show('bad', 'error', { duration: 0 }); // alias to danger const w = window.alerts.show('warn', 'warning', { duration: 0 }); const i = window.alerts.show('info', 'info', { duration: 0 }); expect(s.className).toContain('bg-green-50'); expect(e.className).toContain('bg-red-50'); expect(w.className).toContain('bg-yellow-50'); expect(i.className).toContain('bg-blue-50'); }); it('renders title when provided', () => { const wrapper = window.alerts.show('Body', 'info', { title: 'My Title', duration: 0 }); const titleEl = wrapper.querySelector('p.text-sm.font-bold'); expect(titleEl).toBeTruthy(); expect(titleEl.textContent).toBe('My Title'); }); it('sanitizes HTML when html option is true', () => { const wrapper = window.alerts.show('

hi

', 'info', { html: true, duration: 0 }); const textEl = wrapper.querySelector('.text-sm.mt-1.font-semibold'); expect(textEl).toBeTruthy(); const html = textEl.innerHTML; expect(html).toContain('hi

'); expect(html).not.toMatch(/