mirror of
https://github.com/johannesjo/super-productivity.git
synced 2026-01-23 02:36:05 +00:00
- Remove all console.log statements from E2E test files - Replace console.error with throw new Error for proper error handling - Remove console.warn statements - Fix unused variable linting errors in plugin tests
263 lines
9.8 KiB
TypeScript
263 lines
9.8 KiB
TypeScript
import { test, expect } 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';
|
|
const REFRESH_STATS_BTN = 'button:nth-of-type(2)';
|
|
const LOG_ENTRY = '.log-entry';
|
|
|
|
test.describe.serial('Plugin Iframe', () => {
|
|
test.beforeEach(async ({ page, workViewPage }) => {
|
|
test.setTimeout(30000); // Increase timeout for setup
|
|
|
|
await workViewPage.waitForTaskList();
|
|
|
|
// Enable API Test Plugin
|
|
const settingsBtn = page.locator(`${SIDENAV} .tour-settingsMenuBtn`);
|
|
await settingsBtn.waitFor({ state: 'visible' });
|
|
await settingsBtn.click();
|
|
await page.waitForLoadState('networkidle');
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
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 page.waitForLoadState('networkidle');
|
|
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 };
|
|
}, 'API Test Plugin');
|
|
|
|
// Wait for plugin to initialize (3 seconds like successful tests)
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
// 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('API Test Plugin'),
|
|
);
|
|
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');
|
|
}
|
|
|
|
// Navigate to work view
|
|
await page.goto('/#/tag/TODAY');
|
|
await page.waitForLoadState('networkidle');
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
// 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 }) => {
|
|
test.setTimeout(30000); // Increase timeout more
|
|
|
|
// Wait a bit longer after navigation and setup
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
// 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 page.waitForLoadState('networkidle');
|
|
await expect(page).toHaveURL(/\/plugins\/api-test-plugin\/index/);
|
|
await expect(page.locator(PLUGIN_IFRAME)).toBeVisible();
|
|
await page.waitForLoadState('networkidle'); // Wait for iframe content to load
|
|
});
|
|
|
|
test.skip('verify iframe loads with correct content', async ({ page }) => {
|
|
test.setTimeout(30000); // Increase timeout
|
|
|
|
// Navigate directly to the plugin page
|
|
await page.goto('/#/plugins/api-test-plugin/index');
|
|
await page.waitForLoadState('networkidle');
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
// Wait for iframe to be present
|
|
await page.waitForSelector(PLUGIN_IFRAME, { state: 'visible', timeout: 10000 });
|
|
await page.waitForLoadState('networkidle'); // 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('API Test Plugin');
|
|
}
|
|
} catch (error) {}
|
|
});
|
|
|
|
test.skip('test stats loading in iframe', async ({ page, workViewPage }) => {
|
|
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 page.waitForLoadState('networkidle');
|
|
|
|
// 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\/api-test-plugin\/index/, { timeout: 10000 });
|
|
await page.waitForLoadState('networkidle');
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
// Wait for iframe to be present
|
|
await page.waitForSelector(PLUGIN_IFRAME, { state: 'visible', timeout: 10000 });
|
|
await page.waitForLoadState('networkidle'); // 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 page.waitForLoadState('networkidle'); // 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);
|
|
});
|
|
|
|
test.skip('test refresh stats button', async ({ page }) => {
|
|
test.setTimeout(30000); // Increase timeout
|
|
|
|
// 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\/api-test-plugin\/index/, { timeout: 10000 });
|
|
await page.waitForLoadState('networkidle');
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
// Wait for iframe to be present
|
|
await page.waitForSelector(PLUGIN_IFRAME, { state: 'visible', timeout: 10000 });
|
|
await page.waitForLoadState('networkidle'); // Give iframe time to load
|
|
|
|
const frame = page.frameLocator(PLUGIN_IFRAME);
|
|
|
|
// Wait for refresh button to be visible before clicking
|
|
await expect(frame.locator(REFRESH_STATS_BTN)).toBeVisible({ timeout: 10000 });
|
|
await frame.locator(REFRESH_STATS_BTN).click();
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
// Check that a new log entry appears
|
|
const logEntries = await frame.locator(LOG_ENTRY).count();
|
|
expect(logEntries).toBeGreaterThanOrEqual(3);
|
|
});
|
|
});
|