From 9f22892e246a1c8170f24ecad67fdd97e43acffa Mon Sep 17 00:00:00 2001 From: Robbware Date: Tue, 3 Oct 2023 15:29:02 +0100 Subject: [PATCH] Parsing code review comments and fixing InputEditor and EditorPopup text fixtures to match the new business rules and changes made. --- .gitignore | 2 +- .../BookEditor/EditotPopupTestFixture.cs | 5 ++ .../BookEditor/InputEditorTestFixture.cs | 60 ++++++++++++------- .../BookEditor/InputEditor.razor.cs | 33 ++++++---- .../Components/MultiComboBox.razor.cs | 30 +++++++--- .../Components/MultiComboBox.razor.css | 47 --------------- 6 files changed, 88 insertions(+), 89 deletions(-) delete mode 100644 COMET.Web.Common/Components/MultiComboBox.razor.css diff --git a/.gitignore b/.gitignore index c2732183..d93cc446 100644 --- a/.gitignore +++ b/.gitignore @@ -351,4 +351,4 @@ MigrationBackup/ /COMETwebapp/Tools # Jetbrains folders -.idea/ \ No newline at end of file +.idea/ diff --git a/COMET.Web.Common.Tests/Components/BookEditor/EditotPopupTestFixture.cs b/COMET.Web.Common.Tests/Components/BookEditor/EditotPopupTestFixture.cs index 81cb95cb..a0ff55e9 100644 --- a/COMET.Web.Common.Tests/Components/BookEditor/EditotPopupTestFixture.cs +++ b/COMET.Web.Common.Tests/Components/BookEditor/EditotPopupTestFixture.cs @@ -31,6 +31,7 @@ namespace COMET.Web.Common.Tests.Components.BookEditor using COMET.Web.Common.Components; using COMET.Web.Common.Components.BookEditor; + using COMET.Web.Common.Services.SessionManagement; using COMET.Web.Common.Test.Helpers; using COMET.Web.Common.ViewModels.Components.BookEditor; @@ -40,6 +41,7 @@ namespace COMET.Web.Common.Tests.Components.BookEditor using DynamicData; using Microsoft.AspNetCore.Components; + using Microsoft.Extensions.DependencyInjection; using Moq; @@ -58,12 +60,15 @@ public class EditotPopupTestFixture private List availableCategories; private bool onCancelCalled; private bool onAcceptCalled; + private Mock sessionService; [SetUp] public void Setup() { this.context = new TestContext(); this.context.ConfigureDevExpressBlazor(); + this.sessionService = new Mock(); + this.context.Services.AddSingleton(this.sessionService.Object); this.book = new Book(); diff --git a/COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs b/COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs index fab129e2..bd9de519 100644 --- a/COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs +++ b/COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs @@ -24,18 +24,28 @@ namespace COMET.Web.Common.Tests.Components.BookEditor { + using System.Text.Json; + using Bunit; using CDP4Common.ReportingData; using CDP4Common.SiteDirectoryData; + using COMET.Web.Common.Components; using COMET.Web.Common.Components.BookEditor; + using COMET.Web.Common.Services.SessionManagement; using COMET.Web.Common.Test.Helpers; using DevExpress.Blazor; - + + using Microsoft.Extensions.DependencyInjection; + + using Moq; + using NUnit.Framework; + using RichardSzalay.MockHttp; + using TestContext = Bunit.TestContext; [TestFixture] @@ -46,12 +56,26 @@ public class InputEditorTestFixture private Book book; private List activeDomains; private List availableCategories; - + private Mock sessionService; + private MockHttpMessageHandler mockHttpMessageHandler; + private HttpClient httpClient; + private const string BookName = "Book Example"; + private const string BookShortName = "bookExample"; + [SetUp] public void Setup() { this.context = new TestContext(); this.context.ConfigureDevExpressBlazor(); + this.sessionService = new Mock(); + this.context.Services.AddSingleton(this.sessionService.Object); + this.mockHttpMessageHandler = new MockHttpMessageHandler(); + this.httpClient = this.mockHttpMessageHandler.ToHttpClient(); + this.httpClient.BaseAddress = new Uri("http://localhost/"); + this.context.Services.AddScoped(_ => this.httpClient); + var httpResponse = new HttpResponseMessage(); + httpResponse.Content = new StringContent("{\n \"ShowName\": true,\n \"ShowShortName\" : true \n}\n"); + this.mockHttpMessageHandler.When(HttpMethod.Get, "/_content/CDP4.WEB.Common/BookInputConfiguration.json").Respond(_ => httpResponse); this.activeDomains = new List { @@ -65,8 +89,8 @@ public void Setup() this.book = new Book() { - Name = "Book Example", - ShortName = "bookExample", + Name = BookName, + ShortName = BookShortName, Owner = this.activeDomains.First(), Category = this.availableCategories }; @@ -82,33 +106,27 @@ public void Setup() [Test] public void VerifyComponent() { - var basicTab = this.component.Find(".basic-tab"); - basicTab.Click(); - var textboxes = this.component.FindComponents(); var combobox = this.component.FindComponent>(); + var categoryComboBox = this.component.FindComponent>(); - var nameTextbox = textboxes[0]; - var shortNameTextbox = textboxes[1]; - + var nameTextbox = textboxes.FirstOrDefault(x => x.Instance.Text == BookName); + var shortNameTextbox = textboxes.FirstOrDefault(x => x.Instance.Text == BookShortName); + Assert.Multiple(() => { - Assert.That(nameTextbox.Instance.Text, Is.EqualTo("Book Example")); - Assert.That(shortNameTextbox.Instance.Text, Is.EqualTo("bookExample")); + Assert.IsNotNull(nameTextbox); + Assert.IsNotNull(shortNameTextbox); Assert.That(combobox.Instance.Value, Is.EqualTo(this.activeDomains.First())); + Assert.That(categoryComboBox.Instance, Is.Not.Null); }); - - var categoryTab = this.component.Find(".category-tab"); - categoryTab.Click(); - + this.component.Render(); - - var listbox = this.component.FindComponent>(); - + Assert.Multiple(() => { - Assert.That(listbox.Instance.Data, Is.EquivalentTo(this.availableCategories)); - Assert.That(listbox.Instance.Values, Is.EquivalentTo(this.availableCategories)); + Assert.That(categoryComboBox.Instance.Data, Is.EquivalentTo(this.availableCategories)); + Assert.That(categoryComboBox.Instance.Values, Is.EquivalentTo(this.availableCategories)); }); } } diff --git a/COMET.Web.Common/Components/BookEditor/InputEditor.razor.cs b/COMET.Web.Common/Components/BookEditor/InputEditor.razor.cs index 73c6435b..4021b281 100644 --- a/COMET.Web.Common/Components/BookEditor/InputEditor.razor.cs +++ b/COMET.Web.Common/Components/BookEditor/InputEditor.razor.cs @@ -43,14 +43,14 @@ namespace COMET.Web.Common.Components.BookEditor /// public partial class InputEditor { - /// - /// Gets or sets the + /// + /// Gets or sets the /// [Inject] public ILogger> Logger { get; set; } - /// - /// Gets or sets the + /// + /// Gets or sets the /// [Inject] public HttpClient HttpClient { get; set; } @@ -61,8 +61,8 @@ public partial class InputEditor [Inject] public IOptions Options { get; set; } - /// - /// Gets or sets the + /// + /// Gets or sets the /// [Inject] public ISessionService SessionService { get; set; } @@ -73,8 +73,8 @@ public partial class InputEditor [Parameter] public TItem Item { get; set; } - /// - /// Gets or sets the active + /// + /// Gets or sets the active /// [Parameter] public IEnumerable ActiveDomains { get; set; } @@ -121,9 +121,7 @@ protected override async Task OnInitializedAsync() try { - var path = ContentPathBuilder.BuildPath(jsonFile); - var jsonContent = await this.HttpClient.GetStreamAsync(path); - var configurations = JsonSerializer.Deserialize>(jsonContent); + var configurations = await this.GetBookInputConfigurationAsync(jsonFile); if (configurations.TryGetValue(showNameConfigurationProperty, out var showNameValue)) { @@ -146,6 +144,19 @@ protected override async Task OnInitializedAsync() } } + /// + /// Acquires the BookInput configurations + /// + /// The file name that contains the configurations + /// A KeyValuePair collection with each available configuration + private async Task> GetBookInputConfigurationAsync(string fileName) + { + var path = ContentPathBuilder.BuildPath(fileName); + var jsonContent = await this.HttpClient.GetStreamAsync(path); + var configurations = JsonSerializer.Deserialize>(jsonContent); + return configurations; + } + /// /// Handler for when the selected categories changed /// diff --git a/COMET.Web.Common/Components/MultiComboBox.razor.cs b/COMET.Web.Common/Components/MultiComboBox.razor.cs index cc06144c..2466e144 100644 --- a/COMET.Web.Common/Components/MultiComboBox.razor.cs +++ b/COMET.Web.Common/Components/MultiComboBox.razor.cs @@ -1,15 +1,27 @@ -// ----------------------------------------------------------------------------------- -// -// Copyright (c) 2023 RHEA System S.A. +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. // -// Authors: Sam Gerené, Jaime Bernar +// Authors: Sam Gerené, Jaime Bernar // -// This file is part of AIDA -// European Space Agency Community License – v2.4 Permissive (Type 3) -// See LICENSE file for details +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA Web Application implementation of ECSS-E-TM-10-25 +// Annex A and Annex C. // -// -// ----------------------------------------------------------------------------------- +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// -------------------------------------------------------------------------------------------------------------------- namespace COMET.Web.Common.Components { diff --git a/COMET.Web.Common/Components/MultiComboBox.razor.css b/COMET.Web.Common/Components/MultiComboBox.razor.css deleted file mode 100644 index bf7ef31b..00000000 --- a/COMET.Web.Common/Components/MultiComboBox.razor.css +++ /dev/null @@ -1,47 +0,0 @@ -::deep.chip { - border: 0; - background-color: #EEEEEE; - border-radius: 30px; - padding: 2%; - box-shadow: 0px 0px 0px 1px rgba(0,0,0,0.2); - color: #555; - display: flex; - align-items:center; - justify-content:center; - column-gap: 5px; -} - -::deep.chip-button { - border: 0; - border-radius: 30px; -} - - ::deep.chip-button:hover { - box-shadow: 0px 0px 0px 2px rgba(0,0,0,0.2); - } - -::deep.chips-container { - display: flex; - flex-direction: row; - flex-wrap: wrap; - row-gap: 5px; - column-gap: 5px; - width: 100%; - height: 100%; -} - -::deep.dxbl-listbox-item{ - padding: 0 !important; -} - -::deep.combo-box-item-template { - display: block; - height: 100%; - width: 100%; - padding: 2%; -} - -::deep.combo-box-item-template.selected { - background-color: #0d6efd; - color: white; -} \ No newline at end of file