Skip to content

Commit

Permalink
Add common tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimeatstariongroup committed Sep 21, 2023
1 parent 52d7977 commit 1624816
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 11 deletions.
122 changes: 122 additions & 0 deletions COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="InputEditorTestFixture.cs" company="RHEA System S.A.">
// 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 <http://www.gnu.org/licenses/>.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

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<InputEditor<Book>> component;
private Book book;
private List<DomainOfExpertise> activeDomains;
private List<Category> availableCategories;

[SetUp]
public void Setup()
{
this.context = new TestContext();
this.context.ConfigureDevExpressBlazor();

this.activeDomains = new List<DomainOfExpertise>
{
new() { Name = "Sys" }
};

this.availableCategories = new List<Category>
{
new() { Name = "Category" }
};

this.book = new Book()
{
Name = "Book Example",
ShortName = "bookExample",
Owner = this.activeDomains.First(),
Category = this.availableCategories
};

this.component = this.context.RenderComponent<InputEditor<Book>>(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>();

dxtabs.Instance.ActiveTabIndex = 0;

Check warning on line 94 in COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Component parameter 'ActiveTabIndex' should not be set outside of its component.

Check warning on line 94 in COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Component parameter 'ActiveTabIndex' should not be set outside of its component.

Check warning on line 94 in COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Component parameter 'ActiveTabIndex' should not be set outside of its component.

Check warning on line 94 in COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Component parameter 'ActiveTabIndex' should not be set outside of its component.

Check warning on line 94 in COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs

View workflow job for this annotation

GitHub Actions / Build

Component parameter 'ActiveTabIndex' should not be set outside of its component.

var textboxes = this.component.FindComponents<DxTextBox>();
var combobox = this.component.FindComponent<DxComboBox<DomainOfExpertise, DomainOfExpertise>>();

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;

Check warning on line 109 in COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Component parameter 'ActiveTabIndex' should not be set outside of its component.

Check warning on line 109 in COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Component parameter 'ActiveTabIndex' should not be set outside of its component.

Check warning on line 109 in COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Component parameter 'ActiveTabIndex' should not be set outside of its component.

Check warning on line 109 in COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Component parameter 'ActiveTabIndex' should not be set outside of its component.

Check warning on line 109 in COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs

View workflow job for this annotation

GitHub Actions / Build

Component parameter 'ActiveTabIndex' should not be set outside of its component.
this.component.Render();

var listbox = this.component.FindComponent<DxListBox<Category, Category>>();

Assert.Multiple(() =>
{
Assert.That(listbox.Instance.Data, Is.EquivalentTo(this.availableCategories));
Assert.That(listbox.Instance.Values, Is.EquivalentTo(this.availableCategories));
});
}
}
}

24 changes: 14 additions & 10 deletions COMET.Web.Common/Components/BookEditor/InputEditor.razor
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,20 @@
</DxTabPage>
<DxTabPage Text="Category">
<div class="tab-content">
<DxListBox Data="@this.AvailableCategories"
TData="Category"
TValue="Category"
ValuesChanged="@this.OnCategoryChange"
TextFieldName="@nameof(Category.Name)"
SelectionMode="ListBoxSelectionMode.Multiple"
ShowCheckboxes="true"
CssClass="w-auto mt-1 me-1 flex-grow-1 chi-220"
style="flex-basis: 240px">
</DxListBox>
@if (this.Item is ICategorizableThing categorizableThing)
{
<DxListBox Values="@categorizableThing.Category"
Data="@this.AvailableCategories"
TData="Category"
TValue="Category"
ValuesChanged="@this.OnCategoryChange"
TextFieldName="@nameof(Category.Name)"
SelectionMode="ListBoxSelectionMode.Multiple"
ShowCheckboxes="true"
CssClass="w-auto mt-1 me-1 flex-grow-1 chi-220"
style="flex-basis: 240px">
</DxListBox>
}
</div>
</DxTabPage>
</DxTabs>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

namespace COMET.Web.Common.Components.BookEditor
{
using CDP4Common.CommonData;
using CDP4Common.EngineeringModelData;
using CDP4Common.SiteDirectoryData;

Expand Down

0 comments on commit 1624816

Please sign in to comment.