From 757363e472495a37b9e11bf8368771cc9d4cea67 Mon Sep 17 00:00:00 2001 From: joao4all Date: Fri, 6 Oct 2023 14:28:59 +0100 Subject: [PATCH] Updates - Comments added - Testing focus and blur functionalities --- .../Components/LoginTestFixture.cs | 35 ++++++++++++++++++- COMET.Web.Common/Components/Login.razor | 2 -- COMET.Web.Common/Components/Login.razor.cs | 8 ++--- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/COMET.Web.Common.Tests/Components/LoginTestFixture.cs b/COMET.Web.Common.Tests/Components/LoginTestFixture.cs index 8b77dc06..ca7e864e 100644 --- a/COMET.Web.Common.Tests/Components/LoginTestFixture.cs +++ b/COMET.Web.Common.Tests/Components/LoginTestFixture.cs @@ -25,6 +25,8 @@ namespace COMET.Web.Common.Tests.Components { + using AngleSharp.Dom; + using Bunit; using COMET.Web.Common.Components; @@ -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; @@ -70,6 +73,36 @@ public void Teardown() this.context.CleanContext(); } + [Test] + public async Task VerifyFocusingAndBluring() + { + var renderer = this.context.RenderComponent(); + + Assert.That(renderer.Instance.FieldsFocusedStatus, Is.EqualTo(new Dictionary() + { + { "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() { diff --git a/COMET.Web.Common/Components/Login.razor b/COMET.Web.Common/Components/Login.razor index 3cbbe3a5..938e9948 100644 --- a/COMET.Web.Common/Components/Login.razor +++ b/COMET.Web.Common/Components/Login.razor @@ -62,8 +62,6 @@ - -
    @foreach (var fieldFocusedStatus in this.fieldsFocusedStatus) { diff --git a/COMET.Web.Common/Components/Login.razor.cs b/COMET.Web.Common/Components/Login.razor.cs index cfacd82c..f3752e32 100644 --- a/COMET.Web.Common/Components/Login.razor.cs +++ b/COMET.Web.Common/Components/Login.razor.cs @@ -146,8 +146,8 @@ private async Task ExecuteLogin() /// /// Handles the focus event of the given fieldName /// - /// - private void HandleFieldFocus(string fieldName) + /// Form field name, as indexed in + public void HandleFieldFocus(string fieldName) { this.fieldsFocusedStatus[fieldName] = true; // Set the field as focused } @@ -155,8 +155,8 @@ private void HandleFieldFocus(string fieldName) /// /// Handles the blur event of the given fieldName /// - /// - private void HandleFieldBlur(string fieldName) + /// Form field name, as indexed in + public void HandleFieldBlur(string fieldName) { this.fieldsFocusedStatus[fieldName] = false; // Set the field as not focused when it loses focus }