Skip to content

Commit

Permalink
Add some more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimeatstariongroup committed Sep 21, 2023
1 parent 1624816 commit e4818cd
Show file tree
Hide file tree
Showing 12 changed files with 242 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,9 @@ namespace COMET.Web.Common.Tests.Components.BookEditor

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;
Expand Down Expand Up @@ -89,9 +82,8 @@ public void Setup()
[Test]
public void VerifyComponent()
{
var dxtabs = this.component.FindComponent<DxTabs>();

dxtabs.Instance.ActiveTabIndex = 0;
var basicTab = this.component.Find(".basic-tab");
basicTab.Click();

var textboxes = this.component.FindComponents<DxTextBox>();
var combobox = this.component.FindComponent<DxComboBox<DomainOfExpertise, DomainOfExpertise>>();
Expand All @@ -106,7 +98,9 @@ public void VerifyComponent()
Assert.That(combobox.Instance.Value, Is.EqualTo(this.activeDomains.First()));
});

dxtabs.Instance.ActiveTabIndex = 1;
var categoryTab = this.component.Find(".category-tab");
categoryTab.Click();

this.component.Render();

var listbox = this.component.FindComponent<DxListBox<Category, Category>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,5 +291,19 @@ public void VerifyUpdateThings()
thingsToUpdate.Add(clone);
Assert.DoesNotThrow(() => this.sessionService.UpdateThings(this.iteration, thingsToUpdate));
}

[Test]
public void VerifyDeleteThings()
{
this.sessionService.IsSessionOpen = true;

var element = new ElementDefinition
{
Name = "Battery",
Owner = this.sessionService.GetDomainOfExpertise(this.iteration)
};

Assert.DoesNotThrow(() => this.sessionService.DeleteThing(this.iteration, element.Clone(false)));
}
}
}
114 changes: 114 additions & 0 deletions COMET.Web.Common.Tests/Services/ValidationServiceTestFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ValidationServiceTestFixture.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.Services
{
using COMET.Web.Common.Services;

using NUnit.Framework;

[TestFixture]
public class ValidationServiceTestFixture
{
[Test]
public void VerifyValidateProperty()
{
Assert.Multiple(() =>
{
Assert.That(ValidationService.ValidateProperty("SelectedSource", ""), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("SelectedSource", "valid source"), Is.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("ShortName", "invalid ShortName"), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("ShortName", "validShortName"), Is.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("RDLShortName", ""), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("RDLShortName", "validRDL"), Is.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("RDLName", " invalidRDLName"), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("RDLName", "validRDLName"), Is.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("NativeName", "1nativeName1"), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("NativeName", "nativeName"), Is.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("FileRevisionName", " invalid FileRevisionName"), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("FileRevisionName", "FileRevisionName"), Is.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("Name", "invalidName)"), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("Name", "validName"), Is.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("EmailAddress", "invalidemail.com"), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("EmailAddress", "[email protected]"), Is.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("TelephoneNumber", ""), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("TelephoneNumber", "000 000 000"), Is.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("UserPreference", ""), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("UserPreference", "userPref"), Is.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("LanguageCode", ""), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("LanguageCode", "language code"), Is.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("Content", ""), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("Content", "content"), Is.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("Password", ""), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("Password", "password"), Is.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("ForwardRelationshipName", ""), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("ForwardRelationshipName", "valid"), Is.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("InverseRelationshipName", ""), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("InverseRelationshipName", "valid"), Is.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("Exponent", ""), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("Exponent", "valid"), Is.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("Symbol", ""), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("Symbol", "valid"), Is.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("ScaleValueDefinition", ""), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("ScaleValueDefinition", "valid"), Is.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("ScaleReferenceQuantityValue", ""), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("ScaleReferenceQuantityValue", "valid"), Is.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("Factor", ""), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("Factor", "valid"), Is.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("Modulus", ""), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("Modulus", "valid"), Is.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("Extension", "invalidExtension"), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("Extension", "valid1"), Is.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("FileTypeName", "invented"), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("FileTypeName", "audio/1"), Is.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("Value", ""), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("Value", "valid"), Is.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("ModelSetupShortName", "invalid!"), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("ModelSetupShortName", "valid"), Is.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("PersonShortName", ""), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("PersonShortName", "valid"), Is.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("PersonGivenName", ""), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("PersonGivenName", "valid"), Is.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("PersonSurname", ""), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("PersonSurname", "valid"), Is.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("RequirementShortName", ""), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("RequirementShortName", "valid"), Is.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("ModelSetupName", ""), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("ModelSetupName", "valid"), Is.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("ConversionFactor", ""), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("ConversionFactor", "valid"), Is.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("Description", ""), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("Description", "valid"), Is.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("Title", ""), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("Title", "valid"), Is.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("EnumerationValueDefinitionShortName", ""), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("EnumerationValueDefinitionShortName", "valid"), Is.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("EnumerationValueDefinitionName", ""), Is.Not.Null.Or.Empty);
Assert.That(ValidationService.ValidateProperty("EnumerationValueDefinitionName", "valid"), Is.Null.Or.Empty);

});
}
}
}

