From 54e9c8a3f16b3ab4dfaf38144f91b701b3eee8b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Rua?= Date: Wed, 4 Oct 2023 16:53:56 +0100 Subject: [PATCH 1/8] Rebased --- .../Components/LoginTestFixture.cs | 7 ++ COMET.Web.Common/COMET.Web.Common.csproj | 2 +- COMET.Web.Common/Components/Login.razor | 90 +++++++++++++------ COMET.Web.Common/Components/Login.razor.cs | 32 +++++++ .../Components/MultiComboBox.razor | 1 - 5 files changed, 101 insertions(+), 31 deletions(-) diff --git a/COMET.Web.Common.Tests/Components/LoginTestFixture.cs b/COMET.Web.Common.Tests/Components/LoginTestFixture.cs index 95f84944..8b77dc06 100644 --- a/COMET.Web.Common.Tests/Components/LoginTestFixture.cs +++ b/COMET.Web.Common.Tests/Components/LoginTestFixture.cs @@ -79,6 +79,13 @@ public async Task VerifyPerformLogin() this.authenticationService.Setup(x => x.Login(It.IsAny())) .ReturnsAsync(AuthenticationStateKind.ServerFail); + Assert.That(renderer.Instance.FieldsFocusedStatus, Is.EqualTo(new Dictionary() + { + { "SourceAddress", false }, + { "UserName", false }, + { "Password", false } + })); + await renderer.InvokeAsync(editForm.Instance.OnValidSubmit.InvokeAsync); Assert.Multiple(() => diff --git a/COMET.Web.Common/COMET.Web.Common.csproj b/COMET.Web.Common/COMET.Web.Common.csproj index 7bc6e9a0..7890b639 100644 --- a/COMET.Web.Common/COMET.Web.Common.csproj +++ b/COMET.Web.Common/COMET.Web.Common.csproj @@ -3,7 +3,7 @@ net7.0 Latest - 1.0.23 + 1.0.22 1.0.0 1.0.0 CDP4 WEB Common diff --git a/COMET.Web.Common/Components/Login.razor b/COMET.Web.Common/Components/Login.razor index 86ee9e4b..06b1ff9e 100644 --- a/COMET.Web.Common/Components/Login.razor +++ b/COMET.Web.Common/Components/Login.razor @@ -24,35 +24,67 @@ - - @if (string.IsNullOrEmpty(this.ViewModel.serverConnectionService.ServerAddress)) - { - - - - } - - - - - - - - + + @if (string.IsNullOrEmpty(this.ViewModel.serverConnectionService.ServerAddress)) + { + + + + } + + + + + + + + + + +
    + @foreach (var kvp in this.FieldsFocusedStatus) + { + if (kvp.Value) continue; + + @if (kvp.Key == "SourceAddress" && !string.IsNullOrEmpty(editFormContext.GetValidationMessages(() => this.ViewModel.AuthenticationDto.SourceAddress).FirstOrDefault())) + { +
  • + } + @if (kvp.Key == "UserName" && !string.IsNullOrEmpty(editFormContext.GetValidationMessages(() => this.ViewModel.AuthenticationDto.UserName).FirstOrDefault())) + { +
  • + } + @if (kvp.Key == "Password" && !string.IsNullOrEmpty(editFormContext.GetValidationMessages(() => this.ViewModel.AuthenticationDto.Password).FirstOrDefault())) + { +
  • + } + + } +
+ @if (!string.IsNullOrEmpty(this.ErrorMessage)) { diff --git a/COMET.Web.Common/Components/Login.razor.cs b/COMET.Web.Common/Components/Login.razor.cs index 2520c56c..2f30a94f 100644 --- a/COMET.Web.Common/Components/Login.razor.cs +++ b/COMET.Web.Common/Components/Login.razor.cs @@ -29,6 +29,7 @@ namespace COMET.Web.Common.Components using COMET.Web.Common.ViewModels.Components; using Microsoft.AspNetCore.Components; + using Microsoft.AspNetCore.Components.Web; using ReactiveUI; @@ -64,6 +65,12 @@ public partial class Login /// public bool LoginEnabled { get; set; } = true; + /// + /// The dictionary of focus status from the fields + /// + public Dictionary FieldsFocusedStatus; + + /// /// Method invoked when the component is ready to start, having received its /// initial parameters from its parent in the render tree. @@ -72,6 +79,13 @@ protected override void OnInitialized() { base.OnInitialized(); + this.FieldsFocusedStatus = new Dictionary() + { + { "SourceAddress", false }, + { "UserName", false }, + { "Password", false } + }; + this.Disposables.Add(this.WhenAnyValue(x => x.ViewModel.AuthenticationState) .Subscribe(_ => this.ComputeDisplayProperties())); } @@ -120,5 +134,23 @@ private async Task ExecuteLogin() await this.ViewModel.ExecuteLogin(); this.LoginEnabled = true; } + + /// + /// Handles the focus event of the given fieldName + /// + /// + private void HandleFieldFocus(string fieldName) + { + this.FieldsFocusedStatus[fieldName] = true; // Set the field as focused + } + + /// + /// Handles the blur event of the given fieldName + /// + /// + private void HandleFieldBlur(string fieldName) + { + this.FieldsFocusedStatus[fieldName] = false; // Set the field as not focused when it loses focus + } } } diff --git a/COMET.Web.Common/Components/MultiComboBox.razor b/COMET.Web.Common/Components/MultiComboBox.razor index 485ce07f..926ad8e3 100644 --- a/COMET.Web.Common/Components/MultiComboBox.razor +++ b/COMET.Web.Common/Components/MultiComboBox.razor @@ -19,7 +19,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -------------------------------------------------------------------------------> -@namespace COMET.Web.Common.Components @typeparam TItem Date: Wed, 4 Oct 2023 17:48:55 +0100 Subject: [PATCH 2/8] Following code style guideline --- COMET.Web.Common/Components/Login.razor | 34 ++++++++++++---------- COMET.Web.Common/Components/Login.razor.cs | 1 - 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/COMET.Web.Common/Components/Login.razor b/COMET.Web.Common/Components/Login.razor index 06b1ff9e..87ab37d1 100644 --- a/COMET.Web.Common/Components/Login.razor +++ b/COMET.Web.Common/Components/Login.razor @@ -65,23 +65,27 @@
    - @foreach (var kvp in this.FieldsFocusedStatus) + @foreach (var fieldFocusedStatus in this.FieldsFocusedStatus) { - if (kvp.Value) continue; + if (fieldFocusedStatus.Value) + { + continue; + } - @if (kvp.Key == "SourceAddress" && !string.IsNullOrEmpty(editFormContext.GetValidationMessages(() => this.ViewModel.AuthenticationDto.SourceAddress).FirstOrDefault())) - { -
  • - } - @if (kvp.Key == "UserName" && !string.IsNullOrEmpty(editFormContext.GetValidationMessages(() => this.ViewModel.AuthenticationDto.UserName).FirstOrDefault())) - { -
  • - } - @if (kvp.Key == "Password" && !string.IsNullOrEmpty(editFormContext.GetValidationMessages(() => this.ViewModel.AuthenticationDto.Password).FirstOrDefault())) - { -
  • - } - + @if (fieldFocusedStatus.Key == "SourceAddress" && !string.IsNullOrEmpty(editFormContext.GetValidationMessages(() => this.ViewModel.AuthenticationDto.SourceAddress).FirstOrDefault())) + { +
  • + } + + @if (fieldFocusedStatus.Key == "UserName" && !string.IsNullOrEmpty(editFormContext.GetValidationMessages(() => this.ViewModel.AuthenticationDto.UserName).FirstOrDefault())) + { +
  • + } + + @if (fieldFocusedStatus.Key == "Password" && !string.IsNullOrEmpty(editFormContext.GetValidationMessages(() => this.ViewModel.AuthenticationDto.Password).FirstOrDefault())) + { +
  • + } }
diff --git a/COMET.Web.Common/Components/Login.razor.cs b/COMET.Web.Common/Components/Login.razor.cs index 2f30a94f..219b2901 100644 --- a/COMET.Web.Common/Components/Login.razor.cs +++ b/COMET.Web.Common/Components/Login.razor.cs @@ -70,7 +70,6 @@ public partial class Login ///
public Dictionary FieldsFocusedStatus; - /// /// Method invoked when the component is ready to start, having received its /// initial parameters from its parent in the render tree. From 2bbaca4c077b5d6efcafd38cdb47477cc7a95d19 Mon Sep 17 00:00:00 2001 From: joao4all Date: Wed, 4 Oct 2023 18:12:55 +0100 Subject: [PATCH 3/8] Sonarqube recomendations --- COMET.Web.Common/COMET.Web.Common.csproj | 2 +- COMET.Web.Common/Components/Login.razor | 2 +- COMET.Web.Common/Components/Login.razor.cs | 17 +++++++++++++---- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/COMET.Web.Common/COMET.Web.Common.csproj b/COMET.Web.Common/COMET.Web.Common.csproj index 7890b639..7bc6e9a0 100644 --- a/COMET.Web.Common/COMET.Web.Common.csproj +++ b/COMET.Web.Common/COMET.Web.Common.csproj @@ -3,7 +3,7 @@ net7.0 Latest - 1.0.22 + 1.0.23 1.0.0 1.0.0 CDP4 WEB Common diff --git a/COMET.Web.Common/Components/Login.razor b/COMET.Web.Common/Components/Login.razor index 87ab37d1..3cbbe3a5 100644 --- a/COMET.Web.Common/Components/Login.razor +++ b/COMET.Web.Common/Components/Login.razor @@ -65,7 +65,7 @@
    - @foreach (var fieldFocusedStatus in this.FieldsFocusedStatus) + @foreach (var fieldFocusedStatus in this.fieldsFocusedStatus) { if (fieldFocusedStatus.Value) { diff --git a/COMET.Web.Common/Components/Login.razor.cs b/COMET.Web.Common/Components/Login.razor.cs index 219b2901..cfacd82c 100644 --- a/COMET.Web.Common/Components/Login.razor.cs +++ b/COMET.Web.Common/Components/Login.razor.cs @@ -65,10 +65,19 @@ public partial class Login ///
public bool LoginEnabled { get; set; } = true; + /// + /// The dictionary of focus status from the fields, used by blazor component + /// + private Dictionary fieldsFocusedStatus; + /// /// The dictionary of focus status from the fields /// - public Dictionary FieldsFocusedStatus; + public Dictionary FieldsFocusedStatus + { + get => this.fieldsFocusedStatus; + private set => this.fieldsFocusedStatus = value; + } /// /// Method invoked when the component is ready to start, having received its @@ -78,7 +87,7 @@ protected override void OnInitialized() { base.OnInitialized(); - this.FieldsFocusedStatus = new Dictionary() + this.fieldsFocusedStatus = new Dictionary() { { "SourceAddress", false }, { "UserName", false }, @@ -140,7 +149,7 @@ private async Task ExecuteLogin() /// private void HandleFieldFocus(string fieldName) { - this.FieldsFocusedStatus[fieldName] = true; // Set the field as focused + this.fieldsFocusedStatus[fieldName] = true; // Set the field as focused } /// @@ -149,7 +158,7 @@ private void HandleFieldFocus(string fieldName) /// private 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 } } } From 76cac83dad150fd4e65c55b37ad4acb6796a6449 Mon Sep 17 00:00:00 2001 From: joao4all Date: Wed, 4 Oct 2023 18:24:15 +0100 Subject: [PATCH 4/8] fixing wrong rebasing --- COMET.Web.Common/Components/MultiComboBox.razor | 1 + 1 file changed, 1 insertion(+) diff --git a/COMET.Web.Common/Components/MultiComboBox.razor b/COMET.Web.Common/Components/MultiComboBox.razor index 926ad8e3..485ce07f 100644 --- a/COMET.Web.Common/Components/MultiComboBox.razor +++ b/COMET.Web.Common/Components/MultiComboBox.razor @@ -19,6 +19,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -------------------------------------------------------------------------------> +@namespace COMET.Web.Common.Components @typeparam TItem Date: Fri, 6 Oct 2023 14:28:59 +0100 Subject: [PATCH 5/8] 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 } From 5a4084be6ebd825528e5a419eaba7f70df23be89 Mon Sep 17 00:00:00 2001 From: joao4all Date: Fri, 6 Oct 2023 16:32:22 +0100 Subject: [PATCH 6/8] Requested changes --- .../Components/LoginTestFixture.cs | 29 ++++++++++--------- COMET.Web.Common/Components/Login.razor | 2 +- COMET.Web.Common/Components/Login.razor.cs | 19 ++++-------- 3 files changed, 22 insertions(+), 28 deletions(-) diff --git a/COMET.Web.Common.Tests/Components/LoginTestFixture.cs b/COMET.Web.Common.Tests/Components/LoginTestFixture.cs index ca7e864e..f93b62c4 100644 --- a/COMET.Web.Common.Tests/Components/LoginTestFixture.cs +++ b/COMET.Web.Common.Tests/Components/LoginTestFixture.cs @@ -25,8 +25,6 @@ namespace COMET.Web.Common.Tests.Components { - using AngleSharp.Dom; - using Bunit; using COMET.Web.Common.Components; @@ -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; @@ -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] diff --git a/COMET.Web.Common/Components/Login.razor b/COMET.Web.Common/Components/Login.razor index 938e9948..7ea2bb33 100644 --- a/COMET.Web.Common/Components/Login.razor +++ b/COMET.Web.Common/Components/Login.razor @@ -63,7 +63,7 @@
      - @foreach (var fieldFocusedStatus in this.fieldsFocusedStatus) + @foreach (var fieldFocusedStatus in this.FieldsFocusedStatus) { if (fieldFocusedStatus.Value) { diff --git a/COMET.Web.Common/Components/Login.razor.cs b/COMET.Web.Common/Components/Login.razor.cs index f3752e32..dc402af2 100644 --- a/COMET.Web.Common/Components/Login.razor.cs +++ b/COMET.Web.Common/Components/Login.razor.cs @@ -66,18 +66,9 @@ public partial class Login public bool LoginEnabled { get; set; } = true; /// - /// The dictionary of focus status from the fields, used by blazor component + /// The dictionary of focus status from the form fields /// - private Dictionary fieldsFocusedStatus; - - /// - /// The dictionary of focus status from the fields - /// - public Dictionary FieldsFocusedStatus - { - get => this.fieldsFocusedStatus; - private set => this.fieldsFocusedStatus = value; - } + public Dictionary FieldsFocusedStatus { get; private set; } /// /// Method invoked when the component is ready to start, having received its @@ -87,7 +78,7 @@ protected override void OnInitialized() { base.OnInitialized(); - this.fieldsFocusedStatus = new Dictionary() + this.FieldsFocusedStatus = new Dictionary() { { "SourceAddress", false }, { "UserName", false }, @@ -149,7 +140,7 @@ private async Task ExecuteLogin() /// Form field name, as indexed in public void HandleFieldFocus(string fieldName) { - this.fieldsFocusedStatus[fieldName] = true; // Set the field as focused + this.FieldsFocusedStatus[fieldName] = true; // Set the field as focused } /// @@ -158,7 +149,7 @@ public void HandleFieldFocus(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 + this.FieldsFocusedStatus[fieldName] = false; // Set the field as not focused when it loses focus } } } From ae0ce7f1c12f25edd8c6152345a8d0e9819fce4e Mon Sep 17 00:00:00 2001 From: joao4all Date: Fri, 6 Oct 2023 17:36:25 +0100 Subject: [PATCH 7/8] Important Updates Changing conditional to show source address, given the current way to do it, through serverconnectionservice.serverconfiguration.serveraddress --- COMET.Web.Common/Components/Login.razor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/COMET.Web.Common/Components/Login.razor b/COMET.Web.Common/Components/Login.razor index 41f8dbe3..377bd1e6 100644 --- a/COMET.Web.Common/Components/Login.razor +++ b/COMET.Web.Common/Components/Login.razor @@ -25,7 +25,7 @@ - @if (string.IsNullOrEmpty(this.ViewModel.serverConnectionService.ServerAddress)) + @if (string.IsNullOrEmpty(this.ViewModel.serverConnectionService.ServerConfiguration.ServerAddress)) {