From 1624816bae40a03b67e176187db56eb8c5271e23 Mon Sep 17 00:00:00 2001 From: jaimeatrhea Date: Thu, 21 Sep 2023 10:32:11 +0200 Subject: [PATCH] Add common tests --- .../BookEditor/InputEditorTestFixture.cs | 122 ++++++++++++++++++ .../Components/BookEditor/InputEditor.razor | 24 ++-- .../BookEditor/InputEditor.razor.cs | 1 - 3 files changed, 136 insertions(+), 11 deletions(-) create mode 100644 COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs diff --git a/COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs b/COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs new file mode 100644 index 00000000..bc922220 --- /dev/null +++ b/COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs @@ -0,0 +1,122 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA Web Application implementation of ECSS-E-TM-10-25 Annex A and Annex C. +// +// The COMET WEB Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Affero General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The COMET WEB Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Tests.Components.BookEditor +{ + using Bunit; + + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; + + using COMET.Web.Common.Components.BookEditor; + using COMET.Web.Common.Test.Helpers; + using COMET.Web.Common.ViewModels.Components.BookEditor; + + using DevExpress.Blazor; + + using DynamicData; + + using Microsoft.AspNetCore.Components; + + using Moq; + + using NUnit.Framework; + + using TestContext = Bunit.TestContext; + + [TestFixture] + public class InputEditorTestFixture + { + private TestContext context; + private IRenderedComponent> component; + private Book book; + private List activeDomains; + private List availableCategories; + + [SetUp] + public void Setup() + { + this.context = new TestContext(); + this.context.ConfigureDevExpressBlazor(); + + this.activeDomains = new List + { + new() { Name = "Sys" } + }; + + this.availableCategories = new List + { + new() { Name = "Category" } + }; + + this.book = new Book() + { + Name = "Book Example", + ShortName = "bookExample", + Owner = this.activeDomains.First(), + Category = this.availableCategories + }; + + this.component = this.context.RenderComponent>(parameters => + { + parameters.Add(p => p.Item, this.book); + parameters.Add(p => p.ActiveDomains, this.activeDomains); + parameters.Add(p => p.AvailableCategories, this.availableCategories); + }); + } + + [Test] + public void VerifyComponent() + { + var dxtabs = this.component.FindComponent(); + + dxtabs.Instance.ActiveTabIndex = 0; + + var textboxes = this.component.FindComponents(); + var combobox = this.component.FindComponent>(); + + var nameTextbox = textboxes[0]; + var shortNameTextbox = textboxes[1]; + + Assert.Multiple(() => + { + Assert.That(nameTextbox.Instance.Text, Is.EqualTo("Book Example")); + Assert.That(shortNameTextbox.Instance.Text, Is.EqualTo("bookExample")); + Assert.That(combobox.Instance.Value, Is.EqualTo(this.activeDomains.First())); + }); + + dxtabs.Instance.ActiveTabIndex = 1; + this.component.Render(); + + var listbox = this.component.FindComponent>(); + + Assert.Multiple(() => + { + Assert.That(listbox.Instance.Data, Is.EquivalentTo(this.availableCategories)); + Assert.That(listbox.Instance.Values, Is.EquivalentTo(this.availableCategories)); + }); + } + } +} + diff --git a/COMET.Web.Common/Components/BookEditor/InputEditor.razor b/COMET.Web.Common/Components/BookEditor/InputEditor.razor index 8ae469bf..d010ebf6 100644 --- a/COMET.Web.Common/Components/BookEditor/InputEditor.razor +++ b/COMET.Web.Common/Components/BookEditor/InputEditor.razor @@ -73,16 +73,20 @@
- - + @if (this.Item is ICategorizableThing categorizableThing) + { + + + }
diff --git a/COMET.Web.Common/Components/BookEditor/InputEditor.razor.cs b/COMET.Web.Common/Components/BookEditor/InputEditor.razor.cs index ae083d22..94713e68 100644 --- a/COMET.Web.Common/Components/BookEditor/InputEditor.razor.cs +++ b/COMET.Web.Common/Components/BookEditor/InputEditor.razor.cs @@ -25,7 +25,6 @@ namespace COMET.Web.Common.Components.BookEditor { - using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.SiteDirectoryData;