Skip to content

Commit

Permalink
Requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
joao4all committed Oct 6, 2023
1 parent 757363e commit 5a4084b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 28 deletions.
29 changes: 16 additions & 13 deletions COMET.Web.Common.Tests/Components/LoginTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

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

using Bunit;

using COMET.Web.Common.Components;
Expand All @@ -40,7 +38,7 @@ namespace COMET.Web.Common.Tests.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 @@ -85,22 +83,27 @@ public async Task VerifyFocusingAndBluring()
{ "Password", false }
}));

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

const string fieldToFocusOn = "UserName";
Assert.That(renderer.Instance.FieldsFocusedStatus[fieldToFocusOn], Is.False);
renderer.Instance.HandleFieldFocus(fieldToFocusOn);

foreach (var fieldStatus in renderer.Instance.FieldsFocusedStatus)
Assert.Multiple(()=>
{
Assert.That(fieldStatus.Value, fieldStatus.Key == fieldToFocusOn ? Is.True : Is.False);
}
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.Multiple(() =>
{
Assert.That(fieldStatus.Value, Is.False);
}
foreach (var fieldStatus in renderer.Instance.FieldsFocusedStatus)
{
Assert.That(fieldStatus.Value, Is.False);
}
});
}

[Test]
Expand Down
2 changes: 1 addition & 1 deletion COMET.Web.Common/Components/Login.razor
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
</DxFormLayout>

<ul class="validation-errors">
@foreach (var fieldFocusedStatus in this.fieldsFocusedStatus)
@foreach (var fieldFocusedStatus in this.FieldsFocusedStatus)
{
if (fieldFocusedStatus.Value)
{
Expand Down
19 changes: 5 additions & 14 deletions COMET.Web.Common/Components/Login.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,9 @@ public partial class Login
public bool LoginEnabled { get; set; } = true;

/// <summary>
/// The dictionary of focus status from the fields, used by blazor component
/// The dictionary of focus status from the form fields
/// </summary>
private Dictionary<string, bool> fieldsFocusedStatus;

/// <summary>
/// The dictionary of focus status from the fields
/// </summary>
public Dictionary<string, bool> FieldsFocusedStatus
{
get => this.fieldsFocusedStatus;
private set => this.fieldsFocusedStatus = value;
}
public Dictionary<string, bool> FieldsFocusedStatus { get; private set; }

/// <summary>
/// Method invoked when the component is ready to start, having received its
Expand All @@ -87,7 +78,7 @@ protected override void OnInitialized()
{
base.OnInitialized();

this.fieldsFocusedStatus = new Dictionary<string, bool>()
this.FieldsFocusedStatus = new Dictionary<string, bool>()
{
{ "SourceAddress", false },
{ "UserName", false },
Expand Down Expand Up @@ -149,7 +140,7 @@ private async Task ExecuteLogin()
/// <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
this.FieldsFocusedStatus[fieldName] = true; // Set the field as focused
}

/// <summary>
Expand All @@ -158,7 +149,7 @@ public void HandleFieldFocus(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
this.FieldsFocusedStatus[fieldName] = false; // Set the field as not focused when it loses focus
}
}
}

0 comments on commit 5a4084b

Please sign in to comment.