From 49aedef122aa74b5a7c814345f0111982bcd232a Mon Sep 17 00:00:00 2001 From: Joseph Kempster Date: Thu, 12 May 2022 09:43:25 +0100 Subject: [PATCH] Update the template file name We want the project file to be more intuitive, which we can achieve by including the outgoing trust name (in addition to the incoming trust name) and moving the project reference to the beginning. Add string helpers to hyphenate sentences and remove non-alphanumeric characters so that trust names can be formatted as they are in the updated design. Also, add missing string helper tests and DRY up some duplication between the download handler methods. --- .../TaskList/HtbDocument/DownloadTests.cs | 26 ++++++-- .../TaskList/HtbDocument/Download.cshtml | 2 +- .../TaskList/HtbDocument/Download.cshtml.cs | 41 +++++++++--- Helpers.Tests/StringHelperTests.cs | 63 +++++++++++++++++++ Helpers/StringHelper.cs | 21 +++++-- 5 files changed, 135 insertions(+), 18 deletions(-) create mode 100644 Helpers.Tests/StringHelperTests.cs diff --git a/Frontend.Tests/PagesTests/TaskList/HtbDocument/DownloadTests.cs b/Frontend.Tests/PagesTests/TaskList/HtbDocument/DownloadTests.cs index da3a46654..8ad573c4d 100644 --- a/Frontend.Tests/PagesTests/TaskList/HtbDocument/DownloadTests.cs +++ b/Frontend.Tests/PagesTests/TaskList/HtbDocument/DownloadTests.cs @@ -21,7 +21,13 @@ protected DownloadTests() }; _createHtbDocument.Setup(s => s.Execute(ProjectUrn0001)).ReturnsAsync(new CreateProjectTemplateResponse - {Document = new byte[] {0, 1}}); + { + Document = new byte[] { 0, 1 } + }); + + FoundInformationForProject.Project.TransferringAcademies[0].IncomingTrustName = "Incoming Trust"; + FoundInformationForProject.Project.OutgoingTrustName = "Outgoing Trust"; + FoundInformationForProject.Project.Reference = "SW-MAT-10000001"; } public class GetTests : DownloadTests @@ -29,11 +35,18 @@ public class GetTests : DownloadTests [Fact] public async void GivenId_GetsProjectInformation() { - FoundInformationForProject.Project.TransferringAcademies[0].IncomingTrustName = "Incoming Trust"; await _subject.OnGetAsync(); GetInformationForProject.Verify(s => s.Execute(ProjectUrn0001), Times.Once); } + + [Fact] + public async void GivenId_SetsFileName() + { + await _subject.OnGetAsync(); + + Assert.Equal("SW-MAT-10000001_Outgoing-Trust_Incoming-Trust_project-template", _subject.FileName); + } } public class GetDownloadTests : DownloadTests @@ -41,25 +54,26 @@ public class GetDownloadTests : DownloadTests [Fact] public async void GivenId_GeneratesAnHtbDocumentForTheProject() { - FoundInformationForProject.Project.TransferringAcademies[0].IncomingTrustName = "Incoming Trust"; await _subject.OnGetGenerateDocumentAsync(); + _createHtbDocument.Verify(s => s.Execute(ProjectUrn0001), Times.Once); } [Fact] public async void GivenId_ReturnsAFileWithTheGeneratedDocument() { - var fileContents = new byte[] {1, 2, 3, 4}; + var fileContents = new byte[] { 1, 2, 3, 4 }; var createDocumentResponse = new CreateProjectTemplateResponse { Document = fileContents }; _createHtbDocument.Setup(s => s.Execute(ProjectUrn0001)).ReturnsAsync(createDocumentResponse); - FoundInformationForProject.Project.TransferringAcademies[0].IncomingTrustName = "Incoming Trust"; + var response = await _subject.OnGetGenerateDocumentAsync(); - var fileResponse = Assert.IsType(response); + var fileResponse = Assert.IsType(response); Assert.Equal(fileContents, fileResponse.FileContents); + Assert.Equal("SW-MAT-10000001_Outgoing-Trust_Incoming-Trust_project-template.docx", fileResponse.FileDownloadName); } } } diff --git a/Frontend/Pages/TaskList/HtbDocument/Download.cshtml b/Frontend/Pages/TaskList/HtbDocument/Download.cshtml index a53cd9973..ece47e36c 100644 --- a/Frontend/Pages/TaskList/HtbDocument/Download.cshtml +++ b/Frontend/Pages/TaskList/HtbDocument/Download.cshtml @@ -31,7 +31,7 @@

- @Model.IncomingTrustName, @Model.ProjectReference project template + @Model.FileName