Skip to content

Commit

Permalink
Feat #613 [Engineering Model] Refactor Options page to be inline with…
Browse files Browse the repository at this point in the history
… Measurement Scale page (#653)
  • Loading branch information
joao4all authored Jun 3, 2024
1 parent dac2b88 commit 4cc4115
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 184 deletions.
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="OptionsTableTestFixture.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="OptionsTableTestFixture.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.EngineeringModel
{
using System.Linq;
using System.Threading.Tasks;

using Bunit;

using CDP4Common.EngineeringModelData;
Expand Down Expand Up @@ -63,24 +60,21 @@ public void SetUp()
this.context = new TestContext();
this.viewModel = new Mock<IOptionsTableViewModel>();

this.option = new Option()
this.option = new Option
{
Name = "A name",
ShortName = "AName",
Container = new Iteration(),
Container = new Iteration()
};

var rows = new SourceList<OptionRowViewModel>();
rows.Add(new OptionRowViewModel(this.option){ IsDefault = true});
rows.Add(new OptionRowViewModel(this.option) { IsDefault = true });
this.viewModel.Setup(x => x.Rows).Returns(rows);
this.viewModel.Setup(x => x.CurrentThing).Returns(new Option());

this.context.ConfigureDevExpressBlazor();

this.renderer = this.context.RenderComponent<OptionsTable>(parameters =>
{
parameters.Add(p => p.ViewModel, this.viewModel.Object);
});
this.renderer = this.context.RenderComponent<OptionsTable>(parameters => { parameters.Add(p => p.ViewModel, this.viewModel.Object); });
}

[TearDown]
Expand All @@ -91,23 +85,33 @@ public void Teardown()
}

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

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);
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 VerifyDeleteOption()
{
var deleteButton = this.renderer.FindComponents<DxButton>().First(x => x.Instance.Id == "deleteButton");
var grid = this.renderer.FindComponent<DxGrid>();
await this.renderer.InvokeAsync(() => grid.Instance.SelectedDataItemChanged.InvokeAsync(this.viewModel.Object.Rows.Items.First()));

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<OptionRowViewModel>()), Times.Once);
this.viewModel.VerifySet(x => x.IsOnDeletionMode = true, Times.Once);
this.viewModel.Setup(x => x.IsOnDeletionMode).Returns(true);

this.renderer.Render();
Expand All @@ -118,25 +122,6 @@ public async Task VerifyDeleteOption()
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()
{
Expand All @@ -161,5 +146,17 @@ public async Task VerifyEditOption()
await editForm.InvokeAsync(cancelButton.Instance.Click.InvokeAsync);
Assert.That(this.renderer.Instance.IsOnEditMode, Is.EqualTo(false));
}

[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);
});
}
}
}
5 changes: 4 additions & 1 deletion COMETwebapp/Components/EngineeringModel/OptionsForm.razor
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@ Copyright (c) 2023-2024 Starion Group S.A.
</DxFormLayout>
<FormButtons SaveButtonEnabled="@(this.IsSaveButtonEnabled(editFormContext))"
OnCancel="@(this.OnCancel)"
ValidationMessages="@(this.MapOfValidationMessages.SelectMany(x => x.Value))"/>
OnDelete="@(() => this.ViewModel.IsOnDeletionMode = true)"
DeleteButtonVisible="@(!this.ShouldCreate)"
ValidationMessages="@(this.MapOfValidationMessages.SelectMany(x => x.Value))"
IsLoading="@(this.ViewModel.IsLoading)" />
</EditForm>
99 changes: 37 additions & 62 deletions COMETwebapp/Components/EngineeringModel/OptionsTable.razor
Original file line number Diff line number Diff line change
Expand Up @@ -16,70 +16,45 @@ Copyright (c) 2023-2024 Starion Group S.A.
------------------------------------------------------------------------------->
@inherits SelectedDataItemBase<Option, OptionRowViewModel>

