fix(tests): make WYSIWYG tests more robust and deterministic by initializing and attaching elements consistently, awaiting customElements/firstUpdated, adjusting selectors and assertions, and cleaning up DOM after tests

This commit is contained in:
2025-12-30 12:24:16 +00:00
parent 7acca2c8e7
commit 05409e89d2
9 changed files with 227 additions and 200 deletions

View File

@@ -4,19 +4,20 @@ import { WysiwygSelection } from '../ts_web/elements/00group-input/dees-input-wy
tap.test('Shadow DOM containment should work correctly', async () => {
console.log('=== Testing Shadow DOM Containment ===');
// Create a WYSIWYG block component
const block = await webhelpers.fixture<DeesWysiwygBlock>(
'<dees-wysiwyg-block></dees-wysiwyg-block>'
);
// Set the block data
// Wait for custom element to be defined
await customElements.whenDefined('dees-wysiwyg-block');
// Create a WYSIWYG block component - set properties BEFORE attaching to DOM
const block = document.createElement('dees-wysiwyg-block') as DeesWysiwygBlock;
// Set the block data before attaching to DOM so firstUpdated() sees them
block.block = {
id: 'test-1',
type: 'paragraph',
content: 'Hello world test content'
};
block.handlers = {
onInput: () => {},
onKeyDown: () => {},
@@ -25,8 +26,12 @@ tap.test('Shadow DOM containment should work correctly', async () => {
onCompositionStart: () => {},
onCompositionEnd: () => {}
};
// Now attach to DOM and wait for render
document.body.appendChild(block);
await block.updateComplete;
// Wait for firstUpdated to populate the container
await new Promise(resolve => setTimeout(resolve, 50));
// Get the paragraph element inside Shadow DOM
const container = block.shadowRoot?.querySelector('.wysiwyg-block-container') as HTMLElement;
@@ -93,6 +98,9 @@ tap.test('Shadow DOM containment should work correctly', async () => {
expect(splitResult.after).toEqual(' test content');
}
}
// Clean up
document.body.removeChild(block);
});
tap.test('Shadow DOM containment across different shadow roots', async () => {