Skip to content

Commit

Permalink
Feat #612 [Server Administration] Refactor Models page to be inline w…
Browse files Browse the repository at this point in the history
…ith Measurement Scale page (#652)
  • Loading branch information
joao4all authored Jun 3, 2024
1 parent 732dba8 commit dac2b88
Show file tree
Hide file tree
Showing 39 changed files with 1,015 additions and 1,739 deletions.
Original file line number Diff line number Diff line change
@@ -1,50 +1,39 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ActiveDomainsTableTestFixture.cs" company="Starion Group S.A.">
// Copyright (c) 2023-2024 Starion Group 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 Starion 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="ActiveDomainsTableTestFixture.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.SiteDirectory.EngineeringModels
{
using System.Linq;
using System.Threading.Tasks;

using Bunit;

using CDP4Common.SiteDirectoryData;

using COMET.Web.Common.Test.Helpers;

using COMETwebapp.Components.SiteDirectory.EngineeringModel;
using COMETwebapp.ViewModels.Components.SiteDirectory.EngineeringModels;
using COMETwebapp.ViewModels.Components.SiteDirectory.Rows;

using DevExpress.Blazor;

using DynamicData;

using Microsoft.Extensions.DependencyInjection;

using Moq;

using NUnit.Framework;

using TestContext = Bunit.TestContext;
Expand All @@ -54,7 +43,6 @@ public class ActiveDomainsTableTestFixture
{
private TestContext context;
private IRenderedComponent<ActiveDomainsTable> renderer;
private Mock<IActiveDomainsTableViewModel> viewModel;
private EngineeringModelSetup model;
private DomainOfExpertise domain1;
private DomainOfExpertise domain2;
Expand All @@ -63,37 +51,26 @@ public class ActiveDomainsTableTestFixture
public void SetUp()
{
this.context = new TestContext();
this.viewModel = new Mock<IActiveDomainsTableViewModel>();
this.model = new EngineeringModelSetup();

this.domain1 = new DomainOfExpertise()
this.domain1 = new DomainOfExpertise
{
Name = "domain A",
ShortName = "domainA",
Container = new EngineeringModelSetup(){ ShortName = "model" },
Container = new EngineeringModelSetup { ShortName = "model" }
};

this.domain2 = new DomainOfExpertise()
this.domain2 = new DomainOfExpertise
{
Name = "domain B",
ShortName = "domainB",
Container = new EngineeringModelSetup() { ShortName = "model" },
Container = new EngineeringModelSetup { ShortName = "model" }
};

var rows = new SourceList<DomainOfExpertiseRowViewModel>();
rows.Add(new DomainOfExpertiseRowViewModel(this.domain1));
rows.Add(new DomainOfExpertiseRowViewModel(this.domain2));

this.viewModel.Setup(x => x.Rows).Returns(rows);
this.viewModel.Setup(x => x.CurrentThing).Returns(new DomainOfExpertise());

this.context.Services.AddSingleton(this.viewModel.Object);
this.model.ActiveDomain = [this.domain1, this.domain2];
this.context.ConfigureDevExpressBlazor();

this.renderer = this.context.RenderComponent<ActiveDomainsTable>(p =>
{
p.Add(parameter => parameter.EngineeringModelSetup, this.model);
});
this.renderer = this.context.RenderComponent<ActiveDomainsTable>(p => { p.Add(parameter => parameter.EngineeringModelSetup, this.model); });
}

[TearDown]
Expand All @@ -103,20 +80,6 @@ public void Teardown()
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.Not.Null);
Assert.That(this.renderer.Instance.EngineeringModelSetup, Is.EqualTo(this.model));
Assert.That(this.renderer.Markup, Does.Contain(this.domain1.Name));
Assert.That(this.renderer.Markup, Does.Contain(this.domain2.Name));
this.viewModel.Verify(x => x.InitializeViewModel(It.IsAny<EngineeringModelSetup>()), Times.Once);
});
}

[Test]
public async Task VerifyEditActiveDomains()
{
Expand All @@ -129,18 +92,25 @@ public async Task VerifyEditActiveDomains()

var saveActiveDomainsButton = this.renderer.FindComponents<DxButton>().First(x => x.Instance.Id == "saveActiveDomainsButton");
await this.renderer.InvokeAsync(saveActiveDomainsButton.Instance.Click.InvokeAsync);
this.viewModel.Verify(x => x.EditActiveDomains(), Times.Once);

// Opens the popup again
await this.renderer.InvokeAsync(editActiveDomainsClickableItem.Instance.Click.InvokeAsync);

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

Assert.That(this.renderer.Instance.IsOnEditMode, Is.EqualTo(false));
}

