import { expect, test } from '../../fixtures/test.fixture'; import { cssSelectors } from '../../constants/selectors'; const { SIDENAV } = cssSelectors; // Plugin-related selectors const PLUGIN_MENU_ITEM = `${SIDENAV} plugin-menu button`; const PLUGIN_IFRAME = 'plugin-index iframe'; // Iframe content selectors (used within iframe context) const TASK_COUNT = '#taskCount'; const PROJECT_COUNT = '#projectCount'; const TAG_COUNT = '#tagCount'; test.describe.serial('Plugin Iframe', () => { test.beforeEach(async ({ page, workViewPage, waitForNav }) => { await workViewPage.waitForTaskList(); // Enable Yesterday's Tasks const settingsBtn = page.locator(`${SIDENAV} .tour-settingsMenuBtn`); await settingsBtn.waitFor({ state: 'visible' }); await settingsBtn.click(); await page.locator('formly-form').waitFor({ state: 'visible' }); await page.waitForSelector('formly-form'); await page.waitForTimeout(500); await page.evaluate(() => { const configPage = document.querySelector('.page-settings'); if (!configPage) { throw new Error('Not on config page'); } const pluginSection = document.querySelector('.plugin-section'); if (pluginSection) { pluginSection.scrollIntoView({ behavior: 'smooth', block: 'center' }); } const collapsible = document.querySelector('.plugin-section collapsible'); if (collapsible) { const isExpanded = collapsible.classList.contains('isExpanded'); if (!isExpanded) { const header = collapsible.querySelector('.collapsible-header'); if (header) { (header as HTMLElement).click(); } } } }); await waitForNav(); await expect(page.locator('plugin-management')).toBeVisible({ timeout: 5000 }); // Enable the plugin await page.evaluate((pluginName: string) => { const cards = Array.from(document.querySelectorAll('plugin-management mat-card')); const targetCard = cards.find((card) => { const title = card.querySelector('mat-card-title')?.textContent || ''; return title.includes(pluginName); }); if (targetCard) { const toggleButton = targetCard.querySelector( 'mat-slide-toggle button[role="switch"]', ) as HTMLButtonElement; if (toggleButton) { const wasChecked = toggleButton.getAttribute('aria-checked') === 'true'; if (!wasChecked) { toggleButton.click(); } return { found: true, wasEnabled: wasChecked, clicked: !wasChecked, }; } return { found: true, hasToggle: false }; } return { found: false }; }, "Yesterday's Tasks"); // Wait for plugin to initialize (3 seconds like successful tests) await waitForNav(); // Verify plugin is actually enabled before proceeding const verifyEnabled = await page.evaluate(() => { const cards = Array.from(document.querySelectorAll('plugin-management mat-card')); const apiCard = cards.find((card) => card.querySelector('mat-card-title')?.textContent?.includes("Yesterday's Tasks"), ); const toggle = apiCard?.querySelector( 'mat-slide-toggle button[role="switch"]', ) as HTMLButtonElement; return toggle?.getAttribute('aria-checked') === 'true'; }); if (!verifyEnabled) { // Plugin did not enable properly, waiting more... await page.waitForLoadState('networkidle'); await page.waitForTimeout(200); } // Navigate to work view await page.goto('/#/tag/TODAY'); await waitForNav(); await waitForNav(); // Wait for task list to be visible and dismiss any dialogs await page.waitForSelector('task-list', { state: 'visible', timeout: 10000 }); // Dismiss tour dialog if it appears const tourDialog = page.locator('[data-shepherd-step-id="Welcome"]'); if (await tourDialog.isVisible({ timeout: 1000 }).catch(() => false)) { const cancelBtn = page.locator( 'button:has-text("No thanks"), .shepherd-cancel-icon', ); if (await cancelBtn.isVisible({ timeout: 1000 }).catch(() => false)) { await cancelBtn.click(); await page.waitForLoadState('domcontentloaded'); } } // Skip adding tasks for now - they're not essential for plugin tests // and they're causing timeouts }); test('open plugin iframe view', async ({ page, waitForNav }) => { // Wait a bit longer after navigation and setup await waitForNav(); // Debug: Check if we're on the right page and plugin menu exists await page.evaluate(() => { const menu = document.querySelector('side-nav plugin-menu'); const buttons = menu ? menu.querySelectorAll('button') : []; return { url: window.location.href, hasMenu: !!menu, menuClass: menu?.className || '', buttonCount: buttons.length, buttonTexts: Array.from(buttons).map((b) => b.textContent?.trim() || ''), }; }); // Check if plugin menu item is visible with longer timeout await expect(page.locator(PLUGIN_MENU_ITEM)).toBeVisible({ timeout: 15000 }); await page.click(PLUGIN_MENU_ITEM); await waitForNav(); await expect(page).toHaveURL(/\/plugins\/yesterday-tasks-plugin\/index/); await expect(page.locator(PLUGIN_IFRAME)).toBeVisible(); await waitForNav(); // Wait for iframe content to load }); test.skip('verify iframe loads with correct content', async ({ page, waitForNav }) => { // Navigate directly to the plugin page await page.goto('/#/plugins/yesterday-tasks-plugin/index'); await waitForNav(); await waitForNav(); // Wait for iframe to be present await page.waitForSelector(PLUGIN_IFRAME, { state: 'visible', timeout: 10000 }); await waitForNav(); // Give iframe more time to load // Check iframe is loaded const iframe = await page.$(PLUGIN_IFRAME); expect(iframe).toBeTruthy(); // Try to access iframe content with better error handling try { const frame = page.frameLocator(PLUGIN_IFRAME); // Wait for any element in the iframe to ensure it's loaded await frame.locator('body').waitFor({ state: 'visible', timeout: 5000 }); // Check for h1 element const h1Visible = await frame .locator('h1') .isVisible({ timeout: 5000 }) .catch(() => false); if (h1Visible) { await expect(frame.locator('h1')).toContainText("Yesterday's Tasks"); } } catch (error) {} }); test.skip('test stats loading in iframe', async ({ page, workViewPage, waitForNav, }) => { test.setTimeout(30000); // Increase timeout // Add some tasks for this specific test await workViewPage.addTask('Test Task 1'); await workViewPage.addTask('Test Task 2'); await workViewPage.addTask('Test Task 3'); await waitForNav(); // Ensure we're on the work view page await page.waitForSelector('task-list', { state: 'visible', timeout: 5000 }); // Wait for plugin menu to be available and click it await page.waitForSelector(PLUGIN_MENU_ITEM, { state: 'visible', timeout: 5000 }); await page.click(PLUGIN_MENU_ITEM); // Wait for navigation to plugin page await expect(page).toHaveURL(/\/plugins\/yesterday-tasks-plugin\/index/, { timeout: 10000, }); await waitForNav(); // Wait for iframe to be present await page.waitForSelector(PLUGIN_IFRAME, { state: 'visible', timeout: 10000 }); await waitForNav(); // Give iframe time to load const frame = page.frameLocator(PLUGIN_IFRAME); await expect(frame.locator(TASK_COUNT)).toBeVisible({ timeout: 10000 }); // Stats should auto-load on init, check values await waitForNav(); // Wait for stats to load const taskCount = await frame.locator(TASK_COUNT).textContent(); expect(taskCount).toBe('3'); const projectCount = await frame.locator(PROJECT_COUNT).textContent(); expect(parseInt(projectCount || '0')).toBeGreaterThanOrEqual(1); const tagCount = await frame.locator(TAG_COUNT).textContent(); expect(parseInt(tagCount || '0')).toBeGreaterThanOrEqual(1); }); });