Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stsrki committed Oct 14, 2023
1 parent 366a5b8 commit a681f99
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 19 deletions.
29 changes: 22 additions & 7 deletions Tests/BasicTestApp.Client/ValidateAnnotationsComponent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Validation>
<TextEdit @bind-Text="@autoModelForName.Name">
<Feedback>
<ValidationError>error</ValidationError>
<ValidationError></ValidationError>
</Feedback>
</TextEdit>
</Validation>
Expand All @@ -19,7 +19,7 @@
<Validation>
<TextEdit @bind-Text="@autoModelForName2.Name">
<Feedback>
<ValidationError>error</ValidationError>
<ValidationError></ValidationError>
</Feedback>
</TextEdit>
</Validation>
Expand All @@ -33,7 +33,7 @@
<Validation>
<TextEdit @bind-Text="@autoModelForName.Password">
<Feedback>
<ValidationError>error</ValidationError>
<ValidationError></ValidationError>
</Feedback>
</TextEdit>
</Validation>
Expand All @@ -45,7 +45,7 @@
<Validation>
<TextEdit @bind-Text="@autoModelForName2.Password">
<Feedback>
<ValidationError>error</ValidationError>
<ValidationError></ValidationError>
</Feedback>
</TextEdit>
</Validation>
Expand All @@ -60,7 +60,7 @@
<Validation MessageLocalizer="@((m,a)=>a?.Count() > 0 ? string.Format(m,a?.ToArray()) : m)">
<TextEdit @bind-Text="@autoModelForName.PasswordWithDisplay">
<Feedback>
<ValidationError>error</ValidationError>
<ValidationError></ValidationError>
</Feedback>
</TextEdit>
</Validation>
Expand All @@ -75,7 +75,7 @@
<Validation>
<TextEdit @bind-Text="@manualModelForName.Name">
<Feedback>
<ValidationError>error</ValidationError>
<ValidationError></ValidationError>
</Feedback>
</TextEdit>
</Validation>
Expand All @@ -88,16 +88,31 @@
<Validation>
<TextEdit @bind-Text="@manualModelForName2.Name">
<Feedback>
<ValidationError>error</ValidationError>
<ValidationError></ValidationError>
</Feedback>
</TextEdit>
</Validation>
</Validations>
<Button Clicked="@(()=>manualValidationsName2Ref.ValidateAll())">Validate</Button>
</div>

