test(ui/templates): cover drag-template-to-root via bUnit DragEventArgs
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.Security.Claims;
|
||||
using Bunit;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.AspNetCore.Components.Web;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NSubstitute;
|
||||
using ScadaLink.Commons.Entities.Templates;
|
||||
@@ -118,6 +119,42 @@ public class TemplatesPageTests : BunitContext
|
||||
Assert.Contains("DelmiaReceiver", cut.Markup);
|
||||
Assert.Contains("→", cut.Markup);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DragTemplateOntoRoot_CallsMoveTemplateAsync_WithNullFolderId()
|
||||
{
|
||||
// Arrange: one template currently parented to a folder; the test simulates
|
||||
// the user dragging that template onto the root drop-zone, which should
|
||||
// result in TemplateService.MoveTemplateAsync(..., newFolderId: null) being
|
||||
// invoked. We keep the template at the root in the rendered tree (FolderId
|
||||
// null) so it renders without needing an expand-click; the drag payload only
|
||||
// cares about the in-memory id captured by OnDragStart, not the visual
|
||||
// parent.
|
||||
var template = new Template("RootDragTarget") { Id = 5, FolderId = null };
|
||||
_repo.GetAllTemplatesAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<Template>>(new List<Template> { template }));
|
||||
_repo.GetAllFoldersAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<TemplateFolder>>(new List<TemplateFolder>()));
|
||||
_repo.GetTemplateByIdAsync(5, Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<Template?>(template));
|
||||
|
||||
var cut = Render<TemplatesPage>();
|
||||
|
||||
// Act: fire ondragstart on the template's draggable <div> (RenderNodeLabel
|
||||
// emits draggable="true" for template/folder nodes), then ondrop on the
|
||||
// root wrapper marked with the test-affordance class added to the page.
|
||||
var templateNode = cut.Find("div[draggable='true']");
|
||||
await templateNode.TriggerEventAsync("ondragstart", new DragEventArgs());
|
||||
|
||||
var rootDropZone = cut.Find("div.templates-root-dropzone");
|
||||
await rootDropZone.TriggerEventAsync("ondrop", new DragEventArgs());
|
||||
|
||||
// Assert: TemplateService.MoveTemplateAsync delegates to the repository's
|
||||
// UpdateTemplateAsync with FolderId set to null.
|
||||
await _repo.Received(1).UpdateTemplateAsync(
|
||||
Arg.Is<Template>(t => t.Id == 5 && t.FolderId == null),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class TestAuthStateProvider : AuthenticationStateProvider
|
||||
|
||||
Reference in New Issue
Block a user