using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.AdminUI.Uns;

namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.Uns;

/// <summary>
/// Verifies <see cref="UnsTreeService.LoadEquipmentPickContextAsync"/> resolves a line to its owning
/// cluster and returns that cluster's lines (for the equipment page's Details-tab line picker), and
/// returns empty option lists when the line is null or cannot be resolved.
/// </summary>
[Trait("Category", "Unit")]
public sealed class UnsTreeServiceEquipmentPickContextTests
{
    private static UnsTreeService SeededService()
    {
        var dbName = $"uns-pickctx-{Guid.NewGuid():N}";
        UnsTreeTestDb.SeedNamed(dbName);
        return new UnsTreeService(UnsTreeTestDb.Factory(dbName));
    }

    [Fact]
    public async Task ResolvesClusterLines_forKnownLine()
    {
        var ctx = await SeededService().LoadEquipmentPickContextAsync("LINE-1");
        ctx.Lines.ShouldContain(o => o.Id == "LINE-1");
    }

    [Fact]
    public async Task Empty_for_null_or_unknown_line()
    {
        var svc = SeededService();
        (await svc.LoadEquipmentPickContextAsync(null)).Lines.ShouldBeEmpty();
        (await svc.LoadEquipmentPickContextAsync("NOPE")).Lines.ShouldBeEmpty();
    }
}
