Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ namespace UI_DSM.Client.Tests.Components.NormalUser.ProjectReview
using Bunit.TestDoubles;

using Microsoft.Extensions.DependencyInjection;

using Moq;
using NUnit.Framework;

using UI_DSM.Client.Components.NormalUser.ProjectReview;
using UI_DSM.Client.Services.ReviewObjectiveService;
using UI_DSM.Client.Services.ReviewService;
using UI_DSM.Client.Tests.Helpers;
using UI_DSM.Client.ViewModels.Components;
using UI_DSM.Client.ViewModels.Components.NormalUser.ProjectReview;
using UI_DSM.Shared.DTO.Common;
using UI_DSM.Shared.Enumerator;
using UI_DSM.Shared.Models;
using UI_DSM.Shared.Types;

using TestContext = Bunit.TestContext;

Expand All @@ -36,15 +41,17 @@ public class ReviewObjectiveComponentTestFixture
private TestContext context;
private IReviewObjectiveViewModel viewModel;
private IErrorMessageViewModel errorMessage;
private Mock<IReviewObjectiveService> reviewObjectiveService;

[SetUp]
public void Setup()
{
this.context = new TestContext();
this.errorMessage = new ErrorMessageViewModel();
this.context.ConfigureDevExpressBlazor();
this.reviewObjectiveService = new Mock<IReviewObjectiveService>();

this.viewModel = new ReviewObjectiveViewModel(null)
this.viewModel = new ReviewObjectiveViewModel(this.reviewObjectiveService.Object, null)
{
Review = new Review()
};
Expand Down Expand Up @@ -77,5 +84,87 @@ public void VerifyComponent()
var reviewObjectiveItem1 = renderer.FindComponents<AppObjectiveItem>();
Assert.That(reviewObjectiveItem1, Has.Count.EqualTo(1));
}