<LoadingComponent IsVisible="@(this.ViewModel.IsLoading)">
<div class="d-flex justify-content-between">
<DxGrid @ref="this.Grid"
Data="this.ViewModel.Rows.Items"
ColumnResizeMode="GridColumnResizeMode.ColumnsContainer"
ShowSearchBox="true"
SearchBoxNullText="Search for an option..."
AllowSelectRowByClick="true"
SelectionMode="GridSelectionMode.Single"
SelectedDataItemChanged="@((row) => this.OnSelectedDataItemChanged((OptionRowViewModel)row))"
PopupEditFormCssClass="pw-800"
PopupEditFormHeaderText="Option"
CustomizeElement="@(HighlightDefaultOptionRow)"
CustomizeEditModel="this.CustomizeEditThing"
EditMode="GridEditMode.PopupEditForm"
EditFormButtonsVisible="false"
PageSize="20"
PagerNavigationMode="PagerNavigationMode.Auto"
PageSizeSelectorVisible="true"
PageSizeSelectorItems="@(new int[] { 20, 35, 50 })"
PageSizeSelectorAllRowsItemVisible="true"
CssClass="height-fit-content">
<Columns>
<DxGridDataColumn FieldName="@nameof(OptionRowViewModel.Name)" MinWidth="150"/>
<DxGridDataColumn FieldName="@nameof(OptionRowViewModel.ShortName)" MinWidth="80" SearchEnabled="false"/>
<DxGridDataColumn FieldName="@nameof(OptionRowViewModel.IsDefault)" UnboundType="GridUnboundColumnType.Boolean" Visible="false" Caption="Is Default" MinWidth="80" SearchEnabled="false"/>
<DxGridCommandColumn Width="200px" EditButtonVisible="false">
<HeaderTemplate>
<DxButton Id="addOptionButton" Text="Add Option" IconCssClass="oi oi-plus" Click="() => this.Grid.StartEditNewRowAsync()"/>
</HeaderTemplate>
<CellDisplayTemplate>
@{
var row = (OptionRowViewModel)context.DataItem;
<div class="d-flex justify-content-between">
<DxGrid @ref="this.Grid"
Data="this.ViewModel.Rows.Items"
ColumnResizeMode="GridColumnResizeMode.ColumnsContainer"
ShowSearchBox="true"
SearchBoxNullText="Search for a measurement scale ..."
AllowSelectRowByClick="true"
SelectionMode="GridSelectionMode.Single"
SelectedDataItemChanged="@(row => this.OnSelectedDataItemChanged((OptionRowViewModel)row))"
EditFormButtonsVisible="false"
CustomizeElement="@(HighlightDefaultOptionRow)"
PageSize="20"
PagerNavigationMode="PagerNavigationMode.Auto"
PageSizeSelectorVisible="true"
PageSizeSelectorItems="@(new[] { 20, 35, 50 })"
PageSizeSelectorAllRowsItemVisible="true"
FilterMenuButtonDisplayMode="GridFilterMenuButtonDisplayMode.Always"
CssClass="height-fit-content">
<Columns>
<DxGridDataColumn FieldName="@nameof(OptionRowViewModel.Name)" MinWidth="150"/>
<DxGridDataColumn FieldName="@nameof(OptionRowViewModel.ShortName)" MinWidth="80" SearchEnabled="false"/>
<DxGridDataColumn FieldName="@nameof(OptionRowViewModel.IsDefault)" UnboundType="GridUnboundColumnType.Boolean" Visible="false" Caption="Is Default" MinWidth="80" SearchEnabled="false"/>
</Columns>
</DxGrid>

<DxButton Id="deleteButton"
Text="Delete"
Click="@(() => this.ViewModel.OnDeleteButtonClick(row))"
Enabled="@(row.IsAllowedToWrite)"/>
}
</CellDisplayTemplate>
</DxGridCommandColumn>
</Columns>
<DataItemDetailsComponent IsSelected="@(this.IsOnEditMode)"
OnButtonClick="@(this.OnAddThingClick)">

<EditFormTemplate Context="editFormTemplateContext">
<OptionsForm ViewModel="@this.ViewModel"
IsVisible="true"
ShouldCreate="true"
OnSaved="@(() => this.Grid.CancelEditAsync())"
OnCanceled="@(() => this.Grid.CancelEditAsync())"/>
</EditFormTemplate>
</DxGrid>

<DataItemDetailsComponent IsSelected="@this.IsOnEditMode">
<OptionsForm ViewModel="@this.ViewModel"
@bind-IsVisible="@this.IsOnEditMode"
ShouldCreate="false"/>
</DataItemDetailsComponent>
</div>
</LoadingComponent>
<OptionsForm ViewModel="@(this.ViewModel)"
@bind-IsVisible="@(this.IsOnEditMode)"
ShouldCreate="@(this.ShouldCreateThing)"
OnSaved="@(this.OnSaved)"/>
</DataItemDetailsComponent>
</div>

<DxPopup @bind-Visible="@this.ViewModel.IsOnDeletionMode" HeaderText="Please confirm" Width="auto" CloseOnOutsideClick="false">
@this.ViewModel.PopupDialog
<DxPopup @bind-Visible="@(this.ViewModel.IsOnDeletionMode)" HeaderText="Please confirm" Width="auto" CloseOnOutsideClick="false">
@(this.ViewModel.PopupDialog)
<div class="dxbl-grid-confirm-dialog-buttons">
<DxButton Text="Cancel " RenderStyle="ButtonRenderStyle.Success" Click="@this.ViewModel.OnCancelPopupButtonClick" />
<DxButton Text="Confirm" RenderStyle="ButtonRenderStyle.Danger" Click="@this.OnConfirmDelete" />
<DxButton Text="Cancel " RenderStyle="ButtonRenderStyle.Success" Click="@(this.ViewModel.OnCancelPopupButtonClick)"/>
<DxButton Text="Confirm" RenderStyle="ButtonRenderStyle.Danger" Click="@(this.OnDeletionConfirmed)"/>
</div>
</DxPopup>
</DxPopup>
Loading

0 comments on commit 4cc4115

Please sign in to comment.