Skip to content

Commit

Permalink
Parsing code review comments and fixing InputEditor and EditorPopup t…
Browse files Browse the repository at this point in the history
…ext fixtures to match the new business rules and changes made.
  • Loading branch information
Robbware committed Oct 3, 2023
1 parent aeed121 commit 9f22892
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 89 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -351,4 +351,4 @@ MigrationBackup/
/COMETwebapp/Tools

# Jetbrains folders
.idea/
.idea/
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -40,6 +41,7 @@ namespace COMET.Web.Common.Tests.Components.BookEditor
using DynamicData;

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

using Moq;

Expand All @@ -58,12 +60,15 @@ public class EditotPopupTestFixture
private List<Category> availableCategories;
private bool onCancelCalled;
private bool onAcceptCalled;
private Mock<ISessionService> sessionService;

[SetUp]
public void Setup()
{
this.context = new TestContext();
this.context.ConfigureDevExpressBlazor();
this.sessionService = new Mock<ISessionService>();
this.context.Services.AddSingleton(this.sessionService.Object);

this.book = new Book();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -46,12 +56,26 @@ public class InputEditorTestFixture
private Book book;
private List<DomainOfExpertise> activeDomains;
private List<Category> availableCategories;

private Mock<ISessionService> 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<ISessionService>();
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<DomainOfExpertise>
{
Expand All @@ -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
};
Expand All @@ -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<DxTextBox>();
var combobox = this.component.FindComponent<DxComboBox<DomainOfExpertise, DomainOfExpertise>>();
var categoryComboBox = this.component.FindComponent<MultiComboBox<Category>>();

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<DxListBox<Category, Category>>();


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));
});
}
}
Expand Down
33 changes: 22 additions & 11 deletions COMET.Web.Common/Components/BookEditor/InputEditor.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ namespace COMET.Web.Common.Components.BookEditor
/// </summary>
public partial class InputEditor<TItem>
{
/// <summary>
/// Gets or sets the <see cref="ILogger"/>
/// <summary>
/// Gets or sets the <see cref="ILogger"/>
/// </summary>
[Inject]
public ILogger<InputEditor<TItem>> Logger { get; set; }

/// <summary>
/// Gets or sets the <see cref="HttpClient"/>
/// <summary>
/// Gets or sets the <see cref="HttpClient"/>
/// </summary>
[Inject]
public HttpClient HttpClient { get; set; }
Expand All @@ -61,8 +61,8 @@ public partial class InputEditor<TItem>
[Inject]
public IOptions<GlobalOptions> Options { get; set; }

/// <summary>
/// Gets or sets the <see cref="ISessionService"/>
/// <summary>
/// Gets or sets the <see cref="ISessionService"/>
/// </summary>
[Inject]
public ISessionService SessionService { get; set; }
Expand All @@ -73,8 +73,8 @@ public partial class InputEditor<TItem>
[Parameter]
public TItem Item { get; set; }

/// <summary>
/// Gets or sets the active <see cref="DomainOfExpertise"/>
/// <summary>
/// Gets or sets the active <see cref="DomainOfExpertise"/>
/// </summary>
[Parameter]
public IEnumerable<DomainOfExpertise> ActiveDomains { get; set; }
Expand Down Expand Up @@ -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<Dictionary<string, bool>>(jsonContent);
var configurations = await this.GetBookInputConfigurationAsync(jsonFile);

if (configurations.TryGetValue(showNameConfigurationProperty, out var showNameValue))
{
Expand All @@ -146,6 +144,19 @@ protected override async Task OnInitializedAsync()
}
}

/// <summary>
/// Acquires the BookInput configurations
/// </summary>
/// <param name="fileName">The file name that contains the configurations</param>
/// <returns>A KeyValuePair collection with each available configuration</returns>
private async Task<Dictionary<string, bool>> GetBookInputConfigurationAsync(string fileName)
{
var path = ContentPathBuilder.BuildPath(fileName);
var jsonContent = await this.HttpClient.GetStreamAsync(path);
var configurations = JsonSerializer.Deserialize<Dictionary<string, bool>>(jsonContent);
return configurations;
}

/// <summary>
/// Handler for when the selected categories changed
/// </summary>
Expand Down
30 changes: 21 additions & 9 deletions COMET.Web.Common/Components/MultiComboBox.razor.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
// -----------------------------------------------------------------------------------
// <copyright file="MultiComboBox.razor.cs" company="RHEA System S.A.">
// Copyright (c) 2023 RHEA System S.A.
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="MultiComboBox.razor.cs" company="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.
//
// </copyright>
// -----------------------------------------------------------------------------------
// 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.
//
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace COMET.Web.Common.Components
{
Expand Down
47 changes: 0 additions & 47 deletions COMET.Web.Common/Components/MultiComboBox.razor.css

This file was deleted.

0 comments on commit 9f22892

Please sign in to comment.