Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
- Comments added
- Testing focus and blur functionalities
  • Loading branch information
joao4all committed Oct 6, 2023
1 parent 76cac83 commit 757363e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
35 changes: 34 additions & 1 deletion COMET.Web.Common.Tests/Components/LoginTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

namespace COMET.Web.Common.Tests.Components
{
using AngleSharp.Dom;

using Bunit;

using COMET.Web.Common.Components;
Expand All @@ -36,8 +38,9 @@ namespace COMET.Web.Common.Tests.Components
using COMET.Web.Common.ViewModels.Components;

using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.Extensions.DependencyInjection;

using Microsoft.JSInterop;
using Moq;

using NUnit.Framework;
Expand Down Expand Up @@ -70,6 +73,36 @@ public void Teardown()
this.context.CleanContext();
}

[Test]
public async Task VerifyFocusingAndBluring()

Check warning on line 77 in COMET.Web.Common.Tests/Components/LoginTestFixture.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 77 in COMET.Web.Common.Tests/Components/LoginTestFixture.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 77 in COMET.Web.Common.Tests/Components/LoginTestFixture.cs

View workflow job for this annotation

GitHub Actions / Build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
var renderer = this.context.RenderComponent<Login>();

Assert.That(renderer.Instance.FieldsFocusedStatus, Is.EqualTo(new Dictionary<string, bool>()
{
{ "SourceAddress", false },
{ "UserName", false },
{ "Password", false }
}));

Assert.IsFalse(renderer.Instance.FieldsFocusedStatus["UserName"]);
const string fieldToFocusOn = "Username";

renderer.Instance.HandleFieldFocus(fieldToFocusOn);

foreach (var fieldStatus in renderer.Instance.FieldsFocusedStatus)
{
Assert.That(fieldStatus.Value, fieldStatus.Key == fieldToFocusOn ? Is.True : Is.False);
}

renderer.Instance.HandleFieldBlur(fieldToFocusOn);

foreach (var fieldStatus in renderer.Instance.FieldsFocusedStatus)
{
Assert.That(fieldStatus.Value, Is.False);
}
}

[Test]
public async Task VerifyPerformLogin()
{
Expand Down
2 changes: 0 additions & 2 deletions COMET.Web.Common/Components/Login.razor
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@
</DxFormLayoutItem>
</DxFormLayout>

<!-- <ValidationSummary/> -->

<ul class="validation-errors">
@foreach (var fieldFocusedStatus in this.fieldsFocusedStatus)
{
Expand Down
8 changes: 4 additions & 4 deletions COMET.Web.Common/Components/Login.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,17 @@ private async Task ExecuteLogin()
/// <summary>
/// Handles the focus event of the given fieldName
/// </summary>
/// <param name="fieldName"></param>
private void HandleFieldFocus(string fieldName)
/// <param name="fieldName">Form field name, as indexed in <see cref="FieldsFocusedStatus"/></param>
public void HandleFieldFocus(string fieldName)
{
this.fieldsFocusedStatus[fieldName] = true; // Set the field as focused
}

/// <summary>
/// Handles the blur event of the given fieldName
/// </summary>
/// <param name="fieldName"></param>
private void HandleFieldBlur(string fieldName)
/// <param name="fieldName">Form field name, as indexed in <see cref="FieldsFocusedStatus"/></param>
public void HandleFieldBlur(string fieldName)
{
this.fieldsFocusedStatus[fieldName] = false; // Set the field as not focused when it loses focus
}
Expand Down

0 comments on commit 757363e

Please sign in to comment.