Skip to content

Commit

Permalink
Merge pull request #314 from SkillsFundingAgency/PA-360-RPL-details-o…
Browse files Browse the repository at this point in the history
…n-view-page

PA-360 View has been updated to show RPL details
  • Loading branch information
SreekanthBadigenchula authored Jul 27, 2022
2 parents 3663ebf + 392751a commit 58ad477
Show file tree
Hide file tree
Showing 16 changed files with 227 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ public async Task PostDetails_WithValidModel_ShouldSaveDraftApprenticeshipAndRed
var redirect = result.VerifyReturnsRedirectToActionResult();
Assert.AreEqual("SelectOption", redirect.ActionName);
}

[Test]
public async Task GetViewDetails_Cohort_With_Employer_ShouldReturnViewPage()
{
var fixtures = new DetailsTestFixture()
.WithCohortWithEmployer();

var result = await fixtures.Sut.ViewDetails(fixtures.DetailsRequest);
var viewResult = result.VerifyReturnsViewModel();
Assert.AreEqual("View", viewResult.ViewName);
}
}

public class DetailsTestFixture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,36 @@ public async Task VersionOptionsAreMappedCorrectly()

Assert.AreEqual(_getTrainingProgrammeByStandardUId.TrainingProgramme.Options, result.VersionOptions);
}

[Test]
public async Task RecognisePriorLearning_IsMapped()
{
//Act
var result = await _mapper.Map(_request);

//Assert
Assert.AreEqual(_apprenticeshipResponse.RecognisePriorLearning, result.RecognisePriorLearning);
}

[Test]
public async Task PriceReducedByIsMapped()
{
//Act
var result = await _mapper.Map(_request);

//Assert
Assert.AreEqual(_apprenticeshipResponse.PriceReducedBy, result.PriceReducedBy);
}

[Test]
public async Task DurationReducedByIsMapped()
{
//Act
var result = await _mapper.Map(_request);

//Assert
Assert.AreEqual(_apprenticeshipResponse.DurationReducedBy, result.DurationReducedBy);
}
}

public static class MockCommitmentsApiExtensions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@ public DetailsViewModelMapperTestsFixture WithTwoEmailOverlappingOnSameCourse()
{
draftApprenticeship.CourseCode = "ABC";
draftApprenticeship.CourseName = "ABC Name";
draftApprenticeship.DeliveryModel = DeliveryModel.Regular;
}
DraftApprenticeshipsResponse.DraftApprenticeships = draftApprenticeships;
var first = DraftApprenticeshipsResponse.DraftApprenticeships.First();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using AutoFixture;
using Moq;
using NUnit.Framework;
using SFA.DAS.CommitmentsV2.Shared.Interfaces;
using SFA.DAS.CommitmentsV2.Api.Client;
using SFA.DAS.CommitmentsV2.Api.Types.Responses;
using SFA.DAS.CommitmentsV2.Types;
using SFA.DAS.EmployerCommitmentsV2.Web.Mappers.DraftApprenticeship;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.DraftApprenticeship;

namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Mappers.DraftApprenticeship
{
[TestFixture]
public class ViewDraftApprenticeshipViewModelFromDetailsRequestMapperTests
{
private ViewDraftApprenticeshipViewModelFromDetailsRequestMapper _mapper;
private Mock<ICommitmentsApiClient> _apiClient;
private Mock<IModelMapper> _modelMapper;
private GetCohortResponse _cohort;
private DetailsRequest _request;

[SetUp]
public void Arrange()
{
var autoFixture = new Fixture();
_cohort = autoFixture.Create<GetCohortResponse>();

_request = autoFixture.Create<DetailsRequest>();

_apiClient = new Mock<ICommitmentsApiClient>();

_apiClient.Setup(x => x.GetCohort(It.IsAny<long>(), It.IsAny<CancellationToken>())).ReturnsAsync(_cohort);

_modelMapper = new Mock<IModelMapper>();

_modelMapper.Setup(x => x.Map<IDraftApprenticeshipViewModel>(It.IsAny<ViewDraftApprenticeshipRequest>()))
.ReturnsAsync(new ViewDraftApprenticeshipViewModel());

_mapper = new ViewDraftApprenticeshipViewModelFromDetailsRequestMapper(_apiClient.Object, _modelMapper.Object);
}

[TestCase(Party.Employer, typeof(ViewDraftApprenticeshipRequest))]
[TestCase(Party.Provider, typeof(ViewDraftApprenticeshipRequest))]
[TestCase(Party.TransferSender, typeof(ViewDraftApprenticeshipRequest))]
public async Task When_Mapping_The_Mapping_Request_Is_Passed_On_To_The_Appropriate_Mapper(Party withParty, Type expectedMappingRequestType)
{
_cohort.WithParty = withParty;
await _mapper.Map(_request);

_modelMapper.Verify(
x => x.Map<IDraftApprenticeshipViewModel>(It.Is<IDraftApprenticeshipRequest>(
r => r.GetType() == expectedMappingRequestType
&& r.Request == _request
&& r.Cohort == _cohort)),
Times.Once);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,5 +187,23 @@ public void Then_CourseOptionIsMappedCorrectly()
{
Assert.AreEqual(_draftApprenticeship.TrainingCourseOption, _result.CourseOption);
}

[Test]
public void Then_RecognisePriorLearningIsMappedCorrectly()
{
Assert.AreEqual(_draftApprenticeship.RecognisePriorLearning, _result.RecognisePriorLearning);
}

[Test]
public void Then_DurationReducedByIsMappedCorrectly()
{
Assert.AreEqual(_draftApprenticeship.DurationReducedBy, _result.DurationReducedBy);
}

[Test]
public void Then_PriceReducedByIsMappedCorrectly()
{
Assert.AreEqual(_draftApprenticeship.PriceReducedBy, _result.PriceReducedBy);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,15 @@ public async Task<IActionResult> Details(DetailsRequest request)
return View(viewName, viewModel);
}

[HttpGet]
[Route("{DraftApprenticeshipHashedId}/view", Name = "Details-View")]
public async Task<IActionResult> ViewDetails(DetailsRequest request)
{
var viewModel = await _modelMapper.Map<ViewDraftApprenticeshipViewModel>(request);
var viewName = "View";
return View(viewName, viewModel);
}

[HttpGet]
[Route("{DraftApprenticeshipHashedId}/edit-display", Name="EditDraftApprenticeshipDisplay")]
public IActionResult EditDraftApprenticeshipDisplay(EditDraftApprenticeshipViewModel model)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ public async Task<ApprenticeshipDetailsRequestViewModel> Map(ApprenticeshipDetai
EmailAddressConfirmedByApprentice = apprenticeship.EmailAddressConfirmedByApprentice,
EmploymentEndDate = apprenticeship.EmploymentEndDate,
EmploymentPrice = apprenticeship.EmploymentPrice,
RecognisePriorLearning = apprenticeship.RecognisePriorLearning,
DurationReducedBy = apprenticeship.DurationReducedBy,
PriceReducedBy = apprenticeship.PriceReducedBy,
};

return result;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Threading.Tasks;
using SFA.DAS.CommitmentsV2.Api.Client;
using SFA.DAS.CommitmentsV2.Shared.Interfaces;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.DraftApprenticeship;

namespace SFA.DAS.EmployerCommitmentsV2.Web.Mappers.DraftApprenticeship
{
public class ViewDraftApprenticeshipViewModelFromDetailsRequestMapper : IMapper<DetailsRequest, ViewDraftApprenticeshipViewModel>
{
private readonly ICommitmentsApiClient _commitmentsApiClient;
private readonly IModelMapper _modelMapper;

public ViewDraftApprenticeshipViewModelFromDetailsRequestMapper(ICommitmentsApiClient commitmentsApiClient, IModelMapper modelMapper)
{
_commitmentsApiClient = commitmentsApiClient;
_modelMapper = modelMapper;
}

public async Task<ViewDraftApprenticeshipViewModel> Map(DetailsRequest source)
{
var cohort = await _commitmentsApiClient.GetCohort(source.CohortId);
return (ViewDraftApprenticeshipViewModel)await _modelMapper.Map<IDraftApprenticeshipViewModel>(new ViewDraftApprenticeshipRequest
{
Cohort = cohort,
Request = source
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ public async Task<IDraftApprenticeshipViewModel> Map(ViewDraftApprenticeshipRequ
EndDate = draftApprenticeship.EndDate,
EmploymentEndDate = draftApprenticeship.EmploymentEndDate,
Reference = draftApprenticeship.Reference,
LegalEntityName = source.Cohort.LegalEntityName
LegalEntityName = source.Cohort.LegalEntityName,
RecognisePriorLearning = draftApprenticeship.RecognisePriorLearning,
DurationReducedBy = draftApprenticeship.DurationReducedBy,
PriceReducedBy = draftApprenticeship.PriceReducedBy,
};

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ public class ApprenticeshipDetailsRequestViewModel : IAuthorizationContextModel
public string EmploymentPriceDisplay => EmploymentPrice?.ToGdsCostFormat() ?? string.Empty;
public DateTime? EmploymentEndDate { get; set; }
public string EmploymentEndDateDisplay => EmploymentEndDate?.ToGdsFormatWithoutDay() ?? string.Empty;

public bool? RecognisePriorLearning { get; set; }
public int? DurationReducedBy { get; set; }
public int? PriceReducedBy { get; set; }
public ActionRequiredBanner GetActionRequiredBanners()
{
var actionRequiredBanner = ActionRequiredBanner.None;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@ public class ViewDraftApprenticeshipViewModel : IDraftApprenticeshipViewModel
public string Reference { get; set; }
public string LegalEntityName { get; set; }
public bool HasStandardOptions { get; set; }
public bool? RecognisePriorLearning { get; set; }
public int? DurationReducedBy { get; set; }
public int? PriceReducedBy { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
<PackageReference Include="StructureMap.AspNetCore" Version="2.0.0" />
<PackageReference Include="WebEssentials.AspNetCore.CdnTagHelpers" Version="1.0.16" />
<PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Shared" Version="8.20.26" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@
<td class="govuk-table__cell"></td>
</tr>
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">Planned training finish date</th>
<th scope="row" class="govuk-table__header">Planned training end date</th>
<td id="end-date" class="govuk-table__cell" colspan="2">
@if (Model.EndDate.HasValue)
{
Expand All @@ -302,23 +302,40 @@
<td class="govuk-table__cell"></td>
}
</tr>

@if(Model.DeliveryModel != null)
@if (Model.DeliveryModel != null)
{
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">Planned end date for this employment</th>
<td id="apprentice-end-date" class="govuk-table__cell">@Model.EmploymentEndDateDisplay</td>
<td class="govuk-table__cell"></td>
</tr>
}

@if (Model.RecognisePriorLearning == true)
{
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">Duration reduction due to prior learning</th>
<td id="apprentice-end-date" class="govuk-table__cell">@Model.DurationReducedBy &nbsp;weeks</td>
<td class="govuk-table__cell"></td>
</tr>
}
@if(Model.DeliveryModel != null)
{
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">Training price for this employment</th>
<td id="apprentice-end-date" class="govuk-table__cell">@Model.EmploymentPriceDisplay</td>
<td class="govuk-table__cell"></td>
</tr>
}


@if(Model.RecognisePriorLearning == true)
{
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">Price reduction due to prior learning</th>
<td id="apprentice-end-date" class="govuk-table__cell">@Model.PriceReducedBy.FormatCost()</td>
<td class="govuk-table__cell"></td>
</tr>
}
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">Total agreed apprenticeship price</th>
<td id="apprentice-cost" class="govuk-table__cell" colspan="2">@Model.Cost.FormatCost()</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,12 @@
@(Model.IsReadOnly ? "View" : "Edit")
<span class="govuk-visually-hidden">@draftApprenticeship.DisplayName's details</span>
</a>
<br /><br />
<br />
@if (!Model.IsReadOnly)
{
<a class="govuk-link view-apprentice" href="@Url.RouteUrl("Details-View", new { @draftApprenticeship.DraftApprenticeshipHashedId, @Model.CohortReference, @Model.AccountHashedId })">View</a>
}
<br />
@if (!Model.IsReadOnly)
{
<a class="govuk-link delete-apprentice" href="@Url.RouteUrl("DeleteDraftApprenticeship", new { draftApprenticeship.DraftApprenticeshipHashedId, Model.CohortReference, Model.AccountHashedId, Origin = DeleteDraftApprenticeshipOrigin.CohortDetails })">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,20 @@
@DisplayOptionalEstimatedDate(Model.EmploymentEndDate)
</dd>
</div>
}
@if (Model.RecognisePriorLearning == true)
{
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
Duration reduction due to prior learning
</dt>
<dd class="govuk-summary-list__value">
@Model.DurationReducedBy&nbsp;weeks
</dd>
</div>
}
@if (Model.DeliveryModel != null)
{
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
Training price for this employment
Expand All @@ -126,6 +140,17 @@
</dd>
</div>
}
@if (Model.RecognisePriorLearning == true)
{
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
Price reduction due to prior learning
</dt>
<dd class="govuk-summary-list__value">
@DisplayCost(Model.PriceReducedBy)
</dd>
</div>
}
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
Total agreed apprenticeship price
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<PackageReference Include="SFA.DAS.Authorization.CommitmentPermissions" Version="6.0.97" />
<PackageReference Include="SFA.DAS.Authorization.EmployerFeatures" Version="6.0.97" />
<PackageReference Include="SFA.DAS.Authorization.EmployerUserRoles" Version="6.0.97" />
<PackageReference Include="SFA.DAS.Commitments.Api.Client" Version="8.20.26" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Shared" Version="8.20.26" />
<PackageReference Include="SFA.DAS.Commitments.Api.Client" Version="8.22.5" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Shared" Version="8.22.5" />
<PackageReference Include="SFA.DAS.EmployerAccounts.Api.Client" Version="1.6.3100" />
<PackageReference Include="SFA.DAS.EmployerUrlHelper" Version="3.0.43" />
<PackageReference Include="SFA.DAS.Encoding" Version="1.1.76" />
Expand Down

0 comments on commit 58ad477

Please sign in to comment.