[Test]
public void VerifyOnInitialized()
{
Assert.Multiple(() =>
{
this.viewModel.Verify(x => x.ResetSelectedDomainsOfExpertise(), Times.Once);
Assert.That(this.renderer.Instance.IsOnEditMode, Is.EqualTo(false));
Assert.That(this.renderer.Instance.ShouldCreateThing, Is.EqualTo(false));
Assert.That(this.renderer.Instance.EngineeringModelSetup, Is.EqualTo(this.model));
Assert.That(this.renderer.Markup, Does.Contain(this.domain1.Name));
Assert.That(this.renderer.Markup, Does.Contain(this.domain2.Name));
});
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="EngineeringModelsTableTestFixture.cs" company="Starion Group S.A.">
// Copyright (c) 2023-2024 Starion Group 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 Starion 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="EngineeringModelsTableTestFixture.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.SiteDirectory.EngineeringModels
{
using System.Linq;
using System.Threading.Tasks;

using Bunit;

using CDP4Common.SiteDirectoryData;
Expand All @@ -41,6 +38,7 @@ namespace COMETwebapp.Tests.Components.SiteDirectory.EngineeringModels

using DynamicData;

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

using Moq;
Expand All @@ -65,18 +63,18 @@ public void SetUp()

this.viewModel = new Mock<IEngineeringModelsTableViewModel>();

this.engineeringModel1 = new EngineeringModelSetup()
this.engineeringModel1 = new EngineeringModelSetup
{
Name = "A name",
ShortName = "AName",
Container = new SiteDirectory(){ ShortName = "siteDir" },
Container = new SiteDirectory { ShortName = "siteDir" }
};

this.engineeringModel2 = new EngineeringModelSetup()
this.engineeringModel2 = new EngineeringModelSetup
{
Name = "B name",
ShortName = "BName",
Container = new SiteDirectory() { ShortName = "siteDir" },
Container = new SiteDirectory { ShortName = "siteDir" }
};

var rows = new SourceList<EngineeringModelRowViewModel>();
Expand All @@ -100,42 +98,58 @@ public void Teardown()
}

[Test]
public void VerifyOnInitialized()
public async Task VerifyAddOrEditEngineeringModel()
{
var addEngineeringModelButton = this.renderer.FindComponents<DxButton>().First(x => x.Instance.Id == "dataItemDetailsButton");
await this.renderer.InvokeAsync(addEngineeringModelButton.Instance.Click.InvokeAsync);

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

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

var engineeringModelsForm = this.renderer.FindComponent<EngineeringModelsForm>();
var engineeringModelsEditForm = engineeringModelsForm.FindComponent<EditForm>();
await engineeringModelsForm.InvokeAsync(engineeringModelsEditForm.Instance.OnValidSubmit.InvokeAsync);

Assert.Multiple(() =>
{
this.viewModel.Verify(x => x.CreateOrEditEngineeringModel(false), Times.Once);
Assert.That(this.viewModel.Object.CurrentThing, Is.InstanceOf(typeof(EngineeringModelSetup)));
});

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

[Test]
public async Task VerifyDeleteEngineeringModel()
{
var deleteButton = this.renderer.FindComponents<DxButton>().First(x => x.Instance.Id == "deleteEngineeringModelButton");
var engineeringModelsGrid = this.renderer.FindComponent<DxGrid>();
await this.renderer.InvokeAsync(() => engineeringModelsGrid.Instance.SelectedDataItemChanged.InvokeAsync(new EngineeringModelRowViewModel(this.engineeringModel1)));

var deleteButton = this.renderer.FindComponents<DxButton>().First(x => x.Instance.Id == "deleteItemButton");
await this.renderer.InvokeAsync(deleteButton.Instance.Click.InvokeAsync);
this.viewModel.Verify(x => x.OnDeleteButtonClick(It.IsAny<EngineeringModelRowViewModel>()), Times.Once);
this.viewModel.VerifySet(x => x.IsOnDeletionMode = true, Times.Once);
}

[Test]
public async Task VerifyAddEngineeringModel()
public void VerifyOnInitialized()
{
var addEngineeringModelButton = this.renderer.FindComponents<DxButton>().First(x => x.Instance.Id == "addEngineeringModelButton");
await this.renderer.InvokeAsync(addEngineeringModelButton.Instance.Click.InvokeAsync);
var grid = this.renderer.FindComponent<DxGrid>();
Assert.That(grid.Instance.IsEditing(), Is.EqualTo(true));

var cancelEngineeringModelButton = this.renderer.FindComponents<DxButton>().First(x => x.Instance.Id == "cancelEngineeringModelButton");
await this.renderer.InvokeAsync(cancelEngineeringModelButton.Instance.Click.InvokeAsync);
Assert.That(grid.Instance.IsEditing(), Is.EqualTo(false));

await this.renderer.InvokeAsync(addEngineeringModelButton.Instance.Click.InvokeAsync);
var saveEngineeringModelButton = this.renderer.FindComponents<DxButton>().First(x => x.Instance.Id == "saveEngineeringModelButton");
await this.renderer.InvokeAsync(saveEngineeringModelButton.Instance.Click.InvokeAsync);
this.viewModel.Verify(x => x.CreateEngineeringModel(), Times.Once);
Assert.Multiple(() =>
{
Assert.That(this.renderer.Instance.ShouldCreateThing, Is.EqualTo(false));
Assert.That(this.renderer.Instance.ViewModel, Is.Not.Null);
Assert.That(this.renderer.Markup, Does.Contain(this.engineeringModel1.Name));
Assert.That(this.renderer.Markup, Does.Contain(this.engineeringModel2.Name));
this.viewModel.Verify(x => x.InitializeViewModel(), Times.Once);
});
}

[Test]
Expand Down
Loading

0 comments on commit dac2b88

Please sign in to comment.