Skip to content

Commit

Permalink
Add configurationService for navigation menu : Fix #446 (#447)
Browse files Browse the repository at this point in the history
* add configurationService for navigation menu

* fix unit tests

* fix indentation
  • Loading branch information
nabilatrhea authored Sep 8, 2023
1 parent e05e195 commit ce3541b
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 9 deletions.
12 changes: 8 additions & 4 deletions COMET.Web.Common.Tests/Shared/TopMenuTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace COMET.Web.Common.Tests.Shared

using COMET.Web.Common.Components;
using COMET.Web.Common.Model;
using COMET.Web.Common.Services.ConfigurationService;
using COMET.Web.Common.Services.NotificationService;
using COMET.Web.Common.Services.RegistrationService;
using COMET.Web.Common.Services.SessionManagement;
Expand Down Expand Up @@ -71,6 +72,7 @@ public class TopMenuTestFixture
private Mock<IAuthenticationService> authenticationService;
private Mock<IRegistrationService> registrationService;
private Mock<IVersionService> versionService;
private Mock<IConfigurationService> configurationService;
private SourceList<Iteration> sourceList;
private List<Type> registeredMenuEntries;
private List<Application> registeredApplications;
Expand Down Expand Up @@ -103,6 +105,8 @@ public void Setup()
this.context.Services.AddSingleton<IModelMenuViewModel, ModelMenuViewModel>();
this.context.Services.AddSingleton<IAuthorizedMenuEntryViewModel, AuthorizedMenuEntryViewModel>();
this.context.Services.AddSingleton<INotificationService, NotificationService>();
this.configurationService = new Mock<IConfigurationService>();
this.context.Services.AddSingleton(this.configurationService.Object);
this.context.ConfigureDevExpressBlazor();
}

Expand Down Expand Up @@ -271,8 +275,8 @@ public void VerifyReturnToHomeWithTitle()
navigationManager.NavigateTo("/AnUrl");
var renderer = this.context.RenderComponent<TopMenu>();
var topMenuTitle = renderer.FindComponent<TopMenuTitle>();
var link =(ElementWrapper) topMenuTitle.Find("a");
var htmlAnchor = (IHtmlAnchorElement) link.WrappedElement;
var link = (ElementWrapper)topMenuTitle.Find("a");
var htmlAnchor = (IHtmlAnchorElement)link.WrappedElement;
Assert.That(navigationManager.Uri, Does.EndWith("AnUrl"));
navigationManager.NavigateTo(htmlAnchor.Href);
Assert.That(navigationManager.Uri, Does.Not.EndWith("AnUrl"));
Expand All @@ -283,7 +287,7 @@ public void VerifyCustomTitleHeader()
{
this.registrationService.Setup(x => x.CustomHeader).Returns(typeof(CustomHeader));
var renderer = this.context.RenderComponent<TopMenu>();

Assert.Multiple(() =>
{
Assert.That(() => renderer.FindComponent<TopMenuTitle>(), Throws.Exception);
Expand All @@ -295,7 +299,7 @@ private class TestAuthorizedMenuEntry : AuthorizedMenuEntry
{
}

private class CustomHeader: MenuEntryBase
private class CustomHeader : MenuEntryBase
{
}
}
Expand Down
17 changes: 16 additions & 1 deletion COMET.Web.Common/Enumerations/TextConfigurationKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ public enum TextConfigurationKind
/// <summary>
/// The title to use in the landing page
/// </summary>
LandingPageTitle = 6
LandingPageTitle = 6,

/// <summary>
/// The caption to use as navigation application selector title
/// </summary>
NavigationApplicationSelectorTitle = 7,

/// <summary>
/// The caption to use as navigation model selector title
/// </summary>
NavigationModelSelectorTitle = 8,

/// <summary>
/// The caption to use as title for the open button
/// </summary>
ModelOpenButtonCaption = 9,
}
}
3 changes: 2 additions & 1 deletion COMET.Web.Common/Shared/TopMenuEntry/ApplicationMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
------------------------------------------------------------------------------->
@namespace COMET.Web.Common.Shared.TopMenuEntry

@using COMET.Web.Common.Enumerations
@inherits AuthorizedMenuEntry

