Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/BookApplication #456

Merged
merged 20 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 122 additions & 0 deletions COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="InputEditorTestFixture.cs" company="RHEA System S.A.">
// Copyright (c) 2023 RHEA System S.A.
//
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar
//
// 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.
//
// The COMET WEB Community Edition is free software; you can redistribute it and/or
// modify it under the terms of the GNU Affero General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// The COMET WEB Community Edition is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace COMET.Web.Common.Tests.Components.BookEditor
{
using Bunit;

using CDP4Common.ReportingData;
using CDP4Common.SiteDirectoryData;

using COMET.Web.Common.Components.BookEditor;
using COMET.Web.Common.Test.Helpers;
using COMET.Web.Common.ViewModels.Components.BookEditor;

using DevExpress.Blazor;

using DynamicData;

using Microsoft.AspNetCore.Components;

using Moq;

using NUnit.Framework;

using TestContext = Bunit.TestContext;

[TestFixture]
public class InputEditorTestFixture
{
private TestContext context;
private IRenderedComponent<InputEditor<Book>> component;
private Book book;
private List<DomainOfExpertise> activeDomains;
private List<Category> availableCategories;

[SetUp]
public void Setup()
{
this.context = new TestContext();
this.context.ConfigureDevExpressBlazor();

this.activeDomains = new List<DomainOfExpertise>
{
new() { Name = "Sys" }
};

this.availableCategories = new List<Category>
{
new() { Name = "Category" }
};

this.book = new Book()
{
Name = "Book Example",
ShortName = "bookExample",
Owner = this.activeDomains.First(),
Category = this.availableCategories
};

this.component = this.context.RenderComponent<InputEditor<Book>>(parameters =>
{
parameters.Add(p => p.Item, this.book);
parameters.Add(p => p.ActiveDomains, this.activeDomains);
parameters.Add(p => p.AvailableCategories, this.availableCategories);
});
}

[Test]
public void VerifyComponent()
{
var dxtabs = this.component.FindComponent<DxTabs>();

dxtabs.Instance.ActiveTabIndex = 0;

Check warning on line 94 in COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Component parameter 'ActiveTabIndex' should not be set outside of its component.

Check warning on line 94 in COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Component parameter 'ActiveTabIndex' should not be set outside of its component.

Check warning on line 94 in COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Component parameter 'ActiveTabIndex' should not be set outside of its component.

Check warning on line 94 in COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Component parameter 'ActiveTabIndex' should not be set outside of its component.

Check warning on line 94 in COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs

View workflow job for this annotation

GitHub Actions / Build

Component parameter 'ActiveTabIndex' should not be set outside of its component.

var textboxes = this.component.FindComponents<DxTextBox>();
var combobox = this.component.FindComponent<DxComboBox<DomainOfExpertise, DomainOfExpertise>>();

var nameTextbox = textboxes[0];
var shortNameTextbox = textboxes[1];

Assert.Multiple(() =>
{
Assert.That(nameTextbox.Instance.Text, Is.EqualTo("Book Example"));
Assert.That(shortNameTextbox.Instance.Text, Is.EqualTo("bookExample"));
Assert.That(combobox.Instance.Value, Is.EqualTo(this.activeDomains.First()));
});

dxtabs.Instance.ActiveTabIndex = 1;

Check warning on line 109 in COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Component parameter 'ActiveTabIndex' should not be set outside of its component.

Check warning on line 109 in COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Component parameter 'ActiveTabIndex' should not be set outside of its component.

Check warning on line 109 in COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Component parameter 'ActiveTabIndex' should not be set outside of its component.

Check warning on line 109 in COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Component parameter 'ActiveTabIndex' should not be set outside of its component.

Check warning on line 109 in COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs

View workflow job for this annotation

GitHub Actions / Build

Component parameter 'ActiveTabIndex' should not be set outside of its component.
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));
});
}
}
}

3 changes: 3 additions & 0 deletions COMET.Web.Common/COMET.Web.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
</ItemGroup>
<ItemGroup>
<Content Update="Components\BookEditor\InputEditor.razor">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</Content>
<Content Update="wwwroot\DefaultTextConfiguration.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand Down
41 changes: 41 additions & 0 deletions COMET.Web.Common/Components/BookEditor/EditorPopup.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!------------------------------------------------------------------------------
// Copyright (c) 2023 RHEA System S.A.
//
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar
//
// 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.BookEditor
@inherits DisposableComponent

<DxPopup @bind-Visible="@this.ViewModel.IsVisible" CloseOnOutsideClick="false" ShowCloseButton="true" ShowFooter="true" HeaderText="@this.ViewModel.HeaderText" Closed="@(()=> this.ViewModel.OnCancelClick.InvokeAsync())">

Check warning on line 25 in COMET.Web.Common/Components/BookEditor/EditorPopup.razor

