-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
19b8b84
commit 6a93c57
Showing
7 changed files
with
524 additions
and
13 deletions.
There are no files selected for viewing
117 changes: 117 additions & 0 deletions
117
COMETwebapp.Tests/Components/BookEditor/BookEditorBodyTestFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// <copyright file="BookEditorBodyTestFixture.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.Components.BookEditor | ||
{ | ||
using Bunit; | ||
|
||
using CDP4Common.EngineeringModelData; | ||
using CDP4Common.ReportingData; | ||
using CDP4Common.SiteDirectoryData; | ||
|
||
using COMET.Web.Common.Services.SessionManagement; | ||
using COMET.Web.Common.Test.Helpers; | ||
using COMET.Web.Common.ViewModels.Components; | ||
using COMET.Web.Common.ViewModels.Components.BookEditor; | ||
|
||
using COMETwebapp.Components.BookEditor; | ||
using COMETwebapp.Services.Interoperability; | ||
using COMETwebapp.ViewModels.Components.BookEditor; | ||
|
||
using DynamicData; | ||
|
||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
using Moq; | ||
|
||
using NUnit.Framework; | ||
|
||
using TestContext = Bunit.TestContext; | ||
|
||
[TestFixture] | ||
public class BookEditorBodyTestFixture | ||
{ | ||
private TestContext context; | ||
private IRenderedComponent<BookEditorBody> component; | ||
private Mock<IBookEditorBodyViewModel> viewModel; | ||
private Mock<ISessionService> sessionService; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
this.context = new TestContext(); | ||
this.context.ConfigureDevExpressBlazor(); | ||
this.sessionService = new Mock<ISessionService>(); | ||
|
||
this.viewModel = new Mock<IBookEditorBodyViewModel>(); | ||
this.viewModel.Setup(x => x.CurrentIteration).Returns(new Iteration()); | ||
this.viewModel.Setup(x => x.CurrentDomain).Returns(new DomainOfExpertise()); | ||
this.viewModel.Setup(x => x.AvailableBooks).Returns(new SourceList<Book>()); | ||
|
||
var editorPopupViewModel = new Mock<IEditorPopupViewModel>(); | ||
editorPopupViewModel.Setup(x => x.ValidationErrors).Returns(new SourceList<string>()); | ||
editorPopupViewModel.Setup(x => x.Item).Returns(new Book()); | ||
editorPopupViewModel.Setup(x => x.ActiveDomains).Returns(new List<DomainOfExpertise>()); | ||
editorPopupViewModel.Setup(x => x.AvailableCategories).Returns(new List<Category>()); | ||
|
||
this.viewModel.Setup(x => x.EditorPopupViewModel).Returns(editorPopupViewModel.Object); | ||
|
||
var confirmCancelPopupViewModel = new Mock<IConfirmCancelPopupViewModel>(); | ||
|
||
this.viewModel.Setup(x => x.ConfirmCancelPopupViewModel).Returns(confirmCancelPopupViewModel.Object); | ||
|
||
var domDataService = new Mock<IDomDataService>(); | ||
|
||
this.context.Services.AddSingleton(this.viewModel.Object); | ||
this.context.Services.AddSingleton(this.sessionService.Object); | ||
this.context.Services.AddSingleton(domDataService.Object); | ||
|
||
this.component = this.context.RenderComponent<BookEditorBody>(); | ||
} | ||
|
||
[TearDown] | ||
public void Teardown() | ||
{ | ||
this.context.CleanContext(); | ||
} | ||
|
||
[Test] | ||
public void VerifyComponent() | ||
{ | ||
var bookEditorColumn = this.component.FindComponent<BookEditorColumn<Book>>(); | ||
var sectionEditorColumn = this.component.FindComponent<BookEditorColumn<Section>>(); | ||
var pageEditorColumn = this.component.FindComponent<BookEditorColumn<Page>>(); | ||
var noteEditorColumn = this.component.FindComponent<BookEditorColumn<Note>>(); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
Assert.That(bookEditorColumn.Instance, Is.Not.Null); | ||
Assert.That(sectionEditorColumn.Instance, Is.Not.Null); | ||
Assert.That(pageEditorColumn.Instance, Is.Not.Null); | ||
Assert.That(noteEditorColumn.Instance, Is.Not.Null); | ||
}); | ||
} | ||
} | ||
} | ||
|
150 changes: 150 additions & 0 deletions
150
COMETwebapp.Tests/Components/BookEditor/BookEditorColumnTestFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// <copyright file="BookEditorColumnTestFixture.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.Components.BookEditor | ||
{ | ||
using Bunit; | ||
|
||
using CDP4Common.ReportingData; | ||
using CDP4Common.SiteDirectoryData; | ||
|
||
using COMET.Web.Common.Test.Helpers; | ||
|
||
using COMETwebapp.Components.BookEditor; | ||
using COMETwebapp.Services.Interoperability; | ||
|
||
using Microsoft.AspNetCore.Components; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
using Moq; | ||
|
||
using NUnit.Framework; | ||
|
||
using TestContext = Bunit.TestContext; | ||
|
||
[TestFixture] | ||
public class BookEditorColumnTestFixture | ||
{ | ||
private TestContext context; | ||
private IRenderedComponent<BookEditorColumn<Book>> component; | ||
private Mock<IDomDataService> domDataService; | ||
private bool editIsClicked; | ||
private bool deleteIsClicked; | ||
private bool isCollapsed; | ||
private bool addNewItemIsClicked; | ||
private Book selectedBook; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
this.context = new TestContext(); | ||
this.context.ConfigureDevExpressBlazor(); | ||
|
||
this.domDataService = new Mock<IDomDataService>(); | ||
|
||
this.context.Services.AddSingleton(this.domDataService.Object); | ||
|
||
var book = new Book() | ||
{ | ||
Name = "Book Example", | ||
ShortName = "BookExample", | ||
Owner = new DomainOfExpertise | ||
{ | ||
Name = "Sys", | ||
ShortName = "sys" | ||
} | ||
}; | ||
|
||
var onEditClicked = new EventCallbackFactory().Create<Book>(this, () => { this.editIsClicked = true;}); | ||
var onDeleteClicked = new EventCallbackFactory().Create<Book>(this, () => { this.deleteIsClicked = true; }); | ||
var onSelectedValueClicked = new EventCallbackFactory().Create<Book>(this, (b) => { this.selectedBook = b; }); | ||
var onCollapseClicked = new EventCallbackFactory().Create(this, () => this.isCollapsed = true); | ||
var onAddNewItemClicked = new EventCallbackFactory().Create(this, () => this.addNewItemIsClicked = true); | ||
|
||
this.component = this.context.RenderComponent<BookEditorColumn<Book>>(parameters => | ||
{ | ||
parameters.Add(p => p.CollapseButtonIconClass, "icon-class"); | ||
parameters.Add(p => p.HeaderTitle, "TestColumn"); | ||
parameters.Add(p => p.HeaderHexColor, "#CCC"); | ||
parameters.Add(p => p.Items, new List<Book>() { book }); | ||
parameters.Add(p => p.OnEditClicked, onEditClicked); | ||
parameters.Add(p => p.OnDeleteClicked, onDeleteClicked); | ||
parameters.Add(p => p.SelectedValueChanged, onSelectedValueClicked); | ||
parameters.Add(p => p.CssClass, "node"); | ||
parameters.Add(p => p.OnCollapseClicked, onCollapseClicked); | ||
parameters.Add(p => p.OnCreateNewItemClick, onAddNewItemClicked); | ||
}); | ||
} | ||
|
||
[TearDown] | ||
public void Teardown() | ||
{ | ||
this.context.CleanContext(); | ||
} | ||
|
||
[Test] | ||
public void VerifyComponent() | ||
{ | ||
var collapseButton = this.component.Find(".collapse-button"); | ||
collapseButton.Click(); | ||
|
||
Assert.That(this.isCollapsed, Is.True); | ||
|
||
var addItemButton = this.component.Find(".add-item-button"); | ||
addItemButton.Click(); | ||
|
||
Assert.That(this.addNewItemIsClicked, Is.True); | ||
|
||
var header = this.component.Find(".header-text"); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
Assert.That(header.Attributes["class"].Value, Is.EqualTo("header-text")); | ||
Assert.That(header.HasAttribute("style"), Is.True); | ||
}); | ||
|
||
var nodeButton = this.component.Find(".node-button"); | ||
nodeButton.Click(); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
Assert.That(this.selectedBook, Is.Not.Null); | ||
Assert.That(this.component.Instance.SelectedValue, Is.Not.Null); | ||
}); | ||
|
||
var editButton = this.component.Find(".icon-edit"); | ||
var deleteButton = this.component.Find(".icon-trash"); | ||
|
||
editButton.Click(); | ||
deleteButton.Click(); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
Assert.That(this.editIsClicked, Is.True); | ||
Assert.That(this.deleteIsClicked, Is.True); | ||
}); | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.