[Test]
public async Task VerifyOpenCreationPopupAndCreateReviewObjectives()
{
try
{
var projectGuid = Guid.NewGuid();

var project = new Project(projectGuid)
{
ProjectName = "Project"
};

this.viewModel.Project = project;

var renderer = this.context.RenderComponent<ReviewObjectiveComponent>(parameters =>
{
parameters.Add(p => p.ViewModel, this.viewModel);
parameters.AddCascadingValue(this.errorMessage);
});

var appButton = renderer.FindComponent<AppButton>();
var currentCreationReviewList = this.viewModel.ReviewObjectiveCreationViewModel.SelectedReviewObjectives;
Assert.That(this.viewModel.IsOnCreationMode, Is.False);
await renderer.InvokeAsync(appButton.Instance.Click.InvokeAsync);

Assert.Multiple(() =>
{
Assert.That(this.viewModel.IsOnCreationMode, Is.True);
Assert.That(this.viewModel.ReviewObjectiveCreationViewModel.SelectedReviewObjectives, Is.Not.EqualTo(currentCreationReviewList));
});

this.viewModel.ReviewObjectiveCreationViewModel.SelectedReviewObjectivesSrr = new List<ReviewObjectiveCreationDto>();
this.viewModel.ReviewObjectiveCreationViewModel.SelectedReviewObjectivesPrr = new List<ReviewObjectiveCreationDto>();
this.viewModel.ReviewObjectiveCreationViewModel.SelectedReviewObjectives = new List<ReviewObjectiveCreationDto>();

this.viewModel.ReviewObjectiveCreationViewModel.SelectedReviewObjectives.ToList().Add(new ReviewObjectiveCreationDto()
{
Kind = ReviewObjectiveKind.Prr,
KindNumber = 1,

});

this.reviewObjectiveService.Setup(x => x.CreateReviewObjectives(projectGuid, this.viewModel.Review.Id, this.viewModel.ReviewObjectiveCreationViewModel.SelectedReviewObjectives))
.ReturnsAsync(EntitiesRequestResponses<ReviewObjective>.Fail(new List<string>
{
"A review with the same name already exists"
}));

await this.viewModel.ReviewObjectiveCreationViewModel.OnValidSubmit.InvokeAsync();

Assert.Multiple(() =>
{
Assert.That(this.viewModel.ErrorMessageViewModel.Errors, Has.Count.EqualTo(1));
Assert.That(this.viewModel.IsOnCreationMode, Is.True);
});

this.reviewObjectiveService.Setup(x => x.CreateReviewObjectives(projectGuid, this.viewModel.Review.Id, this.viewModel.ReviewObjectiveCreationViewModel.SelectedReviewObjectives))
.ReturnsAsync(EntitiesRequestResponses<ReviewObjective>.Success(new List<ReviewObjective>
{
new ReviewObjective(Guid.NewGuid())
}));

await this.viewModel.ReviewObjectiveCreationViewModel.OnValidSubmit.InvokeAsync();

Assert.Multiple(() =>
{
Assert.That(this.viewModel.IsOnCreationMode, Is.False);
Assert.That(this.viewModel.ErrorMessageViewModel.Errors, Is.Empty);
});

this.reviewObjectiveService.Setup(x => x.CreateReviewObjectives(projectGuid, this.viewModel.Review.Id, this.viewModel.ReviewObjectiveCreationViewModel.SelectedReviewObjectives))
.ThrowsAsync(new HttpRequestException());

await this.viewModel.ReviewObjectiveCreationViewModel.OnValidSubmit.InvokeAsync();
Assert.That(this.viewModel.ErrorMessageViewModel.Errors, Has.Count.EqualTo(1));
}
catch
{
// On GitHub, exception is thrown even if the JSRuntime has been configured
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// --------------------------------------------------------------------------------------------------------
// <copyright file="ReviewObjectiveCreationTestFixture.cs" company="RHEA System S.A.">
// Copyright (c) 2022 RHEA System S.A.
//
// Author: Antoine Théate, Sam Gerené, Alex Vorobiev, Alexander van Delft, Martin Risseeuw, Nabil Abbar
//
// This file is part of UI-DSM.
// The UI-DSM web application is used to review an ECSS-E-TM-10-25 model.
//
// The UI-DSM application is provided to the community under the Apache License 2.0.
// </copyright>
// --------------------------------------------------------------------------------------------------------

namespace UI_DSM.Client.Tests.Components.NormalUser.ProjectReview
{
using Bunit;

using DevExpress.Blazor;

using Moq;

using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;

using NUnit.Framework;

using UI_DSM.Client.Components.NormalUser.ProjectReview;
using UI_DSM.Client.Services.ReviewObjectiveService;
using UI_DSM.Client.Tests.Helpers;
using UI_DSM.Client.ViewModels.Components;
using UI_DSM.Client.ViewModels.Components.NormalUser.ProjectReview;
using UI_DSM.Shared.Models;

using TestContext = Bunit.TestContext;
using UI_DSM.Client.Services.ReviewService;
using UI_DSM.Shared.DTO.Common;
using UI_DSM.Shared.Enumerator;

[TestFixture]
public class ReviewObjectiveCreationTestFixture
{
private TestContext context;
private IReviewObjectiveCreationViewModel reviewObjectiveCreationViewModel;
private IErrorMessageViewModel errorMessageViewModel;
private Mock<IReviewObjectiveService> reviewObjectiveService;


[SetUp]
public void Setup()
{
this.context = new TestContext();
this.context.ConfigureDevExpressBlazor();
this.errorMessageViewModel = new ErrorMessageViewModel();
this.reviewObjectiveService = new Mock<IReviewObjectiveService>();

this.reviewObjectiveCreationViewModel = new ReviewObjectiveCreationViewModel(this.reviewObjectiveService.Object)
{
ReviewObjective = new ReviewObjective(),
OnValidSubmit = new EventCallbackFactory().Create(this, () => this.reviewObjectiveCreationViewModel.ReviewObjective = new ReviewObjective()),
};

}

[TearDown]
public void TearDown()
{
this.context.CleanContext();
}

[Test]
public async Task VerifyComponent()
{
try
{
this.reviewObjectiveService.Setup(x => x.GetAvailableTemplates(It.IsAny<Guid>(), It.IsAny<Guid>())).ReturnsAsync(new List<ReviewObjectiveCreationDto> { new ReviewObjectiveCreationDto() });
var renderer = this.context.RenderComponent<ReviewObjectiveCreation>(parameters =>
{
parameters.AddCascadingValue(this.errorMessageViewModel);
parameters.Add(p => p.ViewModel, this.reviewObjectiveCreationViewModel);
});

var listBox = renderer.FindComponents<DxListBox<ReviewObjectiveCreationDto, ReviewObjectiveCreationDto>>();

Assert.Multiple(() =>
{
Assert.That(listBox.ToList(), Has.Count.EqualTo(2));
Assert.That(renderer.Instance.CreationText, Is.EqualTo("Create"));
});


var reviewCreationDtoPrr = new ReviewObjectiveCreationDto()
{
Kind = ReviewObjectiveKind.Prr,
KindNumber = 3
};

var reviewCreationDtoSrr = new ReviewObjectiveCreationDto()
{
Kind = ReviewObjectiveKind.Srr,
KindNumber = 2
};

this.reviewObjectiveCreationViewModel.AvailableReviewObjectiveCreationDto.Add(reviewCreationDtoPrr);
this.reviewObjectiveCreationViewModel.AvailableReviewObjectiveCreationDto.Add(reviewCreationDtoSrr);

renderer.Render();

Assert.That(listBox, Has.Count.EqualTo(2));

var dxButton = renderer.FindComponent<EditForm>();
Assert.That(this.reviewObjectiveCreationViewModel.AvailableReviewObjectiveCreationDto[1].ToString(), Is.EqualTo(reviewCreationDtoPrr.ToString()));
}
catch
{
// On GitHub, exception is thrown even if the JSRuntime has been configured
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ public class ReviewPageTestFixture
private IReviewPageViewModel viewModel;
private IReviewObjectiveViewModel reviewObjectiveViewModel;
private Mock<IReviewService> reviewService;

[SetUp]
public void Setup()
{
this.context = new TestContext();
this.reviewObjectiveViewModel = new ReviewObjectiveViewModel(null);
this.context.ConfigureDevExpressBlazor();
this.reviewObjectiveViewModel = new ReviewObjectiveViewModel(null, null);
this.reviewService = new Mock<IReviewService>();
this.viewModel = new ReviewPageViewModel(this.reviewService.Object, this.reviewObjectiveViewModel);
this.viewModel = new ReviewPageViewModel(this.reviewService.Object, this.reviewObjectiveViewModel, null);
this.context.Services.AddSingleton(this.viewModel);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,55 @@ public async Task VerifyCreateReviewObjective()
Assert.That(async () => await this.service.CreateReviewObjective(projectId, reviewId, reviewObjective), Throws.Exception);
}


[Test]
public async Task VerifyCreateReviewObjectives()
{
var reviewObjectives = new List<ReviewObjectiveCreationDto>()
{
new ReviewObjectiveCreationDto()
{
Kind = ReviewObjectiveKind.Prr,
KindNumber = 0
}
};

var projectId = Guid.NewGuid();
var reviewId = Guid.NewGuid();

var httpResponse = new HttpResponseMessage();

var entityRequestResponse = new EntityRequestResponseDto()
{
IsRequestSuccessful = false
};

httpResponse.Content = new StringContent(this.jsonService.Serialize(entityRequestResponse));
var request = this.httpMessageHandler.When(HttpMethod.Post, $"/Project/{projectId}/Review/{reviewId}/ReviewObjective/CreateTemplates");
request.Respond(_ => httpResponse);

var requestResponse = await this.service.CreateReviewObjectives(projectId, reviewId, reviewObjectives);
Assert.That(requestResponse.IsRequestSuccessful, Is.False);

entityRequestResponse.IsRequestSuccessful = true;

entityRequestResponse.Entities = new ReviewObjective().GetAssociatedEntities().ToDtos();

httpResponse.Content = new StringContent(this.jsonService.Serialize(entityRequestResponse));

requestResponse = await this.service.CreateReviewObjectives(projectId, reviewId, reviewObjectives);

Assert.Multiple(() =>
{
Assert.That(requestResponse.IsRequestSuccessful, Is.True);
Assert.That(requestResponse.Entities, Is.Not.Empty);
});

httpResponse.Content = new StringContent(string.Empty);

Assert.That(async () => await this.service.CreateReviewObjectives(projectId, reviewId, reviewObjectives), Throws.Exception);
}

[Test]
public async Task VerifyDeleteReviewObjective()
{
Expand Down Expand Up @@ -242,5 +291,26 @@ public async Task VerifyUpdateReview()
httpResponse.Content = new StringContent(string.Empty);
Assert.That(async () => await this.service.UpdateReviewObjective(projectId, reviewObjective), Throws.Exception);
}

[Test]
public async Task VerifyGetAvailableTemplates()
{
var projectId = Guid.NewGuid();
var reviewId = Guid.NewGuid();
var httpResponse = new HttpResponseMessage();
httpResponse.StatusCode = HttpStatusCode.NotFound;

var request = this.httpMessageHandler.When($"/Project/{projectId}/Review/{reviewId}/ReviewObjective/GetAvailableTemplates");
request.Respond(_ => httpResponse);

Assert.That(async () => await this.service.GetAvailableTemplates(projectId, reviewId), Throws.Exception);
httpResponse.StatusCode = HttpStatusCode.OK;

httpResponse.Content = new StringContent(this.jsonService.Serialize(this.entitiesDto));
var reviewObjectives = await this.service.GetAvailableTemplates(projectId, reviewId);
Assert.That(reviewObjectives, Has.Count.EqualTo(4));
httpResponse.Content = new StringContent(string.Empty);
Assert.That(async () => await this.service.GetAvailableTemplates(projectId, reviewId), Throws.Exception);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,23 @@

<div class="project-page">
<div class="page-header">
<h1 class="h3">Review objectives for @this.ViewModel.Review.Title</h1>
<h1 class="h3">Review objectives for @this.ViewModel.Review.Title</h1>
<AppButton Click="@this.ViewModel.OpenCreatePopup" Type="button">
<FeatherPlusCircle Size="20" Color="currentColor" StrokeWidth="2" /> <span>Create review objective(s)</span>
</AppButton>
</div>

<DxPopup CloseOnOutsideClick="false" HeaderText="Create Review Objective(s)" @bind-Visible="@this.ViewModel.IsOnCreationMode">
<Content>
<CascadingValue Value="this.ViewModel.ErrorMessageViewModel">
<ReviewObjectiveCreation ViewModel="@this.ViewModel.ReviewObjectiveCreationViewModel" />
</CascadingValue>
</Content>
</DxPopup>
<div class="objective-overview">
@foreach (var reviewObjective in this.ViewModel.Review.ReviewObjectives.OrderBy(x => x.ReviewObjectiveNumber))
@foreach (var reviewObjective in this.ViewModel.Review.ReviewObjectives.OrderBy(x => x.ReviewObjectiveKind).ThenBy(x => x.ReviewObjectiveKindNumber))
{

<div div @onclick="@(() => this.ViewModel.GoToReviewObjectivePage(reviewObjective))">
<AppObjectiveItem Title="@reviewObjective.Description" Link=@(this.ViewModel.NavigationManager.Uri+"/ReviewObjective/"+reviewObjective.Id) />
<AppObjectiveItem Title="@reviewObjective.Title" Link=@(this.ViewModel.NavigationManager.Uri+"/ReviewObjective/"+reviewObjective.Id) />
</div>
}
</div>
Expand Down
Loading