26 changes: 6 additions & 20 deletions COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,43 +71,29 @@ private async Task OnConfirmClick()
if (this.ViewModel.Item is INamedThing namedThing)
{
var error = ValidationService.ValidateProperty(nameof(namedThing.Name), namedThing.Name);

if (!string.IsNullOrEmpty(error))
{
validationErrors.Add(error);
}
validationErrors.Add(error);
}

Check warning on line 75 in COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs

View check run for this annotation

Codecov / codecov/patch

COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs#L72-L75

Added lines #L72 - L75 were not covered by tests

if (this.ViewModel.Item is IShortNamedThing shortNamedThing)
{
var error = ValidationService.ValidateProperty(nameof(shortNamedThing.ShortName), shortNamedThing.ShortName);

if (!string.IsNullOrEmpty(error))
{
validationErrors.Add(error);
}
validationErrors.Add(error);
}

Check warning on line 81 in COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs

View check run for this annotation

Codecov / codecov/patch

COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs#L78-L81

Added lines #L78 - L81 were not covered by tests

if (this.ViewModel.Item is IOwnedThing ownedThing)
{

Check warning on line 84 in COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs

View check run for this annotation

Codecov / codecov/patch

COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs#L84

Added line #L84 was not covered by tests
var error = ownedThing.Owner == null ? "The thing must be owned by a DoE" : string.Empty;

if (!string.IsNullOrEmpty(error))
{
validationErrors.Add(error);
}
validationErrors.Add(error);
}

Check warning on line 87 in COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs

View check run for this annotation

Codecov / codecov/patch

COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs#L86-L87

Added lines #L86 - L87 were not covered by tests

if (this.ViewModel.Item is TextualNote textualNote)
{

Check warning on line 90 in COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs

View check run for this annotation

Codecov / codecov/patch

COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs#L90

Added line #L90 was not covered by tests
var error = string.IsNullOrEmpty(textualNote.Content)? "The textual note must contain a content" : string.Empty;

if (!string.IsNullOrEmpty(error))
{
validationErrors.Add(error);
}
validationErrors.Add(error);
}

Check warning on line 93 in COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs

View check run for this annotation

Codecov / codecov/patch

COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs#L92-L93

Added lines #L92 - L93 were not covered by tests

validationErrors = validationErrors.Where(x => !string.IsNullOrEmpty(x)).ToList();

Check warning on line 95 in COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs

View check run for this annotation

Codecov / codecov/patch

COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs#L95

Added line #L95 was not covered by tests

