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 #586 [Reference Data] As a user I want to be able to create and edit a Measurement Scale #587

Merged
merged 5 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="MappingToReferenceScalesTableTestFixture.cs" company="Starion Group S.A.">
// Copyright (c) 2024 Starion Group S.A.
//
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, João Rua
//
// This file is part of COMET WEB Community Edition
// The COMET WEB Community Edition is the Starion Group 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 COMETwebapp.Tests.Components.ReferenceData.MeasurementScales
{
using Bunit;

using CDP4Common.SiteDirectoryData;

using COMET.Web.Common.Test.Helpers;

using COMETwebapp.Components.ReferenceData.MeasurementScales;

using DevExpress.Blazor;

using NUnit.Framework;

using TestContext = Bunit.TestContext;

[TestFixture]
public class MappingToReferenceScalesTableTestFixture
{
private TestContext context;
private IRenderedComponent<MappingToReferenceScalesTable> renderer;

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

var mappingToReferenceScale = new MappingToReferenceScale
{
ReferenceScaleValue = new ScaleValueDefinition(),
DependentScaleValue = new ScaleValueDefinition()
};

this.renderer = this.context.RenderComponent<MappingToReferenceScalesTable>(parameters =>
{
parameters.Add(p => p.MappingToReferenceScales, [mappingToReferenceScale]);
parameters.Add(p => p.DependentScaleValueDefinitions, [new ScaleValueDefinition()]);
parameters.Add(p => p.ReferenceScaleValueDefinitions, [new ScaleValueDefinition()]);
});
}

[TearDown]
public void Teardown()
{
this.context.CleanContext();
this.context.Dispose();
}

[Test]
public void VerifyOnInitialized()
{
Assert.Multiple(() =>
{
Assert.That(this.renderer.Instance, Is.Not.Null);
Assert.That(this.renderer.Instance.DependentScaleValueDefinitions, Is.Not.Null);
Assert.That(this.renderer.Instance.DependentScaleValueDefinitions, Is.Not.Null);
Assert.That(this.renderer.Instance.ShouldCreate, Is.EqualTo(false));
});
}

[Test]
public async Task VerifyUnitFactorsTable()
{
var timesMappingToReferenceScalesChanged = 0;

this.renderer.SetParametersAndRender(p => { p.Add(parameters => parameters.MappingToReferenceScalesChanged, () => { timesMappingToReferenceScalesChanged++; }); });

var editMappingToReferenceScaleButton = this.renderer.FindComponents<DxButton>().First(x => x.Instance.Id == "editMappingToReferenceScaleButton");
await this.renderer.InvokeAsync(editMappingToReferenceScaleButton.Instance.Click.InvokeAsync);

var form = this.renderer.FindComponent<DxGrid>();
await this.renderer.InvokeAsync(form.Instance.EditModelSaving.InvokeAsync);

Assert.Multiple(() =>
{
Assert.That(this.renderer.Instance.ShouldCreate, Is.EqualTo(false));
Assert.That(this.renderer.Instance.MappingToReferenceScales, Has.Count.EqualTo(1));
Assert.That(timesMappingToReferenceScalesChanged, Is.EqualTo(1));
});

var addMappingToReferenceScaleButton = this.renderer.FindComponents<DxButton>().First(x => x.Instance.Id == "addMappingToReferenceScaleButton");
await this.renderer.InvokeAsync(addMappingToReferenceScaleButton.Instance.Click.InvokeAsync);
await this.renderer.InvokeAsync(form.Instance.EditModelSaving.InvokeAsync);

Assert.Multiple(() =>
{
Assert.That(this.renderer.Instance.ShouldCreate, Is.EqualTo(true));
Assert.That(this.renderer.Instance.MappingToReferenceScales, Has.Count.EqualTo(2));
Assert.That(timesMappingToReferenceScalesChanged, Is.EqualTo(2));
});

var removeMappingToReferenceScaleButton = this.renderer.FindComponents<DxButton>().First(x => x.Instance.Id == "removeMappingToReferenceScaleButton");
await this.renderer.InvokeAsync(removeMappingToReferenceScaleButton.Instance.Click.InvokeAsync);

Assert.Multiple(() =>
{
Assert.That(this.renderer.Instance.MappingToReferenceScales, Has.Count.EqualTo(1));
Assert.That(timesMappingToReferenceScalesChanged, Is.EqualTo(3));
});
}
}
}
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="MeasurementScalesTableTestFixture.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
// <copyright file="MeasurementScalesTableTestFixture.cs" company="Starion Group S.A.">
// Copyright (c) 2024 Starion Group S.A.
//
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, João Rua
//
// This file is part of COMET WEB Community Edition
// The COMET WEB Community Edition is the Starion Group 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>
// --------------------------------------------------------------------------------------------------------------------
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace COMETwebapp.Tests.Components.ReferenceData
namespace COMETwebapp.Tests.Components.ReferenceData.MeasurementScales
{
using System.Linq;
using System.Threading.Tasks;

using Bunit;

using CDP4Common.CommonData;
using CDP4Common.SiteDirectoryData;

using COMET.Web.Common.Test.Helpers;

using COMETwebapp.Components.ReferenceData;
using COMETwebapp.Components.ReferenceData.MeasurementScales;
using COMETwebapp.Services.ShowHideDeprecatedThingsService;
using COMETwebapp.ViewModels.Components.ReferenceData.MeasurementScales;
using COMETwebapp.ViewModels.Components.ReferenceData.Rows;
using COMETwebapp.Wrappers;

using DevExpress.Blazor;

using DynamicData;

using Microsoft.AspNetCore.Components.Forms;
using Microsoft.Extensions.DependencyInjection;

using Moq;
Expand All @@ -68,22 +68,22 @@ public void SetUp()
this.showHideService = new Mock<IShowHideDeprecatedThingsService>();
this.showHideService.Setup(x => x.ShowDeprecatedThings).Returns(true);

this.measurementScale1 = new OrdinalScale()
this.measurementScale1 = new LogarithmicScale
{
Name = "A name",
ShortName = "AName",
Container = new SiteReferenceDataLibrary(){ ShortName = "rdl" },
Unit = new SimpleUnit() { ShortName = "unit1" },
Container = new SiteReferenceDataLibrary { ShortName = "rdl" },
Unit = new SimpleUnit { ShortName = "unit1" },
NumberSet = NumberSetKind.NATURAL_NUMBER_SET,
IsDeprecated = false
};

this.measurementScale2 = new OrdinalScale()
this.measurementScale2 = new OrdinalScale
{
Name = "B name",
ShortName = "BName",
Container = new SiteReferenceDataLibrary() { ShortName = "rdl" },
Unit = new SimpleUnit(){ ShortName = "unit2" },
Container = new SiteReferenceDataLibrary { ShortName = "rdl" },
Unit = new SimpleUnit { ShortName = "unit2" },
NumberSet = NumberSetKind.INTEGER_NUMBER_SET,
IsDeprecated = true
};
Expand All @@ -92,13 +92,16 @@ public void SetUp()
rows.Add(new MeasurementScaleRowViewModel(this.measurementScale1));
rows.Add(new MeasurementScaleRowViewModel(this.measurementScale2));

var availableMeasurementScaleTypes = new List<ClassKind> { ClassKind.CyclicRatioScale, ClassKind.IntervalScale, ClassKind.LogarithmicScale, ClassKind.OrdinalScale, ClassKind.RatioScale };

this.viewModel.Setup(x => x.Rows).Returns(rows);
this.viewModel.Setup(x => x.MeasurementUnits).Returns([]);
this.viewModel.Setup(x => x.NumberSetKinds).Returns([]);
this.viewModel.Setup(x => x.ReferenceDataLibraries).Returns([]);
this.viewModel.Setup(x => x.ShowHideDeprecatedThingsService).Returns(this.showHideService.Object);
this.viewModel.Setup(x => x.IsOnDeprecationMode).Returns(true);
this.viewModel.Setup(x => x.Thing).Returns(new OrdinalScale());
this.viewModel.Setup(x => x.MeasurementScaleTypes).Returns(availableMeasurementScaleTypes.Select(x => new ClassKindWrapper(x)));
this.viewModel.Setup(x => x.Thing).Returns(new LogarithmicScale());

this.context.Services.AddSingleton(this.viewModel.Object);
this.context.ConfigureDevExpressBlazor();
Expand All @@ -112,18 +115,36 @@ public void Teardown()
}