<DxMenuItem Text="Application" IconCssClass="oi oi-layers" Enabled="@this.AuthorizedMenuEntryViewModel.IsAuthenticated">
<DxMenuItem Text="@this.ConfigurationService.GetText(TextConfigurationKind.NavigationApplicationSelectorTitle)" IconCssClass="oi oi-layers" Enabled="@this.AuthorizedMenuEntryViewModel.IsAuthenticated">
<Items>
@foreach (var applicationEntry in this.RegistrationService.RegisteredApplications)
{
Expand Down
7 changes: 7 additions & 0 deletions COMET.Web.Common/Shared/TopMenuEntry/ApplicationMenu.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
namespace COMET.Web.Common.Shared.TopMenuEntry
{
using COMET.Web.Common.Model;
using COMET.Web.Common.Services.ConfigurationService;
using COMET.Web.Common.Services.RegistrationService;

using Microsoft.AspNetCore.Components;
Expand All @@ -40,5 +41,11 @@ public partial class ApplicationMenu
/// </summary>
[Inject]
internal IRegistrationService RegistrationService { get; set; }

/// <summary>
/// The <see cref="IConfigurationService"/>
/// </summary>
[Inject]
public IConfigurationService ConfigurationService { get; set; }
}
}
5 changes: 3 additions & 2 deletions COMET.Web.Common/Shared/TopMenuEntry/ModelMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// limitations under the License.
------------------------------------------------------------------------------->
@namespace COMET.Web.Common.Shared.TopMenuEntry
@using COMET.Web.Common.Enumerations
@inherits AuthorizedMenuEntry

<ConfirmCancelPopup ViewModel="@(this.ViewModel.ConfirmCancelViewModel)" />
Expand All @@ -32,14 +33,14 @@
<OpenModel />
</DxPopup>

<DxMenuItem Name="model-entry" Text="Models" IconCssClass="icon icon-folder" Enabled="@(this.AuthorizedMenuEntryViewModel.IsAuthenticated)">
<DxMenuItem Name="model-entry" Text="@this.ConfigurationService.GetText(TextConfigurationKind.NavigationModelSelectorTitle)" IconCssClass="icon icon-folder" Enabled="@(this.AuthorizedMenuEntryViewModel.IsAuthenticated)">
<TextTemplate>
<span id="@context.Name">
@context.Text
</span>
</TextTemplate>
<Items>
<DxMenuItem Name="model-entry-open" Text="Open Model" Click="@this.ViewModel.AskToOpenIteration">
<DxMenuItem Name="model-entry-open" Text="@this.ConfigurationService.GetText(TextConfigurationKind.ModelOpenButtonCaption)" Click="@this.ViewModel.AskToOpenIteration">
<TextTemplate Context="contextSwitch">
<span id="@contextSwitch.Name">
@contextSwitch.Text
Expand Down
7 changes: 7 additions & 0 deletions COMET.Web.Common/Shared/TopMenuEntry/ModelMenu.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace COMET.Web.Common.Shared.TopMenuEntry
{
using CDP4Common.EngineeringModelData;

using COMET.Web.Common.Services.ConfigurationService;
using COMET.Web.Common.ViewModels.Shared.TopMenuEntry;

using Microsoft.AspNetCore.Components;
Expand All @@ -44,6 +45,12 @@ public partial class ModelMenu
[Inject]
public IModelMenuViewModel ViewModel { get; set; }

/// <summary>
/// The <see cref="IConfigurationService"/>
/// </summary>
[Inject]
public IConfigurationService ConfigurationService { get; set; }

/// <summary>
/// Method invoked when the component is ready to start, having received its
/// initial parameters from its parent in the render tree.
Expand Down
5 changes: 4 additions & 1 deletion COMET.Web.Common/wwwroot/DefaultTextConfiguration.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
"ModelTitleCaption": "Model",
"IterationTitleCaption": "Iteration",
"DomainTitleCaption": "Domain",
"LandingPageTitle" : ""
"LandingPageTitle": "",
"NavigationApplicationSelectorTitle": "Application",
"NavigationModelSelectorTitle": "Models",
"ModelOpenButtonCaption": "Open Model"
}

0 comments on commit ce3541b

Please sign in to comment.