/**
* Tests for ShadowDOMManager
*/
import { ShadowDOMManager } from '../ShadowDOMManager';
describe('ShadowDOMManager', () => {
let manager: ShadowDOMManager;
beforeEach(() => {
// Clear any existing shadow hosts
const existing = document.querySelector('#conversioniq-shadow-host');
if (existing) {
existing.remove();
}
});
afterEach(() => {
if (manager) {
manager.destroy();
}
});
describe('Initialization', () => {
it('should initialize with shadow host', () => {
manager = new ShadowDOMManager();
const shadowHost = document.querySelector('#conversioniq-shadow-host');
expect(shadowHost).toBeTruthy();
expect(shadowHost?.tagName).toBe('DIV');
});
it('should create shadow DOM with closed mode', () => {
manager = new ShadowDOMManager();
const shadowHost = document.querySelector('#conversioniq-shadow-host') as HTMLElement;
expect(shadowHost).toBeTruthy();
// In closed mode, shadowRoot is not accessible from outside
expect((shadowHost as any).shadowRoot).toBeNull();
});
it('should position shadow host off-screen initially', () => {
manager = new ShadowDOMManager();
const shadowHost = document.querySelector('#conversioniq-shadow-host') as HTMLElement;
const styles = shadowHost.style;
expect(styles.position).toBe('fixed');
expect(styles.top).toBe('-9999px');
expect(styles.left).toBe('-9999px');
});
it('should have zero components initially', () => {
manager = new ShadowDOMManager();
expect(manager.getComponentCount()).toBe(0);
expect(manager.hasVisibleComponents()).toBe(false);
});
});
describe('Modal Creation', () => {
beforeEach(() => {
manager = new ShadowDOMManager();
});
it('should create a modal with content', () => {
const modal = manager.createModal({
content: 'Test modal content'
});
expect(modal).toBeTruthy();
expect(modal.className).toContain('ciq-modal-overlay');
});
it('should create a modal with title', () => {
const modal = manager.createModal({
title: 'Test Title',
content: 'Test content'
});
expect(modal).toBeTruthy();
expect(modal.querySelector('.ciq-modal-title')).toBeTruthy();
expect(modal.querySelector('.ciq-modal-title')?.textContent).toBe('Test Title');
});
it('should sanitize text content by default', () => {
const modal = manager.createModal({
content: 'Safe text'
});
const body = modal.querySelector('.ciq-modal-body');
expect(body?.innerHTML).not.toContain('Message'
});
expect(notification.innerHTML).not.toContain('Title',
content: 'Content'
});
const title = modal.querySelector('.ciq-modal-title');
expect(title?.innerHTML).not.toContain('