mirror of
https://github.com/radzenhq/radzen-blazor.git
synced 2026-07-08 18:16:08 +00:00
35
Radzen.Blazor.Tests/TemplateFormTests.cs
Normal file
35
Radzen.Blazor.Tests/TemplateFormTests.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Bunit;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Forms;
|
||||
using Xunit;
|
||||
|
||||
namespace Radzen.Blazor.Tests
|
||||
{
|
||||
public class TemplateFormTests
|
||||
{
|
||||
class ContactInfo
|
||||
{
|
||||
[Required]
|
||||
public string Name { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Submit_Passes_EditContext_Model_When_Data_Not_Set()
|
||||
{
|
||||
using var ctx = new TestContext();
|
||||
var model = new ContactInfo { Name = "Alice" };
|
||||
var editContext = new EditContext(model);
|
||||
|
||||
ContactInfo submitted = null;
|
||||
|
||||
var form = ctx.RenderComponent<RadzenTemplateForm<ContactInfo>>(parameters => parameters
|
||||
.Add(p => p.EditContext, editContext)
|
||||
.Add(p => p.Submit, EventCallback.Factory.Create<ContactInfo>(this, value => submitted = value)));
|
||||
|
||||
form.Find("form").Submit();
|
||||
|
||||
Assert.Same(model, submitted);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -181,7 +181,7 @@ namespace Radzen.Blazor
|
||||
|
||||
if (valid)
|
||||
{
|
||||
await Submit.InvokeAsync(Data);
|
||||
await Submit.InvokeAsync(Data ?? (EditContext.Model is TItem model ? model : default));
|
||||
|
||||
if (Action != null && JSRuntime != null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user