Skip to content

Commit

Permalink
Feat #611 [Server Administration] Refactor Participant Roles page to …
Browse files Browse the repository at this point in the history
…be inline with Measurement Scale page (#650)
  • Loading branch information
joao4all authored May 29, 2024
1 parent 870e28c commit 3c843f1
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 330 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ namespace COMETwebapp.Tests.Components.ReferenceData
using COMET.Web.Common.Test.Helpers;

using COMETwebapp.Components.ReferenceData.MeasurementUnits;
using COMETwebapp.Components.SiteDirectory;
using COMETwebapp.Services.ShowHideDeprecatedThingsService;
using COMETwebapp.ViewModels.Components.ReferenceData.MeasurementUnits;
using COMETwebapp.ViewModels.Components.ReferenceData.Rows;
using COMETwebapp.ViewModels.Components.SiteDirectory.Rows;
using COMETwebapp.Wrappers;

using DevExpress.Blazor;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ParticipantRolesTableTestFixture.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="ParticipantRolesTableTestFixture.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.Roles
{
using System.Linq;
using System.Threading.Tasks;

using Bunit;

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

using DynamicData;

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

using Moq;
Expand All @@ -63,11 +61,11 @@ public void SetUp()
this.context = new TestContext();
this.viewModel = new Mock<IParticipantRolesTableViewModel>();

this.participantRole1 = new ParticipantRole()
this.participantRole1 = new ParticipantRole
{
Name = "Role 1",
ShortName = "role1",
Container = new SiteDirectory(){ ShortName = "siteDir" },
Container = new SiteDirectory { ShortName = "siteDir" }
};

var rows = new SourceList<ParticipantRoleRowViewModel>();
Expand All @@ -90,47 +88,46 @@ public void Teardown()
}

[Test]
public void VerifyOnInitialized()
public async Task VerifyAddingOrEditingParticipantRole()
{
var addParticipantRoleButton = this.renderer.FindComponents<DxButton>().First(x => x.Instance.Id == "dataItemDetailsButton");
await this.renderer.InvokeAsync(addParticipantRoleButton.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.participantRole1.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(ParticipantRole)));
});
}

[Test]
public async Task VerifyAddParticipantRoleClick()
{
var addParticipantRoleButton = this.renderer.FindComponents<DxButton>().First(x => x.Instance.Id == "addParticipantRoleButton");
await this.renderer.InvokeAsync(addParticipantRoleButton.Instance.Click.InvokeAsync);
var participantRolesGrid = this.renderer.FindComponent<DxGrid>();
await this.renderer.InvokeAsync(() => participantRolesGrid.Instance.SelectedDataItemChanged.InvokeAsync(new ParticipantRoleRowViewModel(this.participantRole1)));
Assert.That(this.renderer.Instance.IsOnEditMode, Is.EqualTo(true));

var grid = this.renderer.FindComponent<DxGrid>();
Assert.That(grid.Instance.IsEditing(), Is.EqualTo(true));
var participantRoleForm = this.renderer.FindComponent<ParticipantRoleForm>();
var participantRoleEditForm = participantRoleForm.FindComponent<EditForm>();
await participantRoleForm.InvokeAsync(participantRoleEditForm.Instance.OnValidSubmit.InvokeAsync);

await this.renderer.InvokeAsync(grid.Instance.EditModelSaving.InvokeAsync);
this.viewModel.Verify(x => x.CreateOrEditParticipantRole(true), Times.Once);
Assert.Multiple(() =>
{
this.viewModel.Verify(x => x.CreateOrEditParticipantRole(false), Times.Once);
Assert.That(this.viewModel.Object.CurrentThing, Is.InstanceOf(typeof(ParticipantRole)));
});

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

[Test]
public async Task VerifyRowClick()
public void VerifyOnInitialized()
{
Assert.That(this.renderer.Instance.IsOnEditMode, Is.EqualTo(false));

var firstRow = this.viewModel.Object.Rows.Items.First();
var grid = this.renderer.FindComponent<DxGrid>();
await this.renderer.InvokeAsync(async () => await grid.Instance.SelectedDataItemChanged.InvokeAsync(firstRow));

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

var details = this.renderer.FindComponent<ParticipantRoleDetails>();
await this.renderer.InvokeAsync(details.Instance.OnSubmit.InvokeAsync);
this.viewModel.Verify(x => x.CreateOrEditParticipantRole(false), Times.Once);

await this.renderer.InvokeAsync(details.Instance.OnCancel.InvokeAsync);
Assert.That(this.renderer.Instance.IsOnEditMode, Is.EqualTo(false));
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.participantRole1.Name));
this.viewModel.Verify(x => x.InitializeViewModel(), Times.Once);
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace COMETwebapp.Tests.ViewModels.Components.SiteDirectory.Roles
using COMET.Web.Common.Enumerations;
using COMET.Web.Common.Model;
using COMET.Web.Common.Services.SessionManagement;
using COMET.Web.Common.Test.Helpers;

using COMETwebapp.Services.ShowHideDeprecatedThingsService;
using COMETwebapp.ViewModels.Components.SiteDirectory.Roles;
Expand Down Expand Up @@ -177,8 +178,11 @@ public async Task VerifyParticipantRoleCreation()
{
this.viewModel.InitializeViewModel();
await this.viewModel.CreateOrEditParticipantRole(true);

this.sessionService.Verify(x => x.CreateOrUpdateThingsWithNotification(It.IsAny<SiteDirectory>(), It.IsAny<IReadOnlyCollection<Thing>>(), It.IsAny<NotificationDescription>()), Times.Once);

this.sessionService.Setup(x => x.CreateOrUpdateThingsWithNotification(It.IsAny<SiteDirectory>(), It.IsAny<IReadOnlyCollection<Thing>>(), It.IsAny<NotificationDescription>())).Throws(new Exception());
await this.viewModel.CreateOrEditParticipantRole(false);
this.loggerMock.Verify(LogLevel.Error, x => !string.IsNullOrWhiteSpace(x.ToString()), Times.Once());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
<!------------------------------------------------------------------------------
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
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 CDP4-COMET WEB Community Edition is distributed in the hope that it will be useful,
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
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/.
along with this program. If not, see <http://www.gnu.org/licenses/>.
------------------------------------------------------------------------------->
@inherits DisposableComponent
@inherits SelectedDataItemForm

<EditForm Context="editFormContext" Model="@(this.ViewModel.CurrentThing)" OnValidSubmit="@(this.OnValidSubmit)">
<FluentValidationValidator />
Expand Down Expand Up @@ -47,6 +52,7 @@ Copyright (c) 2023-2024 Starion Group S.A.
</DxFormLayoutGroup>

</DxFormLayout>
<FormButtons SaveButtonEnabled="@(true)"
OnCancel="@(() => this.OnCancel.InvokeAsync())"/>
<FormButtons SaveButtonEnabled="@(this.IsSaveButtonEnabled(editFormContext))"
OnCancel="@(this.OnCancel)"
ValidationMessages="@(this.MapOfValidationMessages.SelectMany(x => x.Value))"/>
</EditForm>
Loading

0 comments on commit 3c843f1

Please sign in to comment.