107 lines
3.4 KiB
C#
107 lines
3.4 KiB
C#
using Microsoft.Playwright;
|
|
|
|
namespace JdeScoping.Ui.Tests.Helpers;
|
|
|
|
internal static class UiNavigationHelper
|
|
{
|
|
public static async Task NavigateToSearchPageAsync(IPage page)
|
|
{
|
|
await page.GotoAsync("/search");
|
|
await page.WaitForLoadStateAsync(LoadState.NetworkIdle);
|
|
await UiAuthHelper.LoginAsync(page);
|
|
await EnsureAuthenticatedOrThrowAsync(page);
|
|
await WaitForBlazorReadyAsync(page);
|
|
}
|
|
|
|
public static async Task NavigateToSearchesDashboardAsync(IPage page)
|
|
{
|
|
await page.GotoAsync("/searches");
|
|
await page.WaitForLoadStateAsync(LoadState.NetworkIdle);
|
|
await UiAuthHelper.LoginAsync(page);
|
|
await EnsureAuthenticatedOrThrowAsync(page);
|
|
await WaitForBlazorReadyAsync(page);
|
|
}
|
|
|
|
public static async Task NavigateToQueueAsync(IPage page)
|
|
{
|
|
await page.GotoAsync("/search/queue");
|
|
await page.WaitForLoadStateAsync(LoadState.NetworkIdle);
|
|
await UiAuthHelper.LoginAsync(page);
|
|
await EnsureAuthenticatedOrThrowAsync(page);
|
|
await WaitForBlazorReadyAsync(page);
|
|
}
|
|
|
|
public static async Task NavigateToRefreshStatusAsync(IPage page)
|
|
{
|
|
await page.GotoAsync("/refresh-status");
|
|
await page.WaitForLoadStateAsync(LoadState.NetworkIdle);
|
|
await UiAuthHelper.LoginAsync(page);
|
|
await EnsureAuthenticatedOrThrowAsync(page);
|
|
await WaitForBlazorReadyAsync(page);
|
|
}
|
|
|
|
public static async Task NavigateToDataSyncAsync(IPage page)
|
|
{
|
|
await page.GotoAsync("/data-sync/requests");
|
|
await page.WaitForLoadStateAsync(LoadState.NetworkIdle);
|
|
await UiAuthHelper.LoginAsync(page);
|
|
await EnsureAuthenticatedOrThrowAsync(page);
|
|
await WaitForBlazorReadyAsync(page);
|
|
}
|
|
|
|
public static async Task NavigateToLoginAsync(IPage page)
|
|
{
|
|
await page.GotoAsync("/login");
|
|
await page.WaitForLoadStateAsync(LoadState.NetworkIdle);
|
|
}
|
|
|
|
private static async Task WaitForBlazorReadyAsync(IPage page)
|
|
{
|
|
var timeoutMs = 15_000;
|
|
try
|
|
{
|
|
await page.Locator(".rz-dropdown").First.WaitForAsync(new LocatorWaitForOptions
|
|
{
|
|
State = WaitForSelectorState.Visible,
|
|
Timeout = timeoutMs
|
|
});
|
|
return;
|
|
}
|
|
catch (PlaywrightException)
|
|
{
|
|
// Try additional readiness markers.
|
|
}
|
|
|
|
try
|
|
{
|
|
await page.Locator(".rz-data-grid").First.WaitForAsync(new LocatorWaitForOptions
|
|
{
|
|
State = WaitForSelectorState.Visible,
|
|
Timeout = timeoutMs
|
|
});
|
|
return;
|
|
}
|
|
catch (PlaywrightException)
|
|
{
|
|
// Try text marker as final fallback.
|
|
}
|
|
|
|
await page.GetByText("Search Details").First.WaitForAsync(new LocatorWaitForOptions
|
|
{
|
|
State = WaitForSelectorState.Visible,
|
|
Timeout = timeoutMs
|
|
});
|
|
await page.WaitForTimeoutAsync(1_000);
|
|
}
|
|
|
|
private static async Task EnsureAuthenticatedOrThrowAsync(IPage page)
|
|
{
|
|
var meResponse = await page.Context.APIRequest.GetAsync("/api/auth/me");
|
|
if (meResponse.Status != 200)
|
|
{
|
|
throw new InvalidOperationException(
|
|
$"UI test host did not establish authenticated session after login. /api/auth/me status={meResponse.Status}.");
|
|
}
|
|
}
|
|
}
|