Skip to content

Commit

Permalink
Feat #610 [Server Administration] Refactor Person Roles page to be in…
Browse files Browse the repository at this point in the history
…line with Measurement Scale page (#651)

This commit also removes the loading component from person/participant role pages
  • Loading branch information
joao4all authored May 31, 2024
1 parent 3c843f1 commit 732dba8
Show file tree
Hide file tree
Showing 12 changed files with 285 additions and 432 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="PersonRolesTableTestFixture.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="PersonRolesTableTestFixture.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<IPersonRolesTableViewModel>();

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

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

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

[Test]
public async Task VerifyAddPersonRoleClick()
{
var addPersonRoleButton = this.renderer.FindComponents<DxButton>().First(x => x.Instance.Id == "addPersonRoleButton");
await this.renderer.InvokeAsync(addPersonRoleButton.Instance.Click.InvokeAsync);
var personRolesGrid = this.renderer.FindComponent<DxGrid>();
await this.renderer.InvokeAsync(() => personRolesGrid.Instance.SelectedDataItemChanged.InvokeAsync(new PersonRoleRowViewModel(this.personRole)));
Assert.That(this.renderer.Instance.IsOnEditMode, Is.EqualTo(true));

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

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

var form = this.renderer.FindComponent<DxGrid>();
await this.renderer.InvokeAsync(form.Instance.EditModelSaving.InvokeAsync);
this.viewModel.Verify(x => x.CreateOrEditPersonRole(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<PersonRoleDetails>();
await this.renderer.InvokeAsync(details.Instance.OnSubmit.InvokeAsync);
this.viewModel.Verify(x => x.CreateOrEditPersonRole(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.personRole.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.CreateOrEditPersonRole(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.CreateOrEditPersonRole(false);
this.loggerMock.Verify(LogLevel.Error, x => !string.IsNullOrWhiteSpace(x.ToString()), Times.Once());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ Copyright (c) 2024 Starion Group S.A.
}

</DxFormLayoutGroup>

</DxFormLayout>
<FormButtons SaveButtonEnabled="@(this.IsSaveButtonEnabled(editFormContext))"
OnCancel="@(this.OnCancel)"
ValidationMessages="@(this.MapOfValidationMessages.SelectMany(x => x.Value))"/>
ValidationMessages="@(this.MapOfValidationMessages.SelectMany(x => x.Value))"
IsLoading="@(this.ViewModel.IsLoading)"/>
</EditForm>
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ParticipantRoleDetails.razor.cs" company="Starion Group S.A.">
// Copyright (c) 2023-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 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="ParticipantRoleForm.razor.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.Components.SiteDirectory.Roles
{
Expand All @@ -32,14 +32,15 @@ namespace COMETwebapp.Components.SiteDirectory.Roles
using Microsoft.AspNetCore.Components;

/// <summary>
/// Support class for the <see cref="ParticipantRoleForm"/>
/// Support class for the <see cref="ParticipantRoleForm" />
/// </summary>
public partial class ParticipantRoleForm : SelectedDataItemForm
{
/// <summary>
/// The <see cref="IParticipantRolesTableViewModel" /> for this component
/// </summary>
[Parameter, Required]
[Parameter]
[Required]
public IParticipantRolesTableViewModel ViewModel { get; set; }

/// <summary>
Expand Down
Loading

0 comments on commit 732dba8

Please sign in to comment.