test(ui): drive DataConnectionForm tests via NavigationManager for SupplyParameterFromQuery
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.Security.Claims;
|
||||
using System.Text.Json;
|
||||
using Bunit;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NSubstitute;
|
||||
@@ -35,10 +36,17 @@ public class DataConnectionFormTests : BunitContext
|
||||
Services.AddAuthorizationCore();
|
||||
}
|
||||
|
||||
private IRenderedComponent<DataConnectionForm> RenderForCreateSite(int siteId)
|
||||
{
|
||||
Services.GetRequiredService<NavigationManager>()
|
||||
.NavigateTo($"/admin/connections/create?siteId={siteId}");
|
||||
return Render<DataConnectionForm>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NoProtocolDropdown_IsRendered()
|
||||
{
|
||||
var cut = Render<DataConnectionForm>(p => p.Add(f => f.SiteId, 1));
|
||||
var cut = RenderForCreateSite(1);
|
||||
Assert.DoesNotContain("Custom", cut.Markup);
|
||||
var labels = cut.FindAll("label").Select(l => l.TextContent.Trim()).ToList();
|
||||
Assert.DoesNotContain(labels, l => l == "Protocol");
|
||||
@@ -47,7 +55,7 @@ public class DataConnectionFormTests : BunitContext
|
||||
[Fact]
|
||||
public async Task Save_InvalidPrimaryUrl_DoesNotCallRepo()
|
||||
{
|
||||
var cut = Render<DataConnectionForm>(p => p.Add(f => f.SiteId, 1));
|
||||
var cut = RenderForCreateSite(1);
|
||||
cut.FindAll("input[type='text']")
|
||||
.First(i => i.GetAttribute("placeholder")?.StartsWith("opc.tcp") == true)
|
||||
.Change("not-a-url");
|
||||
@@ -72,7 +80,7 @@ public class DataConnectionFormTests : BunitContext
|
||||
await _siteRepo.AddDataConnectionAsync(
|
||||
Arg.Do<DataConnection>(d => captured = d));
|
||||
|
||||
var cut = Render<DataConnectionForm>(p => p.Add(f => f.SiteId, 1));
|
||||
var cut = RenderForCreateSite(1);
|
||||
|
||||
// Name
|
||||
cut.FindAll("input[type='text']")
|
||||
|
||||
Reference in New Issue
Block a user