using Microsoft.Playwright;
using System.Text.Json;
using ZB.MOM.WW.ScadaBridge.CentralUI.PlaywrightTests.Cluster;
namespace ZB.MOM.WW.ScadaBridge.CentralUI.PlaywrightTests.Admin;
///
/// End-to-end CRUD round-trip for the LDAP Group Mappings admin page.
/// Covers create → edit → delete via the UI against the running dev cluster.
///
[Collection("Playwright")]
public class LdapMappingCrudTests
{
private readonly PlaywrightFixture _fixture;
public LdapMappingCrudTests(PlaywrightFixture fixture)
{
_fixture = fixture;
}
[SkippableFact]
public async Task CreateEditDelete_LdapMapping_RoundTrips()
{
Skip.IfNot(await ClusterAvailability.IsAvailableAsync(), ClusterAvailability.SkipReason);
// Truncated to 18 chars to stay within the form field's maximum input length
// while still being unique (the zztest-grp- prefix + 7 hex chars from the GUID).
var group = $"zztest-grp-{Guid.NewGuid():N}"[..18];
var page = await _fixture.NewAuthenticatedPageAsync();
try
{
// ── CREATE ────────────────────────────────────────────────────────────────
await page.GotoAsync($"{PlaywrightFixture.BaseUrl}/admin/ldap-mappings/create");
await page.WaitForLoadStateAsync(LoadState.NetworkIdle);
// The LDAP Group Name label has no `for=` attribute so GetByLabel does not
// work. Locate the input that immediately follows the label text instead.
await page.Locator("label:has-text('LDAP Group Name') + input.form-control.form-control-sm").FillAsync(group);
// Scope the role select to the div.mb-2 that owns the "Role" label so a
// second select (Site Scope) on the edit page cannot cause a strict-mode
// violation. The LdapMappingForm.razor uses Blazor @bind, not