View check run for this annotation

Codecov / codecov/patch

COMET.Web.Common/Components/BookEditor/EditorPopup.razor#L25

Added line #L25 was not covered by tests
<Content>
<InputEditor Item="@this.ViewModel.Item" ActiveDomains="@this.ViewModel.ActiveDomains" AvailableCategories="@this.ViewModel.AvailableCategories" />
<div style="display:flex; flex-direction:column">
@foreach (var validationError in this.ViewModel.ValidationErrors.Items)
{

Check warning on line 30 in COMET.Web.Common/Components/BookEditor/EditorPopup.razor

View check run for this annotation

Codecov / codecov/patch

COMET.Web.Common/Components/BookEditor/EditorPopup.razor#L30

Added line #L30 was not covered by tests
<ValidationMessageComponent ValidationMessage="@validationError"/>
}

Check warning on line 32 in COMET.Web.Common/Components/BookEditor/EditorPopup.razor

View check run for this annotation

Codecov / codecov/patch

COMET.Web.Common/Components/BookEditor/EditorPopup.razor#L32

Added line #L32 was not covered by tests
</div>
</Content>
<FooterTemplate>
<div class="modal-footer">
<DxButton Text="OK" RenderStyle="ButtonRenderStyle.Primary" Click="@(async () => await this.OnConfirmClick())" />
<DxButton Text="Cancel" RenderStyle="ButtonRenderStyle.Danger" Click="@(async () => await this.ViewModel.OnCancelClick.InvokeAsync())" />

Check warning on line 38 in COMET.Web.Common/Components/BookEditor/EditorPopup.razor

View check run for this annotation

Codecov / codecov/patch

COMET.Web.Common/Components/BookEditor/EditorPopup.razor#L37-L38

Added lines #L37 - L38 were not covered by tests
</div>
</FooterTemplate>
</DxPopup>
123 changes: 123 additions & 0 deletions COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="InputEditor.razor.cs" company="RHEA System S.A.">
// Copyright (c) 2023 RHEA System S.A.
//
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar
//
// 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.
//
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace COMET.Web.Common.Components.BookEditor
{
using CDP4Common.ReportingData;

using COMET.Web.Common.Services;
using COMET.Web.Common.ViewModels.Components.BookEditor;

using Microsoft.AspNetCore.Components;

using INamedThing = CDP4Common.CommonData.INamedThing;
using IOwnedThing = CDP4Common.EngineeringModelData.IOwnedThing;
using IShortNamedThing = CDP4Common.CommonData.IShortNamedThing;

/// <summary>
/// Support class for the BookEditorPopup component
/// </summary>
public partial class EditorPopup
{
/// <summary>
/// Gets or sets the <see cref="IEditorPopupViewModel"/>
/// </summary>
[Parameter]
public IEditorPopupViewModel ViewModel { get; set; }

/// <summary>
/// Method invoked when the component is ready to start, having received its
/// initial parameters from its parent in the render tree.
///
/// Override this method if you will perform an asynchronous operation and
/// want the component to refresh when that operation is completed.
/// </summary>
/// <returns>A <see cref="Task"/> representing any asynchronous operation.</returns>
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
this.Disposables.Add(this.ViewModel.ValidationErrors.Connect().Subscribe(_ => this.InvokeAsync(this.StateHasChanged)));
}

/// <summary>
/// Handler for when the confirm button has been clicked
/// </summary>
private async Task OnConfirmClick()

Check warning on line 67 in COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 17 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)

Check warning on line 67 in COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 17 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
var validationErrors = new List<string>();

Check warning on line 69 in COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs

View check run for this annotation

Codecov / codecov/patch

COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs#L68-L69

Added lines #L68 - L69 were not covered by tests

if (this.ViewModel.Item is INamedThing namedThing)
{
var error = ValidationService.ValidateProperty(nameof(namedThing.Name), namedThing.Name);

Check warning on line 73 in COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs

View check run for this annotation

Codecov / codecov/patch

COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs#L72-L73

Added lines #L72 - L73 were not covered by tests

if (!string.IsNullOrEmpty(error))
{
validationErrors.Add(error);
}
}

Check warning on line 79 in COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs

View check run for this annotation

Codecov / codecov/patch

COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs#L76-L79

Added lines #L76 - L79 were not covered by tests

if (this.ViewModel.Item is IShortNamedThing shortNamedThing)
{
var error = ValidationService.ValidateProperty(nameof(shortNamedThing.ShortName), shortNamedThing.ShortName);

Check warning on line 83 in COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs

View check run for this annotation

Codecov / codecov/patch

COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs#L82-L83

Added lines #L82 - L83 were not covered by tests

if (!string.IsNullOrEmpty(error))
{
validationErrors.Add(error);
}
}

Check warning on line 89 in COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs

