-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat #557 As a user i want to show the options of a model and create,…
… edit and delete an option (#570)
- Loading branch information
Showing
39 changed files
with
1,590 additions
and
26 deletions.
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
COMETwebapp.Tests/Components/EngineeringModel/EngineeringModelBodyTestFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// <copyright file="EngineeringModelBodyTestFixture.cs" company="RHEA System S.A."> | ||
// 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 <http://www.gnu.org/licenses/>. | ||
// </copyright> | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
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<EngineeringModelBody> renderer; | ||
private Mock<IEngineeringModelBodyViewModel> viewModel; | ||
private Mock<IOptionsTableViewModel> optionsTableViewModel; | ||
private Iteration iteration; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
this.context = new TestContext(); | ||
|
||
this.viewModel = new Mock<IEngineeringModelBodyViewModel>(); | ||
this.iteration = new Iteration(); | ||
|
||
this.viewModel.Setup(x => x.CurrentThing).Returns(this.iteration); | ||
|
||
this.optionsTableViewModel = new Mock<IOptionsTableViewModel>(); | ||
this.optionsTableViewModel.Setup(x => x.Rows).Returns(new SourceList<OptionRowViewModel>()); | ||
this.viewModel.Setup(x => x.OptionsTableViewModel).Returns(this.optionsTableViewModel.Object); | ||
|
||
var configuration = new Mock<IConfigurationService>(); | ||
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<EngineeringModelBody>(); | ||
} | ||
|
||
[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<DxToolbarItem>(); | ||
await this.renderer.InvokeAsync(toolbarItem.Instance.Click.InvokeAsync); | ||
Assert.That(this.renderer.Instance.SelectedComponent, Is.Not.Null); | ||
} | ||
} | ||
} |
170 changes: 170 additions & 0 deletions
170
COMETwebapp.Tests/Components/EngineeringModel/OptionsTableTestFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// <copyright file="OptionsTableTestFixture.cs" company="RHEA System S.A."> | ||
// 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 <http://www.gnu.org/licenses/>. | ||
// </copyright> | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
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<OptionsTable> renderer; | ||
private Mock<IOptionsTableViewModel> viewModel; | ||
private Option option; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
this.context = new TestContext(); | ||
this.viewModel = new Mock<IOptionsTableViewModel>(); | ||
|
||
this.option = new Option() | ||
{ | ||
Name = "A name", | ||
ShortName = "AName", | ||
Container = new Iteration(), | ||
}; | ||
|
||
var rows = new SourceList<OptionRowViewModel>(); | ||
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<OptionsTable>(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<DxButton>().First(x => x.Instance.Id == "deleteButton"); | ||
await this.renderer.InvokeAsync(deleteButton.Instance.Click.InvokeAsync); | ||
this.viewModel.Verify(x => x.OnDeleteButtonClick(It.IsAny<OptionRowViewModel>()), Times.Once); | ||
this.viewModel.Setup(x => x.IsOnDeletionMode).Returns(true); | ||
|
||
this.renderer.Render(); | ||
|
||
var deletionPopup = this.renderer.FindComponent<DxPopup>(); | ||
var confirmDeletionButton = deletionPopup.FindComponents<DxButton>().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<DxButton>().First(x => x.Instance.Id == "addOptionButton"); | ||
await this.renderer.InvokeAsync(addOptionButton.Instance.Click.InvokeAsync); | ||
var form = this.renderer.FindComponent<OptionsForm>(); | ||
|
||
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<EditForm>(); | ||
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<DxGrid>(); | ||
await this.renderer.InvokeAsync(() => grid.Instance.SelectedDataItemChanged.InvokeAsync(this.viewModel.Object.Rows.Items.First())); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
this.viewModel.Verify(x => x.SetCurrentOption(It.IsAny<Option>())); | ||
Assert.That(this.renderer.Instance.IsOnEditMode, Is.EqualTo(true)); | ||
}); | ||
|
||
var form = this.renderer.FindComponent<OptionsForm>(); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
Assert.That(form, Is.Not.Null); | ||
Assert.That(form.Instance.IsVisible, Is.EqualTo(true)); | ||
Assert.That(form.Instance.ShouldCreate, Is.EqualTo(false)); | ||
}); | ||
|
||
var editForm = form.FindComponent<EditForm>(); | ||
await form.InvokeAsync(editForm.Instance.OnValidSubmit.InvokeAsync); | ||
this.viewModel.Verify(x => x.CreateOrEditOption(false), Times.Once); | ||
|
||
var cancelButton = editForm.FindComponents<DxButton>().First(x => x.Instance.Id == "cancelOptionsButton"); | ||
await editForm.InvokeAsync(cancelButton.Instance.Click.InvokeAsync); | ||
Assert.That(this.renderer.Instance.IsOnEditMode, Is.EqualTo(false)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
COMETwebapp.Tests/Validators/EngineeringModel/OptionValidatorTestFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// <copyright file="OptionValidatorTestFixture.cs" company="RHEA System S.A."> | ||
// 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 <http://www.gnu.org/licenses/>. | ||
// </copyright> | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
namespace COMETwebapp.Tests.Validators.EngineeringModel | ||
{ | ||
using CDP4Common.EngineeringModelData; | ||
using CDP4Common.Validation; | ||
|
||
using COMETwebapp.Validators.EngineeringModel; | ||
|
||
using NUnit.Framework; | ||
|
||
[TestFixture] | ||
public class OptionValidatorTestFixture | ||
{ | ||
private OptionValidator validator; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
var validationService = new ValidationService(); | ||
this.validator = new OptionValidator(validationService); | ||
} | ||
|
||
[Test] | ||
public void VerifyValidationScenarios() | ||
{ | ||
var option = new Option(); | ||
Assert.That(this.validator.Validate(option).IsValid, Is.EqualTo(false)); | ||
|
||
option = new Option() | ||
{ | ||
Name = "name1", | ||
ShortName = "short name" | ||
}; | ||
|
||
Assert.That(this.validator.Validate(option).IsValid, Is.EqualTo(false)); | ||
|
||
option.ShortName = "shortName"; | ||
Assert.That(this.validator.Validate(option).IsValid, Is.EqualTo(true)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.