From 5e5c505f87ebd2dc321cc8bb742d6c0f75f73506 Mon Sep 17 00:00:00 2001 From: Joao Rua Date: Thu, 18 Apr 2024 15:47:35 +0100 Subject: [PATCH] tests for doe form --- .../DomainsOfExpertiseTableTestFixture.cs | 14 ++++++++++---- .../SiteDirectory/DomainsOfExpertiseTable.razor | 4 ++-- .../SiteDirectory/DomainsOfExpertiseTable.razor.cs | 12 ++---------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/COMETwebapp.Tests/Components/SiteDirectory/DomainsOfExpertiseTableTestFixture.cs b/COMETwebapp.Tests/Components/SiteDirectory/DomainsOfExpertiseTableTestFixture.cs index f01eacc1..a9d7c979 100644 --- a/COMETwebapp.Tests/Components/SiteDirectory/DomainsOfExpertiseTableTestFixture.cs +++ b/COMETwebapp.Tests/Components/SiteDirectory/DomainsOfExpertiseTableTestFixture.cs @@ -42,6 +42,7 @@ namespace COMETwebapp.Tests.Components.SiteDirectory using DynamicData; + using Microsoft.AspNetCore.Components.Forms; using Microsoft.Extensions.DependencyInjection; using Moq; @@ -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().First(x => x.Instance.Id == "editDomainOfExpertiseButton"); - await renderer.InvokeAsync(editDomainOfExpertiseButton.Instance.Click.InvokeAsync); + var domainsGrid = renderer.FindComponent(); + await renderer.InvokeAsync(() => domainsGrid.Instance.SelectedDataItemChanged.InvokeAsync(new DomainOfExpertiseRowViewModel(this.domainOfExpertise1))); + Assert.That(renderer.Instance.IsOnEditMode, Is.EqualTo(true)); + + var domainsForm = renderer.FindComponents()[1]; + var domainsEditForm = domainsForm.FindComponent(); + 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))); }); diff --git a/COMETwebapp/Components/SiteDirectory/DomainsOfExpertiseTable.razor b/COMETwebapp/Components/SiteDirectory/DomainsOfExpertiseTable.razor index 797f9be2..661b78b1 100644 --- a/COMETwebapp/Components/SiteDirectory/DomainsOfExpertiseTable.razor +++ b/COMETwebapp/Components/SiteDirectory/DomainsOfExpertiseTable.razor @@ -72,8 +72,8 @@ Copyright (c) 2023-2024 RHEA System S.A. + @bind-IsVisible="@this.IsOnEditMode" + ShouldCreate="false"/> diff --git a/COMETwebapp/Components/SiteDirectory/DomainsOfExpertiseTable.razor.cs b/COMETwebapp/Components/SiteDirectory/DomainsOfExpertiseTable.razor.cs index 48bd699e..c050b2fd 100644 --- a/COMETwebapp/Components/SiteDirectory/DomainsOfExpertiseTable.razor.cs +++ b/COMETwebapp/Components/SiteDirectory/DomainsOfExpertiseTable.razor.cs @@ -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; } ///