From d29ecd2b05286eca131d0c22add97c39e3c27b87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Rua?= <140734849+joao4all@users.noreply.github.com> Date: Mon, 8 Apr 2024 13:14:59 +0100 Subject: [PATCH] Feat #557 As a user i want to show the options of a model and create, edit and delete an option (#570) --- .../EngineeringModelBodyTestFixture.cs | 112 ++++++++++++ .../OptionsTableTestFixture.cs | 170 ++++++++++++++++++ .../Model/ApplicationsTestFixture.cs | 2 +- .../OptionValidatorTestFixture.cs | 64 +++++++ .../MeasurementUnitValidatorsTestFixture.cs | 10 +- ...teDomainOfExpertiseValidatorTestFixture.cs | 4 +- .../EngineeringModelValidatorTestFixture.cs | 4 +- .../ParticipantValidatorTestFixture.cs | 4 +- .../RolesValidatorsTestFixture.cs | 4 +- ...ngineeringModelBodyViewModelTestFixture.cs | 74 ++++++++ .../OptionsTableViewModelTestFixture.cs | 166 +++++++++++++++++ .../EngineeringModelBody.razor | 43 +++++ .../EngineeringModelBody.razor.cs | 98 ++++++++++ .../EngineeringModel/OptionsForm.razor | 46 +++++ .../EngineeringModel/OptionsForm.razor.cs | 97 ++++++++++ .../EngineeringModel/OptionsTable.razor | 89 +++++++++ .../EngineeringModel/OptionsTable.razor.cs | 111 ++++++++++++ .../SiteDirectory/Roles/RolesTables.razor | 1 - .../Extensions/ServiceCollectionExtensions.cs | 5 +- COMETwebapp/Model/Applications.cs | 8 + .../EngineeringModel/EngineeringModel.razor | 32 ++++ .../Pages/ModelDashboard/ModelDashboard.razor | 2 +- COMETwebapp/Utilities/WebAppConstantValues.cs | 5 + .../EngineeringModel/OptionValidator.cs | 48 +++++ .../LinearConversionUnitValidator.cs | 2 +- .../MeasurementUnitValidator.cs | 2 +- .../MeasurementUnits/PrefixedUnitValidator.cs | 2 +- .../MeasurementUnits/UnitFactorValidator.cs | 2 +- .../CreateDomainOfExpertiseValidator.cs | 2 +- .../EngineeringModelValidator.cs | 2 +- .../EngineeringModel/ParticipantValidator.cs | 2 +- .../Roles/ParticipantRoleValidator.cs | 2 +- .../Roles/PersonRoleValidator.cs | 2 +- .../EngineeringModelBodyViewModel.cs | 73 ++++++++ .../IEngineeringModelBodyViewModel.cs | 41 +++++ .../Options/IOptionsTableViewModel.cs | 61 +++++++ .../Options/OptionsTableViewModel.cs | 162 +++++++++++++++++ .../Rows/OptionRowViewModel.cs | 61 +++++++ COMETwebapp/_Imports.razor | 1 + 39 files changed, 1590 insertions(+), 26 deletions(-) create mode 100644 COMETwebapp.Tests/Components/EngineeringModel/EngineeringModelBodyTestFixture.cs create mode 100644 COMETwebapp.Tests/Components/EngineeringModel/OptionsTableTestFixture.cs create mode 100644 COMETwebapp.Tests/Validators/EngineeringModel/OptionValidatorTestFixture.cs rename COMETwebapp.Tests/Validators/{ => ReferenceData}/MeasurementUnitValidatorsTestFixture.cs (95%) rename COMETwebapp.Tests/Validators/{ => SiteDirectory}/CreateDomainOfExpertiseValidatorTestFixture.cs (96%) rename COMETwebapp.Tests/Validators/{EngineeringModel => SiteDirectory}/EngineeringModelValidatorTestFixture.cs (96%) rename COMETwebapp.Tests/Validators/{EngineeringModel => SiteDirectory}/ParticipantValidatorTestFixture.cs (95%) rename COMETwebapp.Tests/Validators/{ => SiteDirectory}/RolesValidatorsTestFixture.cs (96%) create mode 100644 COMETwebapp.Tests/ViewModels/Components/EngineeringModel/EngineeringModelBodyViewModelTestFixture.cs create mode 100644 COMETwebapp.Tests/ViewModels/Components/EngineeringModel/OptionsTableViewModelTestFixture.cs create mode 100644 COMETwebapp/Components/EngineeringModel/EngineeringModelBody.razor create mode 100644 COMETwebapp/Components/EngineeringModel/EngineeringModelBody.razor.cs create mode 100644 COMETwebapp/Components/EngineeringModel/OptionsForm.razor create mode 100644 COMETwebapp/Components/EngineeringModel/OptionsForm.razor.cs create mode 100644 COMETwebapp/Components/EngineeringModel/OptionsTable.razor create mode 100644 COMETwebapp/Components/EngineeringModel/OptionsTable.razor.cs create mode 100644 COMETwebapp/Pages/EngineeringModel/EngineeringModel.razor create mode 100644 COMETwebapp/Validators/EngineeringModel/OptionValidator.cs rename COMETwebapp/Validators/{ => ReferenceData}/MeasurementUnits/LinearConversionUnitValidator.cs (97%) rename COMETwebapp/Validators/{ => ReferenceData}/MeasurementUnits/MeasurementUnitValidator.cs (97%) rename COMETwebapp/Validators/{ => ReferenceData}/MeasurementUnits/PrefixedUnitValidator.cs (97%) rename COMETwebapp/Validators/{ => ReferenceData}/MeasurementUnits/UnitFactorValidator.cs (97%) rename COMETwebapp/Validators/{ => SiteDirectory}/CreateDomainOfExpertiseValidator.cs (97%) rename COMETwebapp/Validators/{ => SiteDirectory}/EngineeringModel/EngineeringModelValidator.cs (98%) rename COMETwebapp/Validators/{ => SiteDirectory}/EngineeringModel/ParticipantValidator.cs (97%) rename COMETwebapp/Validators/{ => SiteDirectory}/Roles/ParticipantRoleValidator.cs (97%) rename COMETwebapp/Validators/{ => SiteDirectory}/Roles/PersonRoleValidator.cs (97%) create mode 100644 COMETwebapp/ViewModels/Components/EngineeringModel/EngineeringModelBodyViewModel.cs create mode 100644 COMETwebapp/ViewModels/Components/EngineeringModel/IEngineeringModelBodyViewModel.cs create mode 100644 COMETwebapp/ViewModels/Components/EngineeringModel/Options/IOptionsTableViewModel.cs create mode 100644 COMETwebapp/ViewModels/Components/EngineeringModel/Options/OptionsTableViewModel.cs create mode 100644 COMETwebapp/ViewModels/Components/EngineeringModel/Rows/OptionRowViewModel.cs diff --git a/COMETwebapp.Tests/Components/EngineeringModel/EngineeringModelBodyTestFixture.cs b/COMETwebapp.Tests/Components/EngineeringModel/EngineeringModelBodyTestFixture.cs new file mode 100644 index 00000000..91b4e5ab --- /dev/null +++ b/COMETwebapp.Tests/Components/EngineeringModel/EngineeringModelBodyTestFixture.cs @@ -0,0 +1,112 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Antoine Théate, João Rua +// +// This file is part of CDP4-COMET WEB Community Edition +// The CDP4-COMET WEB Community Edition is the RHEA Web Application implementation of ECSS-E-TM-10-25 Annex A and Annex C. +// +// The CDP4-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 CDP4-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 . +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMETwebapp.Tests.Components.EngineeringModel +{ + using System.Threading.Tasks; + + using Bunit; + + using CDP4Common.EngineeringModelData; + + using COMET.Web.Common.Model.Configuration; + using COMET.Web.Common.Services.ConfigurationService; + using COMET.Web.Common.Test.Helpers; + + using COMETwebapp.Components.EngineeringModel; + using COMETwebapp.ViewModels.Components.EngineeringModel; + using COMETwebapp.ViewModels.Components.EngineeringModel.Options; + using COMETwebapp.ViewModels.Components.EngineeringModel.Rows; + + using DevExpress.Blazor; + + using DynamicData; + + using Microsoft.Extensions.DependencyInjection; + + using Moq; + + using NUnit.Framework; + + using TestContext = Bunit.TestContext; + + [TestFixture] + public class EngineeringModelBodyTestFixture + { + private TestContext context; + private IRenderedComponent renderer; + private Mock viewModel; + private Mock optionsTableViewModel; + private Iteration iteration; + + [SetUp] + public void SetUp() + { + this.context = new TestContext(); + + this.viewModel = new Mock(); + this.iteration = new Iteration(); + + this.viewModel.Setup(x => x.CurrentThing).Returns(this.iteration); + + this.optionsTableViewModel = new Mock(); + this.optionsTableViewModel.Setup(x => x.Rows).Returns(new SourceList()); + this.viewModel.Setup(x => x.OptionsTableViewModel).Returns(this.optionsTableViewModel.Object); + + var configuration = new Mock(); + configuration.Setup(x => x.ServerConfiguration).Returns(new ServerConfiguration()); + + this.context.Services.AddSingleton(configuration.Object); + this.context.Services.AddSingleton(this.viewModel.Object); + this.context.ConfigureDevExpressBlazor(); + + this.renderer = this.context.RenderComponent(); + } + + [TearDown] + public void Teardown() + { + this.context.CleanContext(); + this.context.Dispose(); + } + + [Test] + public void VerifyOnInitialized() + { + Assert.Multiple(() => + { + Assert.That(this.renderer.Instance.ViewModel, Is.Not.Null); + Assert.That(this.viewModel.Object.CurrentThing, Is.EqualTo(this.iteration)); + }); + } + + [Test] + public async Task VerifySelectComponent() + { + var toolbarItem = this.renderer.FindComponent(); + await this.renderer.InvokeAsync(toolbarItem.Instance.Click.InvokeAsync); + Assert.That(this.renderer.Instance.SelectedComponent, Is.Not.Null); + } + } +} diff --git a/COMETwebapp.Tests/Components/EngineeringModel/OptionsTableTestFixture.cs b/COMETwebapp.Tests/Components/EngineeringModel/OptionsTableTestFixture.cs new file mode 100644 index 00000000..ebd1cef5 --- /dev/null +++ b/COMETwebapp.Tests/Components/EngineeringModel/OptionsTableTestFixture.cs @@ -0,0 +1,170 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Antoine Théate, João Rua +// +// This file is part of CDP4-COMET WEB Community Edition +// The CDP4-COMET WEB Community Edition is the RHEA Web Application implementation of ECSS-E-TM-10-25 Annex A and Annex C. +// +// The CDP4-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 CDP4-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 . +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMETwebapp.Tests.Components.EngineeringModel +{ + using System.Linq; + using System.Threading.Tasks; + + using Bunit; + + using CDP4Common.EngineeringModelData; + + using COMET.Web.Common.Test.Helpers; + + using COMETwebapp.Components.EngineeringModel; + using COMETwebapp.ViewModels.Components.EngineeringModel.Options; + using COMETwebapp.ViewModels.Components.EngineeringModel.Rows; + + using DevExpress.Blazor; + + using DynamicData; + + using Microsoft.AspNetCore.Components.Forms; + + using Moq; + + using NUnit.Framework; + + using TestContext = Bunit.TestContext; + + [TestFixture] + public class OptionsTableTestFixture + { + private TestContext context; + private IRenderedComponent renderer; + private Mock viewModel; + private Option option; + + [SetUp] + public void SetUp() + { + this.context = new TestContext(); + this.viewModel = new Mock(); + + this.option = new Option() + { + Name = "A name", + ShortName = "AName", + Container = new Iteration(), + }; + + var rows = new SourceList(); + rows.Add(new OptionRowViewModel(this.option){ IsDefault = true}); + this.viewModel.Setup(x => x.Rows).Returns(rows); + this.viewModel.Setup(x => x.Thing).Returns(new Option()); + + this.context.ConfigureDevExpressBlazor(); + + this.renderer = this.context.RenderComponent(parameters => + { + parameters.Add(p => p.ViewModel, this.viewModel.Object); + }); + } + + [TearDown] + public void Teardown() + { + this.context.CleanContext(); + this.context.Dispose(); + } + + [Test] + public void VerifyOnInitialized() + { + Assert.Multiple(() => + { + Assert.That(this.renderer.Instance.ShouldCreateThing, Is.EqualTo(false)); + Assert.That(this.renderer.Instance.ViewModel, Is.EqualTo(this.viewModel.Object)); + Assert.That(this.renderer.Markup, Does.Contain(this.option.Name)); + this.viewModel.Verify(x => x.InitializeViewModel(), Times.Once); + }); + } + + [Test] + public async Task VerifyDeleteOption() + { + var deleteButton = this.renderer.FindComponents().First(x => x.Instance.Id == "deleteButton"); + await this.renderer.InvokeAsync(deleteButton.Instance.Click.InvokeAsync); + this.viewModel.Verify(x => x.OnDeleteButtonClick(It.IsAny()), Times.Once); + this.viewModel.Setup(x => x.IsOnDeletionMode).Returns(true); + + this.renderer.Render(); + + var deletionPopup = this.renderer.FindComponent(); + var confirmDeletionButton = deletionPopup.FindComponents().ElementAt(1); + await deletionPopup.InvokeAsync(confirmDeletionButton.Instance.Click.InvokeAsync); + this.viewModel.Verify(x => x.OnConfirmPopupButtonClick(), Times.Once); + } + + [Test] + public async Task VerifyCreateOption() + { + var addOptionButton = this.renderer.FindComponents().First(x => x.Instance.Id == "addOptionButton"); + await this.renderer.InvokeAsync(addOptionButton.Instance.Click.InvokeAsync); + var form = this.renderer.FindComponent(); + + Assert.Multiple(() => + { + Assert.That(form, Is.Not.Null); + Assert.That(form.Instance.IsVisible, Is.EqualTo(true)); + Assert.That(form.Instance.ShouldCreate, Is.EqualTo(true)); + }); + + var editForm = form.FindComponent(); + await form.InvokeAsync(editForm.Instance.OnValidSubmit.InvokeAsync); + this.viewModel.Verify(x => x.CreateOrEditOption(true), Times.Once); + } + + [Test] + public async Task VerifyEditOption() + { + var grid = this.renderer.FindComponent(); + await this.renderer.InvokeAsync(() => grid.Instance.SelectedDataItemChanged.InvokeAsync(this.viewModel.Object.Rows.Items.First())); + + Assert.Multiple(() => + { + this.viewModel.Verify(x => x.SetCurrentOption(It.IsAny