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