[Test]
public void VerifyOnInitialized()
public async Task VerifyAddingOrEditingMeasurementScale()
{
var renderer = this.context.RenderComponent<MeasurementScalesTable>();

var addMeasurementScaleButton = renderer.FindComponents<DxButton>().First(x => x.Instance.Id == "addMeasurementScaleButton");
await renderer.InvokeAsync(addMeasurementScaleButton.Instance.Click.InvokeAsync);

Assert.Multiple(() =>
{
Assert.That(renderer.Instance.ShouldCreateThing, Is.EqualTo(false));
Assert.That(renderer.Instance.ViewModel, Is.Not.Null);
Assert.That(renderer.Markup, Does.Contain(this.measurementScale1.Name));
Assert.That(renderer.Markup, Does.Contain(this.measurementScale2.Name));
this.viewModel.Verify(x => x.InitializeViewModel(), Times.Once);
Assert.That(renderer.Instance.ShouldCreateThing, Is.EqualTo(true));
Assert.That(this.viewModel.Object.Thing, Is.InstanceOf(typeof(MeasurementScale)));
});

var measurementScalesGrid = renderer.FindComponent<DxGrid>();
await renderer.InvokeAsync(() => measurementScalesGrid.Instance.SelectedDataItemChanged.InvokeAsync(new MeasurementScaleRowViewModel(this.measurementScale1)));
Assert.That(renderer.Instance.IsOnEditMode, Is.EqualTo(true));

var measurementScalesForm = renderer.FindComponents<MeasurementScalesForm>()[1];
var measurementScalesEditForm = measurementScalesForm.FindComponent<EditForm>();
await measurementScalesForm.InvokeAsync(measurementScalesEditForm.Instance.OnValidSubmit.InvokeAsync);

Assert.Multiple(() =>
{
this.viewModel.Verify(x => x.CreateOrEditMeasurementScale(false), Times.Once);
Assert.That(this.viewModel.Object.Thing, Is.InstanceOf(typeof(LogarithmicScale)));
});

var form = renderer.FindComponent<DxGrid>();
await renderer.InvokeAsync(form.Instance.EditModelSaving.InvokeAsync);
this.viewModel.Verify(x => x.CreateOrEditMeasurementScale(false), Times.Once);
}