this.ViewModel.ValidationErrors.Edit(inner =>
{
inner.Clear();
Expand Down
4 changes: 2 additions & 2 deletions COMET.Web.Common/Components/BookEditor/InputEditor.razor
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

<div>
<DxTabs>
<DxTabPage Text="Basic">
<DxTabPage Text="Basic" CssClass="basic-tab">
<div class="tab-content">
@if (this.Item is INamedThing namedThing)
{
Expand Down Expand Up @@ -71,7 +71,7 @@
}

Check warning on line 71 in COMET.Web.Common/Components/BookEditor/InputEditor.razor

View check run for this annotation

Codecov / codecov/patch

COMET.Web.Common/Components/BookEditor/InputEditor.razor#L71

Added line #L71 was not covered by tests
</div>
</DxTabPage>
<DxTabPage Text="Category">
<DxTabPage Text="Category" CssClass="category-tab">
<div class="tab-content">
@if (this.Item is ICategorizableThing categorizableThing)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public partial class InputEditor<TItem>
/// <summary>
/// Handler for when the selected categories changed
/// </summary>
/// <param name="categories"></param>
/// <param name="categories">the changed categories</param>
private void OnCategoryChange(IEnumerable<Category> categories)
{

Check warning on line 61 in COMET.Web.Common/Components/BookEditor/InputEditor.razor.cs

View check run for this annotation

Codecov / codecov/patch

COMET.Web.Common/Components/BookEditor/InputEditor.razor.cs#L61

Added line #L61 was not covered by tests
if (this.Item is ICategorizableThing categorizableThing)
Expand Down
5 changes: 1 addition & 4 deletions COMET.Web.Common/wwwroot/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,6 @@
margin: 4%;
}

.editor-row {
display: flex;
}

.content-scale {
margin-top: auto;
margin-bottom: auto;
Expand Down Expand Up @@ -514,6 +510,7 @@
}

.editor-row {
display: flex;
align-items: center;
justify-content: space-between;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="DomDataServiceTestFixture.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 COMETwebapp.Tests.Services.Interoperability
{
using CDP4Common.ReportingData;

using COMETwebapp.Components.BookEditor;
using COMETwebapp.Services.Interoperability;

using Microsoft.JSInterop;

using Moq;

using NUnit.Framework;

[TestFixture]
public class DomDataServiceTestFixture
{
private Mock<IDomDataService> service;

[SetUp]
public void Setup()
{
this.service = new Mock<IDomDataService>();

this.service.Setup(x => x.GetElementSizeAndPosition(It.IsAny<int>(), It.IsAny<string>(), It.IsAny<bool>()))
.ReturnsAsync(new float[] { 1, 2, 3, 4 });
}

[Test]
public async Task VerifyMethods()
{
var dotnet = DotNetObjectReference.Create(new BookEditorColumn<Book>());

Assert.Multiple(() =>
{
Assert.That(() => this.service.Object.LoadDotNetHelper(dotnet), Throws.Nothing);
Assert.That(async () => await this.service.Object.GetElementSizeAndPosition(0, "node", true), Throws.Nothing);
});

var sizeAndPosition = await this.service.Object.GetElementSizeAndPosition(0, "node", true);

Assert.Multiple(() =>
{
Assert.That(sizeAndPosition, Is.EquivalentTo(new float[] { 1, 2, 3, 4 }));
Assert.That(() => this.service.Object.SubscribeToResizeEvent("resize"), Throws.Nothing);
});
}
}
}


6 changes: 3 additions & 3 deletions COMETwebapp/Components/BookEditor/BookEditorColumn.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,17 @@ public partial class BookEditorColumn<TItem>
/// <summary>
/// The data of size and position of the first item in the list
/// </summary>
private float[] firstItemSizeAndPosition = {};
private float[] firstItemSizeAndPosition = Array.Empty<float>();

/// <summary>
/// The data of size and position of the last item in the list
/// </summary>
private float[] lastItemSizeAndPosition = {};
private float[] lastItemSizeAndPosition = Array.Empty<float>();

/// <summary>
/// The data of size and position of the selected item
/// </summary>
private float[] selectedItemSizeAndPosition = {};
private float[] selectedItemSizeAndPosition = Array.Empty<float>();

/// <summary>
/// Gets or sets the class used to selected the nodes
Expand Down
2 changes: 1 addition & 1 deletion COMETwebapp/Services/Interoperability/DomDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
namespace COMETwebapp.Services.Interoperability
{
using COMETwebapp.Components.BookEditor;
using COMETwebapp.Components.ModelEditor;

using Microsoft.JSInterop;

/// <summary>
Expand Down
Loading

0 comments on commit e4818cd

Please sign in to comment.