mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-05 05:27:37 +08:00
8e60219b35
* Add support multiple date formats for DatePickerBase * Fix test * Extend docs * Fix merge * Revert "Add support multiple date formats for DatePickerBase" This reverts commit 9021dcdd * Refactoring. Add mask property for DatePickerBase. For input value constraint. * Some fixes * Refactoring * Add value converter for MaskInput * Some fix * fix Chinese * Refactoring * Fix tests * Fix tests * clean up * Fix tests * Pass mask to RangePicker * Fix AvatarTests * Fix merge * Stage * Stabilized tests --------- Co-authored-by: James Yeung <shunjiey@hotmail.com>
97 lines
3.0 KiB
C#
97 lines
3.0 KiB
C#
using System.Collections.Generic;
|
|
using AntDesign.JsInterop;
|
|
using Bunit;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Xunit;
|
|
|
|
namespace AntDesign.Tests.Form.Validation
|
|
{
|
|
public class FormItemTests : AntDesignTestBase
|
|
{
|
|
public FormItemTests() : base()
|
|
{
|
|
}
|
|
|
|
[Theory]
|
|
[MemberData(nameof(RequiredMarkTestData))]
|
|
public void ItShouldRenderProperRequiredMark(bool isRequired, FormRequiredMark requiredMark, string expectedMarkup)
|
|
{
|
|
JSInterop.Setup<Window>("AntDesign.interop.domInfoHelper.getWindow", _ => true).SetResult(new Window
|
|
{
|
|
InnerHeight = 1000m,
|
|
InnerWidth = 1000m
|
|
});
|
|
|
|
RenderFragment<object> fragment = model => builder =>
|
|
{
|
|
builder.OpenComponent<FormItem>(0);
|
|
|
|
builder.AddAttribute(1, "Label", "Test Label");
|
|
|
|
var validationRules = new FormValidationRule[]
|
|
{
|
|
new()
|
|
{
|
|
Required = isRequired
|
|
}
|
|
};
|
|
|
|
builder.AddAttribute(2, "Rules", validationRules);
|
|
|
|
builder.CloseComponent();
|
|
};
|
|
|
|
var wrappedSystemUnderTest = RenderComponent<Form<object>>(parameters => parameters
|
|
.Add(x => x.ChildContent, fragment)
|
|
.Add(x => x.RequiredMark, requiredMark)
|
|
.Add(x => x.ValidateMode, FormValidateMode.Rules)
|
|
.Add(x => x.Model, new { }));
|
|
|
|
wrappedSystemUnderTest.WaitForAssertion(
|
|
() => wrappedSystemUnderTest
|
|
.FindComponent<FormItem>()
|
|
.Find("label")
|
|
.MarkupMatches(expectedMarkup));
|
|
}
|
|
|
|
public static IEnumerable<object[]> RequiredMarkTestData()
|
|
{
|
|
yield return new object[]{
|
|
true,
|
|
FormRequiredMark.Optional,
|
|
"<label class=\"\">Test Label</label>"
|
|
};
|
|
|
|
yield return new object[]{
|
|
true,
|
|
FormRequiredMark.Required,
|
|
"<label class=\"ant-form-item-required\">Test Label</label>"
|
|
};
|
|
|
|
yield return new object[]{
|
|
true,
|
|
FormRequiredMark.None,
|
|
"<label class=\"\">Test Label</label>"
|
|
};
|
|
|
|
yield return new object[]{
|
|
false,
|
|
FormRequiredMark.Optional,
|
|
"<label class=\"\">Test Label<span class=\"ant-form-item-optional\">(optional)</span></label>"
|
|
};
|
|
|
|
yield return new object[]{
|
|
false,
|
|
FormRequiredMark.Required,
|
|
"<label class=\"\">Test Label</label>"
|
|
};
|
|
|
|
yield return new object[]{
|
|
false,
|
|
FormRequiredMark.None,
|
|
"<label class=\"\">Test Label</label>"
|
|
};
|
|
}
|
|
}
|
|
}
|