Skip to content

Commit

Permalink
tests for doe form
Browse files Browse the repository at this point in the history
  • Loading branch information
joao4all committed Apr 18, 2024
1 parent f1d100b commit 5e5c505
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace COMETwebapp.Tests.Components.SiteDirectory

using DynamicData;

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

using Moq;
Expand Down Expand Up @@ -142,16 +143,21 @@ public async Task VerifyAddingOrEditingDomainOfExpertise()

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

var editDomainOfExpertiseButton = renderer.FindComponents<DxButton>().First(x => x.Instance.Id == "editDomainOfExpertiseButton");
await renderer.InvokeAsync(editDomainOfExpertiseButton.Instance.Click.InvokeAsync);
var domainsGrid = renderer.FindComponent<DxGrid>();
await renderer.InvokeAsync(() => domainsGrid.Instance.SelectedDataItemChanged.InvokeAsync(new DomainOfExpertiseRowViewModel(this.domainOfExpertise1)));
Assert.That(renderer.Instance.IsOnEditMode, Is.EqualTo(true));

var domainsForm = renderer.FindComponents<DomainsOfExpertiseForm>()[1];
var domainsEditForm = domainsForm.FindComponent<EditForm>();
await domainsForm.InvokeAsync(domainsEditForm.Instance.OnValidSubmit.InvokeAsync);

Assert.Multiple(() =>
{
Assert.That(renderer.Instance.ShouldCreateThing, Is.EqualTo(false));
this.viewModel.Verify(x => x.CreateOrEditDomainOfExpertise(false), Times.Once);
Assert.That(this.viewModel.Object.Thing, Is.InstanceOf(typeof(DomainOfExpertise)));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ Copyright (c) 2023-2024 RHEA System S.A.

<DataItemDetailsComponent IsSelected="@this.IsOnEditMode">
<DomainsOfExpertiseForm ViewModel="@this.ViewModel"
@bind-IsVisible="@this.IsOnEditMode"
ShouldCreate="false"/>
@bind-IsVisible="@this.IsOnEditMode"
ShouldCreate="false"/>
</DataItemDetailsComponent>

</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,8 @@ protected override void CustomizeEditThing(GridCustomizeEditModelEventArgs e)

var dataItem = (DomainOfExpertiseRowViewModel)e.DataItem;
this.ShouldCreateThing = e.IsNew;

if (dataItem == null)
{
this.ViewModel.Thing = new DomainOfExpertise();
e.EditModel = this.ViewModel.Thing;
return;
}

e.EditModel = dataItem;
this.ViewModel.Thing = dataItem.Thing.Clone(true);
this.ViewModel.Thing = dataItem == null ? new DomainOfExpertise() : dataItem.Thing.Clone(true);
e.EditModel = this.ViewModel.Thing;
}

/// <summary>
Expand Down

0 comments on commit 5e5c505

Please sign in to comment.