Skip to content

Commit

Permalink
unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joao4all committed Jul 17, 2024
1 parent 5512602 commit 0161cb8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
36 changes: 34 additions & 2 deletions COMETwebapp.Tests/Pages/TabsTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -91,20 +93,24 @@ public void Setup()
IterationSetup = new IterationSetup
{
Container = new EngineeringModelSetup()
}
},
Container = new EngineeringModel()
};

var configuration = new Mock<IConfigurationService>();
configuration.Setup(x => x.ServerConfiguration).Returns(new ServerConfiguration());

var sessionService = new Mock<ISessionService>();
sessionService.Setup(x => x.GetDomainOfExpertise(It.IsAny<Iteration>())).Returns(new DomainOfExpertise());

this.context.ConfigureDevExpressBlazor();
this.context.Services.AddSingleton(this.viewModel.Object);
this.context.Services.AddSingleton(this.engineeringModelBodyViewModel.Object);
this.context.Services.AddSingleton(configuration.Object);
this.context.Services.AddSingleton(new Mock<IOpenTabViewModel>().Object);
this.context.Services.AddSingleton(new Mock<IOpenModelViewModel>().Object);
this.context.Services.AddSingleton(new Mock<IStringTableService>().Object);
this.context.Services.AddSingleton(new Mock<ISessionService>().Object);
this.context.Services.AddSingleton(sessionService.Object);

this.renderer = this.context.RenderComponent<Tabs>();
}
Expand Down Expand Up @@ -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<TabbedApplicationInformation>();
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<DxButton>().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<OpenTab>();
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<DxButton>().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()
{
Expand Down
6 changes: 4 additions & 2 deletions COMETwebapp/Components/Tabs/TabComponent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@
{
<DxButton RenderStyle="ButtonRenderStyle.None"
Click="@(() => this.OnCustomOptionIconClick?.Invoke())"
CssClass="ps-1 pe-0">
CssClass="ps-1 pe-0"
Id="tab-custom-option-button">
<DynamicComponent Type="@(this.CustomOptionIcon)"
Parameters="IconConfiguration"/>
</DxButton>
}

<DxButton RenderStyle="ButtonRenderStyle.None"
Click="@(() => this.OnIconClick?.Invoke())"
CssClass="px-1">
CssClass="px-1"
Id="tab-button">
<DynamicComponent Type="@(this.Icon)"
Parameters="IconConfiguration"/>
</DxButton>
Expand Down

0 comments on commit 0161cb8

Please sign in to comment.