Skip to content

Commit

Permalink
Feat #557 As a user i want to show the options of a model and create,…
Browse files Browse the repository at this point in the history
… edit and delete an option (#570)
  • Loading branch information
joao4all authored Apr 8, 2024
1 parent cfa95a5 commit d29ecd2
Show file tree
Hide file tree
Showing 39 changed files with 1,590 additions and 26 deletions.
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);
}
}
}
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));
}
}
}
2 changes: 1 addition & 1 deletion COMETwebapp.Tests/Model/ApplicationsTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void VerifyApplications()
{
var applications = Applications.ExistingApplications;

Assert.That(applications, Has.Count.EqualTo(12));
Assert.That(applications, Has.Count.EqualTo(13));

foreach (var application in applications)
{
Expand Down
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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace COMETwebapp.Tests.Validators
namespace COMETwebapp.Tests.Validators.ReferenceData
{
using CDP4Common.SiteDirectoryData;
using CDP4Common.Validation;
using COMETwebapp.Validators.MeasurementUnits;

using COMETwebapp.Validators.ReferenceData.MeasurementUnits;

using NUnit.Framework;

Expand Down Expand Up @@ -100,8 +100,8 @@ public void VerifyPrefixedUnitValidation()

prefixedUnit = new PrefixedUnit()
{
Prefix = new UnitPrefix(){ ShortName = "pre" },
ReferenceUnit = new SimpleUnit(){ ShortName = "ref" }
Prefix = new UnitPrefix() { ShortName = "pre" },
ReferenceUnit = new SimpleUnit() { ShortName = "ref" }
};

Assert.Multiple(() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace COMETwebapp.Tests.Validators
namespace COMETwebapp.Tests.Validators.SiteDirectory
{
using CDP4Common.SiteDirectoryData;
using CDP4Common.Validation;

using COMETwebapp.Validators;
using COMETwebapp.Validators.SiteDirectory;

using NUnit.Framework;

Expand Down
Loading

0 comments on commit d29ecd2

Please sign in to comment.