From 0161cb8139914304168f4de020ac52c2956ff5ae Mon Sep 17 00:00:00 2001 From: Joao Rua Date: Wed, 17 Jul 2024 14:13:53 +0100 Subject: [PATCH] unit tests --- COMETwebapp.Tests/Pages/TabsTestFixture.cs | 36 +++++++++++++++++-- .../Components/Tabs/TabComponent.razor | 6 ++-- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/COMETwebapp.Tests/Pages/TabsTestFixture.cs b/COMETwebapp.Tests/Pages/TabsTestFixture.cs index 57afe13e..14db8dee 100644 --- a/COMETwebapp.Tests/Pages/TabsTestFixture.cs +++ b/COMETwebapp.Tests/Pages/TabsTestFixture.cs @@ -47,6 +47,8 @@ namespace COMETwebapp.Tests.Pages using COMETwebapp.ViewModels.Components.EngineeringModel.Rows; using COMETwebapp.ViewModels.Pages; + using DevExpress.Blazor; + using DynamicData; using Microsoft.Extensions.DependencyInjection; @@ -91,12 +93,16 @@ public void Setup() IterationSetup = new IterationSetup { Container = new EngineeringModelSetup() - } + }, + Container = new EngineeringModel() }; var configuration = new Mock(); configuration.Setup(x => x.ServerConfiguration).Returns(new ServerConfiguration()); + var sessionService = new Mock(); + sessionService.Setup(x => x.GetDomainOfExpertise(It.IsAny())).Returns(new DomainOfExpertise()); + this.context.ConfigureDevExpressBlazor(); this.context.Services.AddSingleton(this.viewModel.Object); this.context.Services.AddSingleton(this.engineeringModelBodyViewModel.Object); @@ -104,7 +110,7 @@ public void Setup() this.context.Services.AddSingleton(new Mock().Object); this.context.Services.AddSingleton(new Mock().Object); this.context.Services.AddSingleton(new Mock().Object); - this.context.Services.AddSingleton(new Mock().Object); + this.context.Services.AddSingleton(sessionService.Object); this.renderer = this.context.RenderComponent(); } @@ -142,6 +148,32 @@ public async Task VerifyTabComponents() Assert.That(this.renderer.Instance.IsOpenTabVisible, Is.True); } + [Test] + public async Task VerifyTabCustomButton() + { + var openTabs = new SourceList(); + var tabToOpen = new TabbedApplicationInformation(this.engineeringModelBodyViewModel.Object, typeof(EngineeringModelBody), this.iteration); + openTabs.Add(tabToOpen); + this.viewModel.Setup(x => x.OpenTabs).Returns(openTabs); + this.viewModel.Setup(x => x.CurrentTab).Returns(tabToOpen); + this.renderer.Render(); + + var tabCustomButton = this.renderer.FindComponents().First(x => x.Instance.Id == "tab-custom-option-button"); + await this.renderer.InvokeAsync(tabCustomButton.Instance.Click.InvokeAsync); + Assert.That(this.renderer.Instance.IsOpenTabVisible, Is.True); + + var openTabComponent = this.renderer.FindComponent(); + await this.renderer.InvokeAsync(openTabComponent.Instance.OnCancel.Invoke); + Assert.That(this.renderer.Instance.IsOpenTabVisible, Is.False); + + tabToOpen = new TabbedApplicationInformation(this.engineeringModelBodyViewModel.Object, typeof(EngineeringModelBody), null); + openTabs.ReplaceAt(0, tabToOpen); + this.renderer.Render(); + tabCustomButton = this.renderer.FindComponents().First(x => x.Instance.Id == "tab-custom-option-button"); + await this.renderer.InvokeAsync(tabCustomButton.Instance.Click.InvokeAsync); + Assert.That(this.renderer.Instance.IsOpenTabVisible, Is.False); + } + [Test] public void VerifyTabsPage() { diff --git a/COMETwebapp/Components/Tabs/TabComponent.razor b/COMETwebapp/Components/Tabs/TabComponent.razor index 6b583e6c..c0b230b3 100644 --- a/COMETwebapp/Components/Tabs/TabComponent.razor +++ b/COMETwebapp/Components/Tabs/TabComponent.razor @@ -30,7 +30,8 @@ { + CssClass="ps-1 pe-0" + Id="tab-custom-option-button"> @@ -38,7 +39,8 @@ + CssClass="px-1" + Id="tab-button">