[Test]
Expand All @@ -141,26 +162,17 @@ public async Task VerifyDeprecatingAndUndeprecatingMeasurementScale()
}

[Test]
public async Task VerifyAddingOrEditingMeasurementScale()
public void VerifyOnInitialized()
{
var renderer = this.context.RenderComponent<MeasurementScalesTable>();

var addMeasurementScaleButton = renderer.FindComponents<DxButton>().First(x => x.Instance.Id == "addMeasurementScaleButton");
await renderer.InvokeAsync(addMeasurementScaleButton.Instance.Click.InvokeAsync);

Assert.Multiple(() =>
{
Assert.That(renderer.Instance.ShouldCreateThing, Is.EqualTo(true));
Assert.That(this.viewModel.Object.Thing, Is.InstanceOf(typeof(MeasurementScale)));
});

var editMeasurementScaleButton = renderer.FindComponents<DxButton>().First(x => x.Instance.Id == "editScaleButton");
await renderer.InvokeAsync(editMeasurementScaleButton.Instance.Click.InvokeAsync);

Assert.Multiple(() =>
{
Assert.That(renderer.Instance.ShouldCreateThing, Is.EqualTo(false));
Assert.That(this.viewModel.Object.Thing, Is.InstanceOf(typeof(MeasurementScale)));
Assert.That(renderer.Instance.ViewModel, Is.Not.Null);
Assert.That(renderer.Markup, Does.Contain(this.measurementScale1.Name));
Assert.That(renderer.Markup, Does.Contain(this.measurementScale2.Name));
this.viewModel.Verify(x => x.InitializeViewModel(), Times.Once);
});
}
}
Expand Down
Loading
Loading