const { test, expect } = require('@playwright/test'); const { HVACTestBase } = require('./page-objects/HVACTestBase'); /** * Rich Text Editor Comprehensive Test Suite * * Tests the contentEditable-based rich text editor including: * - Toolbar functionality and commands * - Content synchronization between editor and textarea * - XSS prevention and content sanitization * - Keyboard shortcuts and accessibility * - Character limits and validation * - Deprecated API usage handling */ test.describe('Rich Text Editor Functionality', () => { let hvacTest; test.beforeEach(async ({ page }) => { hvacTest = new HVACTestBase(page); await hvacTest.loginAsTrainer(); await hvacTest.navigateToCreateEvent(); // Wait for rich text editor to be ready await expect(page.locator('#event-description-editor')).toBeVisible(); await expect(page.locator('#event-description-toolbar')).toBeVisible(); }); test.describe('Basic Editor Functionality', () => { test('should initialize rich text editor correctly', async ({ page }) => { // Verify editor elements are present await expect(page.locator('#event-description-editor')).toBeVisible(); await expect(page.locator('#event-description-toolbar')).toBeVisible(); await expect(page.locator('#event_description')).toBeVisible(); // Verify editor is contentEditable const isEditable = await page.locator('#event-description-editor').getAttribute('contenteditable'); expect(isEditable).toBe('true'); // Verify initial state const editorContent = await page.locator('#event-description-editor').innerHTML(); expect(editorContent.trim()).toBe(''); }); test('should allow text input and maintain focus', async ({ page }) => { const testText = 'This is a test of the rich text editor.'; await page.click('#event-description-editor'); await page.keyboard.type(testText); const editorContent = await page.locator('#event-description-editor').textContent(); expect(editorContent).toBe(testText); // Verify focus is maintained const focused = await page.evaluate(() => document.activeElement.id === 'event-description-editor' ); expect(focused).toBe(true); }); test('should synchronize content between editor and hidden textarea', async ({ page }) => { const testContent = '
Test paragraph with bold text.
'; // Set content in editor await page.click('#event-description-editor'); await page.locator('#event-description-editor').fill(testContent); // Trigger content sync (blur event) await page.click('body'); // Verify content is synchronized to hidden textarea const textareaValue = await page.locator('#event_description').inputValue(); expect(textareaValue).toContain('Test paragraph'); expect(textareaValue).toContain('bold text'); }); test('should restore content from hidden textarea on page reload', async ({ page }) => { const testContent = 'Persistent content test
'; // Set initial content await page.locator('#event_description').fill(testContent); // Reload page to test content restoration await page.reload(); await hvacTest.navigateToCreateEvent(); // Verify content is restored in editor const restoredContent = await page.locator('#event-description-editor').innerHTML(); expect(restoredContent).toContain('Persistent content test'); }); }); test.describe('Toolbar Commands', () => { test('should execute bold command correctly', async ({ page }) => { await page.click('#event-description-editor'); await page.keyboard.type('Bold test'); // Select the text await page.keyboard.press('Control+a'); // Click bold button await page.click('[data-command="bold"]'); const editorContent = await page.locator('#event-description-editor').innerHTML(); expect(editorContent).toContain('Bold test'); }); test('should execute italic command correctly', async ({ page }) => { await page.click('#event-description-editor'); await page.keyboard.type('Italic test'); await page.keyboard.press('Control+a'); await page.click('[data-command="italic"]'); const editorContent = await page.locator('#event-description-editor').innerHTML(); expect(editorContent).toContain('Italic test'); }); test('should execute underline command correctly', async ({ page }) => { await page.click('#event-description-editor'); await page.keyboard.type('Underline test'); await page.keyboard.press('Control+a'); await page.click('[data-command="underline"]'); const editorContent = await page.locator('#event-description-editor').innerHTML(); expect(editorContent).toContain('Underline test'); }); test('should create ordered lists', async ({ page }) => { await page.click('#event-description-editor'); await page.keyboard.type('List item 1'); await page.click('[data-command="insertOrderedList"]'); const editorContent = await page.locator('#event-description-editor').innerHTML(); expect(editorContent).toContain('