fix(e2e): use client-side routing for settings navigation
The PluginSettings component reads the plugin registry once on mount and never re-renders when new plugins register. Using page.goto() for the settings URL re-initializes the SPA, causing PluginSettings to mount before async plugin scripts finish calling registerPluginSettings(). Replace page.goto() with pushState + popstate to do client-side routing. This preserves the already-loaded plugin registrations from the main page, so PluginSettings sees the plugin immediately on mount. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
+14
-6
@@ -2,10 +2,12 @@ import { test, expect, Page } from '@playwright/test';
|
|||||||
|
|
||||||
/** Navigate to the Polaris plugin settings page and wait for settings to render. */
|
/** Navigate to the Polaris plugin settings page and wait for settings to render. */
|
||||||
async function goToPolarisSettings(page: Page) {
|
async function goToPolarisSettings(page: Page) {
|
||||||
// Load the main page first so Headlamp fetches the plugin list and stores
|
// Load the main page first so all plugin scripts execute and call
|
||||||
// it in localStorage (headlampPluginSettings). The PluginSettings component
|
// registerPluginSettings(). Headlamp loads plugins asynchronously — the
|
||||||
// initializes its state from localStorage on mount, so the data must already
|
// PluginSettings component reads the plugin registry once on mount and
|
||||||
// be there before we navigate to the settings page.
|
// never re-renders when new plugins register. A full page.goto() to the
|
||||||
|
// settings URL would re-initialize the SPA, causing PluginSettings to
|
||||||
|
// mount before plugin scripts finish executing.
|
||||||
await page.goto('/');
|
await page.goto('/');
|
||||||
const sidebar = page.getByRole('navigation', { name: 'Navigation' });
|
const sidebar = page.getByRole('navigation', { name: 'Navigation' });
|
||||||
await expect(sidebar).toBeVisible({ timeout: 15_000 });
|
await expect(sidebar).toBeVisible({ timeout: 15_000 });
|
||||||
@@ -13,8 +15,14 @@ async function goToPolarisSettings(page: Page) {
|
|||||||
timeout: 15_000,
|
timeout: 15_000,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Now navigate to plugin settings — localStorage has the plugin list
|
// Navigate to plugin settings via client-side routing (pushState + popstate)
|
||||||
await page.goto('/c/main/settings/plugins');
|
// instead of page.goto(). This preserves the already-loaded plugin scripts
|
||||||
|
// and their registerPluginSettings() registrations. React Router's history
|
||||||
|
// listener picks up the popstate event and re-renders with the new route.
|
||||||
|
await page.evaluate(() => {
|
||||||
|
window.history.pushState({}, '', '/c/main/settings/plugins');
|
||||||
|
window.dispatchEvent(new PopStateEvent('popstate', { state: {} }));
|
||||||
|
});
|
||||||
|
|
||||||
// Find and click the Polaris plugin entry to open its settings
|
// Find and click the Polaris plugin entry to open its settings
|
||||||
const pluginEntry = page.locator('text=headlamp-polaris').first();
|
const pluginEntry = page.locator('text=headlamp-polaris').first();
|
||||||
|
|||||||
Reference in New Issue
Block a user