Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/BookApplication #456

Merged
merged 20 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 143 additions & 0 deletions COMET.Web.Common.Tests/Components/BookEditor/EditotPopupTestFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="EditotPopupTestFixture.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;
using COMET.Web.Common.Components.BookEditor;
using COMET.Web.Common.Test.Helpers;
using COMET.Web.Common.ViewModels.Components.BookEditor;

using DevExpress.Blazor;
using DevExpress.Blazor.Popup.Internal;

using DynamicData;

using Microsoft.AspNetCore.Components;

using Moq;

using NUnit.Framework;

using TestContext = Bunit.TestContext;

[TestFixture]
public class EditotPopupTestFixture
{
private TestContext context;
private Mock<IEditorPopupViewModel> viewmodel;
private IRenderedComponent<EditorPopup> component;
private Book book;
private List<DomainOfExpertise> activeDomains;
private List<Category> availableCategories;
private bool onCancelCalled;
private bool onAcceptCalled;

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

this.book = new Book();

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

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

var onCancelClicked = new EventCallbackFactory().Create(this, () => this.onCancelCalled = true);
var onConfirmClicked = new EventCallbackFactory().Create(this, () => this.onAcceptCalled = true);

this.viewmodel = new Mock<IEditorPopupViewModel>();
this.viewmodel.Setup(x => x.IsVisible).Returns(true);
this.viewmodel.Setup(x => x.ActiveDomains).Returns(this.activeDomains);
this.viewmodel.Setup(x => x.AvailableCategories).Returns(this.availableCategories);
this.viewmodel.Setup(x => x.HeaderText).Returns("Header");
this.viewmodel.Setup(x => x.OnCancelClick).Returns(onCancelClicked);
this.viewmodel.Setup(x => x.OnConfirmClick).Returns(onConfirmClicked);
this.viewmodel.Setup(x => x.ValidationErrors).Returns(new SourceList<string>());

this.component = this.context.RenderComponent<EditorPopup>(parameters =>
{
parameters.Add(p => p.ViewModel, this.viewmodel.Object);
});
}

[Test]
public void VerifyComponent()
{
var popup = this.component.FindComponent<DxPopup>();

Assert.Multiple(() =>
{
Assert.That(popup.Instance.Visible, Is.True);
Assert.That(popup.Instance.HeaderText, Is.EqualTo("Header"));
});

var okButton = this.component.Find(".ok-button");
okButton.Click();

Assert.That(this.onAcceptCalled, Is.True);

var cancelButton = this.component.Find(".cancel-button");
cancelButton.Click();

Assert.That(this.onCancelCalled, Is.True);

var errors = new SourceList<string>();
errors.Add("Error 1");
errors.Add("Error 2");

this.viewmodel.Setup(x => x.ValidationErrors).Returns(errors);

this.component.Render();

var errorMessages = this.component.FindComponents<ValidationMessageComponent>();

Assert.Multiple(() =>
{
Assert.That(errorMessages, Has.Count.EqualTo(2));
Assert.That(errorMessages[0].Instance.ValidationMessage, Is.EqualTo("Error 1"));
Assert.That(errorMessages[1].Instance.ValidationMessage, Is.EqualTo("Error 2"));
});
}
}
}
116 changes: 116 additions & 0 deletions COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// --------------------------------------------------------------------------------------------------------------------
// <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 DevExpress.Blazor;

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 basicTab = this.component.Find(".basic-tab");
basicTab.Click();

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()));
});

var categoryTab = this.component.Find(".category-tab");
categoryTab.Click();

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));
});
}
}
}

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)));
}
}
}
Loading
Loading