generated from DFE-Digital/govuk-dotnet-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #319 from DFE-Digital/resource-pages-update
- Loading branch information
Showing
52 changed files
with
1,905 additions
and
316 deletions.
There are no files selected for viewing
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
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
126 changes: 126 additions & 0 deletions
126
Childrens-Social-Care-CPD-Tests/Contentful/Renderers/AssetStructureRendererTests.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,126 @@ | ||
| ||
using Childrens_Social_Care_CPD.Contentful.Renderers; | ||
using Contentful.Core.Models; | ||
using FluentAssertions; | ||
using Microsoft.Extensions.WebEncoders.Testing; | ||
using NUnit.Framework; | ||
using StringWriter = System.IO.StringWriter; | ||
|
||
|
||
namespace Childrens_Social_Care_CPD_Tests.Contentful.Renderers; | ||
|
||
public class AssetStructureRendererTests | ||
{ | ||
private readonly IRenderer<AssetStructure> _sut = new AssetStructureRenderer(); | ||
|
||
[Test] | ||
public void Ignores_Empty_Structure() | ||
{ | ||
// arrange | ||
var assetStructure = new AssetStructure(); | ||
|
||
// act | ||
var htmlContent = _sut.Render(assetStructure); | ||
|
||
// assert | ||
htmlContent.Should().BeNull(); | ||
} | ||
|
||
[Test] | ||
public void Ignores_Empty_StructureData() | ||
{ | ||
// arrange | ||
var assetStructure = new AssetStructure | ||
{ | ||
Data = new AssetStructureData() | ||
}; | ||
|
||
// act | ||
var htmlContent = _sut.Render(assetStructure); | ||
|
||
// assert | ||
htmlContent.Should().BeNull(); | ||
} | ||
|
||
[Test] | ||
public void Ignores_Empty_Asset() | ||
{ | ||
// arrange | ||
var assetStructure = new AssetStructure | ||
{ | ||
Data = new AssetStructureData | ||
{ | ||
Target = new Asset() | ||
} | ||
}; | ||
|
||
// act | ||
var htmlContent = _sut.Render(assetStructure); | ||
|
||
// assert | ||
htmlContent.Should().BeNull(); | ||
} | ||
|
||
[TestCase("text/html")] | ||
[TestCase("application/pdf")] | ||
public void Ignores_ContentTypes(string contentType) | ||
{ | ||
// arrange | ||
var assetStructure = new AssetStructure | ||
{ | ||
Data = new AssetStructureData | ||
{ | ||
Target = new Asset | ||
{ | ||
File = new File | ||
{ | ||
ContentType = contentType, | ||
Url = "/foo" | ||
}, | ||
Description = "foo" | ||
} | ||
} | ||
}; | ||
|
||
// act | ||
var htmlContent = _sut.Render(assetStructure); | ||
|
||
// assert | ||
htmlContent.Should().BeNull(); | ||
} | ||
|
||
[TestCase("image/png")] | ||
[TestCase("Image/PNG")] | ||
[TestCase("image/gif")] | ||
[TestCase("image/xxx")] | ||
public void Renders_Image_Asset(string contentType) | ||
{ | ||
// arrange | ||
var stringWriter = new StringWriter(); | ||
var assetStructure = new AssetStructure | ||
{ | ||
Data = new AssetStructureData | ||
{ | ||
Target = new Asset | ||
{ | ||
File = new File | ||
{ | ||
ContentType = contentType, | ||
Url = "/foo" | ||
}, | ||
Description = "foo" | ||
} | ||
} | ||
}; | ||
|
||
// act | ||
var htmlContent = _sut.Render(assetStructure); | ||
htmlContent.WriteTo(stringWriter, new HtmlTestEncoder()); | ||
var actual = stringWriter.ToString(); | ||
|
||
// assert | ||
actual.Should().StartWith("<img"); | ||
actual.Should().Contain("src=\"HtmlEncode[[/foo]]\""); | ||
actual.Should().Contain("alt=\"HtmlEncode[[foo]]\""); | ||
} | ||
} |
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
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
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
Oops, something went wrong.