<h2>Auto name validation with override message</h2>
<div id="auto-validate-name-initially-populated-error-override">
Initially populated:
<Validations Model="@autoModelForName3" ValidateOnLoad>
<Validation>
<TextEdit @bind-Text="@autoModelForName3.Name">
<Feedback>
<ValidationError>error override message</ValidationError>
</Feedback>
</TextEdit>
</Validation>
</Validations>
</div>
@code {
User autoModelForName = new();
User autoModelForName2 = new() { Name = "a", Password = "12345" };
User autoModelForName3 = new() { Name = "a", Password = "12345" };

User manualModelForName = new();
User manualModelForName2 = new() { Name = "a", Password = "12345" };
Expand Down
24 changes: 12 additions & 12 deletions Tests/BasicTestApp.Client/ValidateSelectComponent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<SelectItem Value="@("George")">George</SelectItem>
</ChildContent>
<Feedback>
<ValidationError>error</ValidationError>
<ValidationError></ValidationError>
</Feedback>
</Select>
</Validation>
Expand All @@ -30,7 +30,7 @@
<SelectItem Value="@("George")">George</SelectItem>
</ChildContent>
<Feedback>
<ValidationError>error</ValidationError>
<ValidationError></ValidationError>
</Feedback>
</Select>
</Validation>
Expand All @@ -47,7 +47,7 @@
<SelectItem Value="@("George")">George</SelectItem>
</ChildContent>
<Feedback>
<ValidationError>error</ValidationError>
<ValidationError></ValidationError>
</Feedback>
</Select>
</Validation>
Expand All @@ -66,7 +66,7 @@
<SelectItem Value="@("George")">George</SelectItem>
</ChildContent>
<Feedback>
<ValidationError>error</ValidationError>
<ValidationError></ValidationError>
</Feedback>
</Select>
</Validation>
Expand All @@ -83,7 +83,7 @@
<SelectItem Value="@("George")">George</SelectItem>
</ChildContent>
<Feedback>
<ValidationError>error</ValidationError>
<ValidationError></ValidationError>
</Feedback>
</Select>
</Validation>
Expand All @@ -101,7 +101,7 @@
<SelectItem Value="4">4</SelectItem>
</ChildContent>
<Feedback>
<ValidationError>error</ValidationError>
<ValidationError></ValidationError>
</Feedback>
</Select>
</Validation>
Expand All @@ -120,7 +120,7 @@
<SelectItem Value="4">4</SelectItem>
</ChildContent>
<Feedback>
<ValidationError>error</ValidationError>
<ValidationError></ValidationError>
</Feedback>
</Select>
</Validation>
Expand All @@ -137,7 +137,7 @@
<SelectItem Value="4">4</SelectItem>
</ChildContent>
<Feedback>
<ValidationError>error</ValidationError>
<ValidationError></ValidationError>
</Feedback>
</Select>
</Validation>
Expand All @@ -155,7 +155,7 @@
<SelectItem Value="@("George")">George</SelectItem>
</ChildContent>
<Feedback>
<ValidationError>error</ValidationError>
<ValidationError></ValidationError>
</Feedback>
</Select>
</Validation>
Expand All @@ -172,7 +172,7 @@
<SelectItem Value="SelectableValues.Last">Last</SelectItem>
</ChildContent>
<Feedback>
<ValidationError>error</ValidationError>
<ValidationError></ValidationError>
</Feedback>
</Select>
</Validation>
Expand All @@ -190,7 +190,7 @@
<SelectItem Value="SelectableValues.Last">Last</SelectItem>
</ChildContent>
<Feedback>
<ValidationError>error</ValidationError>
<ValidationError></ValidationError>
</Feedback>
</Select>
</Validation>
Expand All @@ -206,7 +206,7 @@
<SelectItem Value="SelectableValues.Last">Last</SelectItem>
</ChildContent>
<Feedback>
<ValidationError>error</ValidationError>
<ValidationError></ValidationError>
</Feedback>
</Select>
</Validation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class ValidateAnnotationsComponentTest : TestContext
private const string NameRequired = "The Name field is required.";
private const string PasswordLength = "The field Password must be a string with a minimum length of 5 and a maximum length of 8.";
private const string PasswordWithDisplayLength = "The field DisplayName:Some.Custom.Name must be a string with a minimum length of 5 and a maximum length of 8.";
private const string ErrorOverride = "error override message";

public ValidateAnnotationsComponentTest()
{
Expand Down Expand Up @@ -209,4 +210,27 @@ public void CanManuallyValidateName_InitiallyPopulated()
btn.Click();
Assert.Contains( "is-valid", edit.ClassList );
}

[Fact]
public void CanAutoValidateName_InitiallyPopulated_ErrorOverride()
{
// setup
var comp = RenderComponent<ValidateAnnotationsComponent>();
var edit = comp.Find( "#auto-validate-name-initially-populated-error-override input" );

Assert.Contains( "is-valid", edit.ClassList );

// test 1
edit.Input( string.Empty );
Assert.Contains( "is-invalid", edit.ClassList );

var feedback = comp.Find( "#auto-validate-name-initially-populated-error-override .invalid-feedback" );

Assert.NotNull( feedback );
Assert.Contains( ErrorOverride, feedback.TextContent );

// test 2
edit.Input( "b" );
Assert.Contains( "is-valid", edit.ClassList );
}
}

0 comments on commit a681f99

Please sign in to comment.