From 20837c6716c773dd4d838b49d08bdb575b4f0960 Mon Sep 17 00:00:00 2001 From: Alexander van Delft Date: Mon, 16 Dec 2024 09:29:56 +0100 Subject: [PATCH] Unit Test selected item --- .../CardView/CardViewTestFixture.cs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/COMET.Web.Common.Tests/Components/CardView/CardViewTestFixture.cs b/COMET.Web.Common.Tests/Components/CardView/CardViewTestFixture.cs index c02b042f..13c2957e 100644 --- a/COMET.Web.Common.Tests/Components/CardView/CardViewTestFixture.cs +++ b/COMET.Web.Common.Tests/Components/CardView/CardViewTestFixture.cs @@ -32,6 +32,7 @@ namespace COMET.Web.Common.Tests.Components.CardView using Microsoft.AspNetCore.Components; using Microsoft.Extensions.DependencyInjection; + using Microsoft.VisualStudio.TestPlatform.Common.Utilities; using NUnit.Framework; @@ -278,6 +279,39 @@ public void VerifyComponentRerenders() }); } + [Test] + public void VerifySelectComponent() + { + var component = this.context.RenderComponent>(parameters => + { + parameters + .Add(p => p.Items, this.testClasses) + .Add(p => p.ItemSize, 150) + .Add(p => p.ItemTemplate, NormalTemplate()); + }); + + var cardView = component; + + Assert.Multiple(() => + { + Assert.That(cardView.Instance.AllowSort, Is.True); + Assert.That(cardView.Instance.AllowSearch, Is.True); + Assert.That(cardView.Instance.ItemSize, Is.EqualTo(150)); + Assert.That(cardView.Instance.SearchFields, Is.EquivalentTo(new[] { "Id", "Name" })); + Assert.That(cardView.Instance.SortFields, Is.EquivalentTo(new[] { string.Empty, "Id", "Name" })); + }); + + var firstCardField = component.Find(".card"); + firstCardField.Click(); + + var selectedCardField = component.Find(".selected"); + + Assert.Multiple(() => + { + Assert.That(firstCardField.InnerHtml, Is.EqualTo(selectedCardField.InnerHtml)); + }); + } + /// /// Configure the for DevExpress ///