using System.Collections.Concurrent;
using Microsoft.Playwright;
namespace ZB.MOM.WW.ScadaBridge.CentralUI.PlaywrightTests;
/// Read-only deployed smoke for CSRF login, bounded lazy topology, and debugger navigation.
[Collection("Playwright")]
public class LowReviewSmokeTests(PlaywrightFixture fixture)
{
[Fact]
public async Task LowReview_CsrfLogin_LazyTopology_AndFlowDebuggerNavigation()
{
var page = await fixture.NewAuthenticatedPageAsync();
var errors = new ConcurrentQueue();
page.PageError += (_, error) => errors.Enqueue(error);
try
{
// Fixture fetch posts the real login form's antiforgery token with its cookie.
Assert.DoesNotContain("/login", page.Url);
await page.GotoAsync($"{PlaywrightFixture.BaseUrl}/deployment/topology");
await Assertions.Expect(page.GetByRole(AriaRole.Heading, new() { Name = "Topology", Exact = true })).ToBeVisibleAsync();
var live = page.Locator("#live-updates");
if (await live.IsCheckedAsync()) await live.UncheckAsync();
await Assertions.Expect(page.Locator("i.bi-box")).ToHaveCountAsync(0);
await Assertions.Expect(page.GetByText("0 loaded instance(s)", new() { Exact = false })).ToBeVisibleAsync();
var site = page.Locator("li[role='treeitem'][aria-level='1']").First;
await Assertions.Expect(site).ToBeVisibleAsync();
var toggle = site.Locator(":scope > .tv-row .tv-toggle").First;
if (await toggle.GetAttributeAsync("aria-expanded") == "false") await toggle.ClickAsync();
await site.GetByRole(AriaRole.Button, new() { Name = "Load instances", Exact = true }).First.ClickAsync();
await Assertions.Expect(site.GetByText("Page 1", new() { Exact = true })).ToBeVisibleAsync();
await Assertions.Expect(site.GetByRole(AriaRole.Button, new() { Name = "Previous", Exact = true })).ToBeDisabledAsync();
await Assertions.Expect(site.GetByRole(AriaRole.Button, new() { Name = "Next", Exact = true })).ToBeVisibleAsync();
Assert.InRange(await site.Locator("i.bi-box").CountAsync(), 0, 50);
await Assertions.Expect(page.Locator("#blazor-error-ui")).ToBeHiddenAsync();
await Assertions.Expect(page.Locator(".alert-danger")).ToHaveCountAsync(0);
await PlaywrightFixture.ExpandAllNavSectionsAsync(page);
await page.GetByRole(AriaRole.Link, new() { Name = "Flow Debugger", Exact = true }).ClickAsync();
await PlaywrightFixture.WaitForPathAsync(page, "/deployment/flow-debugger");
await Assertions.Expect(page.GetByRole(AriaRole.Heading, new() { Name = "Flow Debugger", Exact = true })).ToBeVisibleAsync();
await Assertions.Expect(page.Locator("#blazor-error-ui")).ToBeHiddenAsync();
Assert.Empty(errors);
}
finally { await page.Context.CloseAsync(); }
}
}