View check run for this annotation

Codecov / codecov/patch

COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs#L86-L89

Added lines #L86 - L89 were not covered by tests

if (this.ViewModel.Item is IOwnedThing ownedThing)
{

Check warning on line 92 in COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs

View check run for this annotation

Codecov / codecov/patch

COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs#L92

Added line #L92 was not covered by tests
var error = ownedThing.Owner == null ? "The thing must be owned by a DoE" : string.Empty;

if (!string.IsNullOrEmpty(error))
{
validationErrors.Add(error);
}
}

Check warning on line 99 in COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs

View check run for this annotation

Codecov / codecov/patch

COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs#L96-L99

Added lines #L96 - L99 were not covered by tests

if (this.ViewModel.Item is TextualNote textualNote)
{

Check warning on line 102 in COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs

View check run for this annotation

Codecov / codecov/patch

COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs#L102

Added line #L102 was not covered by tests
var error = string.IsNullOrEmpty(textualNote.Content)? "The textual note must contain a content" : string.Empty;

if (!string.IsNullOrEmpty(error))
{
validationErrors.Add(error);
}
}

Check warning on line 109 in COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs

View check run for this annotation

Codecov / codecov/patch

COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs#L106-L109

Added lines #L106 - L109 were not covered by tests

this.ViewModel.ValidationErrors.Edit(inner =>
{
inner.Clear();
inner.AddRange(validationErrors);
});

Check warning on line 115 in COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs

View check run for this annotation

Codecov / codecov/patch

COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs#L111-L115

Added lines #L111 - L115 were not covered by tests

if (!this.ViewModel.ValidationErrors.Items.Any())
{
await this.ViewModel.OnConfirmClick.InvokeAsync();
}
}

Check warning on line 121 in COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs

View check run for this annotation

Codecov / codecov/patch

COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs#L118-L121

Added lines #L118 - L121 were not covered by tests
}
}
93 changes: 93 additions & 0 deletions COMET.Web.Common/Components/BookEditor/InputEditor.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<!------------------------------------------------------------------------------
// Copyright (c) 2023 RHEA System S.A.
//
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar
//
// 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.BookEditor
@inherits DisposableComponent
@using CDP4Common.SiteDirectoryData
@using CDP4Common.CommonData
@using CDP4Common.EngineeringModelData
@using CDP4Common.ReportingData
@typeparam TItem

<div>
<DxTabs>
<DxTabPage Text="Basic">
<div class="tab-content">
@if (this.Item is INamedThing namedThing)
{
<div class="w-100 editor-row">
<p>Name:</p>
<DxTextBox CssClass="w-100" @bind-Text="@namedThing.Name" />
</div>
}

@if (this.Item is IShortNamedThing shortNamedThing)
{
<div class="w-100 editor-row">
<p>ShortName:</p>
<DxTextBox CssClass="w-100" @bind-Text="@shortNamedThing.ShortName" />
</div>
}

@if (this.Item is IOwnedThing ownedThing)
{
<div class="w-100 editor-row">
<p>Owner:</p>
<DxComboBox @bind-Value="@ownedThing.Owner"
Data="@this.ActiveDomains"
TData="DomainOfExpertise"
TValue="DomainOfExpertise"
TextFieldName="@nameof(DomainOfExpertise.Name)"
CssClass="w-100" />
</div>
}

@if (this.Item is TextualNote textualNote)
{

Check warning on line 64 in COMET.Web.Common/Components/BookEditor/InputEditor.razor

View check run for this annotation

Codecov / codecov/patch

COMET.Web.Common/Components/BookEditor/InputEditor.razor#L64

Added line #L64 was not covered by tests
<div class="w-100 editor-row">
<p>Content:</p>
<DxMemo @bind-Text="textualNote.Content"
CssClass="w-100"
Rows="4" />
</div>
}

Check warning on line 71 in COMET.Web.Common/Components/BookEditor/InputEditor.razor

View check run for this annotation

Codecov / codecov/patch

COMET.Web.Common/Components/BookEditor/InputEditor.razor#L71

Added line #L71 was not covered by tests
</div>
</DxTabPage>
<DxTabPage Text="Category">
<div class="tab-content">
@if (this.Item is ICategorizableThing categorizableThing)
{
<DxListBox Values="@categorizableThing.Category"
Data="@this.AvailableCategories"
TData="Category"
TValue="Category"
ValuesChanged="@this.OnCategoryChange"
TextFieldName="@nameof(Category.Name)"
SelectionMode="ListBoxSelectionMode.Multiple"
ShowCheckboxes="true"
CssClass="w-auto mt-1 me-1 flex-grow-1 chi-220"
style="flex-basis: 240px">
</DxListBox>
}
</div>
</DxTabPage>
</DxTabs>
</div>
Loading
Loading