Skip to content

Commit

Permalink
feat: Resource pages update
Browse files Browse the repository at this point in the history
Merge pull request #319 from DFE-Digital/resource-pages-update
  • Loading branch information
killij authored Nov 10, 2023
2 parents 2d65c35 + cd5049e commit 2b72e12
Show file tree
Hide file tree
Showing 52 changed files with 1,905 additions and 316 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ public class EntityResolverTests
[TestCase("detailedRole", typeof(DetailedRole))]
[TestCase("heroBanner", typeof(HeroBanner))]
[TestCase("imageCard", typeof(ImageCard))]
[TestCase("imageResource", typeof(ImageResource))]
[TestCase("linkCard", typeof(LinkCard))]
[TestCase("linkListCard", typeof(LinkListCard))]
[TestCase("pdfFileResource", typeof(PdfFileResource))]
[TestCase("resource", typeof(Resource))]
[TestCase("richTextBlock", typeof(RichTextBlock))]
[TestCase("roleList", typeof(RoleList))]
[TestCase("sideMenu", typeof(SideMenu))]
[TestCase("navigationMenu", typeof(NavigationMenu))]
[TestCase("textBlock", typeof(TextBlock))]
[TestCase("videoResource", typeof(VideoResource))]
public void Resolves_Correctly(string contentTypeId, Type expectedType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Childrens_Social_Care_CPD_Tests.Contentful;
[TestFixture]
public partial class PartialsFactoryTests
{
public static object[] Successful_Resolves =
private static readonly object[] Successful_Resolves =
{
new object[] { new AreaOfPractice(), "_AreaOfPractice" },
new object[] { new AreaOfPracticeList(), "_AreaOfPracticeList" },
Expand All @@ -23,13 +23,11 @@ public partial class PartialsFactoryTests
new object[] { new HeroBanner(), string.Empty },
new object[] { new LinkCard(), "_LinkCard" },
new object[] { new ImageCard(), "_ImageCard" },
new object[] { new ImageResource(), "_ImageResource" },
new object[] { new NavigationMenu(), "_NavigationMenu" },
new object[] { new LinkListCard(), "_LinkListCard" },
new object[] { new PdfFileResource(), "_PdfFileResource" },
new object[] { new Resource(), "_Resource" },
new object[] { new RichTextBlock(), "_RichTextBlock" },
new object[] { new RoleList(), "_RoleList" },
new object[] { new SideMenu(), "_SideMenu" },
new object[] { new TextBlock(), "_TextBlock" },
new object[] { new VideoResource(), "_VideoResource" },
};
Expand All @@ -42,7 +40,7 @@ public void Resolves_Correctly(IContent item, string expectedPartialName)
actual.Should().Be(expectedPartialName);
}

public static IContent[] Unsuccessful_Resolves =
private static readonly IContent[] Unsuccessful_Resolves =
{
new TestingContentItem(),
null
Expand Down
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]]\"");
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Childrens_Social_Care_CPD.Contentful.Models;
using Childrens_Social_Care_CPD.Contentful.Renderers;
using Contentful.Core.Models;
using FluentAssertions;
using Microsoft.Extensions.WebEncoders.Testing;
using NUnit.Framework;
Expand All @@ -10,7 +9,7 @@ namespace Childrens_Social_Care_CPD_Tests.Contentful.Renderers;

public class ContentLinkRendererTests
{
private ContentLinkRenderer _sut = new ContentLinkRenderer();
private readonly IRenderer<ContentLink> _sut = new ContentLinkRenderer();

[TestCase("http://foo", "http://foo")]
[TestCase("https://foo", "https://foo")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,21 @@ public async Task Index_Sets_The_ContextModel_Preferences_Set_Value_Correctly(bo
actual.PreferenceSet.Should().Be(preferenceSet);
}

private static readonly object[] _sideMenuContent =
private static readonly object[] _navigationMenuContent =
{
new object[] { new SideMenu() },
new object[] { new NavigationMenu() },
new object[] { null },
};

[TestCaseSource(nameof(_sideMenuContent))]
public async Task Index_Sets_The_ContextModel_UseContainers_From_SideMenu_Value_Correctly(SideMenu sideMenu)
[TestCaseSource(nameof(_navigationMenuContent))]
public async Task Index_Sets_The_ContextModel_UseContainers_From_SideMenu_Value_Correctly(NavigationMenu navigationMenu)
{
// arrange
var rootContent = new Content()
{
SideMenu = sideMenu
Navigation = navigationMenu
};
var expected = sideMenu == null;
var expected = navigationMenu == null;
SetContent(rootContent);

// act
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,19 @@ public async Task Cookies_Sets_The_ContextModel_Preferences_Set_Value_Correctly(
actual.PreferenceSet.Should().Be(preferenceSet);
}

private static readonly object[] _sideMenuContent =
private static readonly object[] _navigationMenuContent =
{
new object[] { new SideMenu() },
new object[] { new NavigationMenu() },
new object[] { null },
};

[TestCaseSource(nameof(_sideMenuContent))]
public async Task Cookies_Sets_The_ContextModel_UseContainers_Ignoring_The_SideMenu_Value(SideMenu sideMenu)
[TestCaseSource(nameof(_navigationMenuContent))]
public async Task Cookies_Sets_The_ContextModel_UseContainers_Ignoring_The_SideMenu_Value(NavigationMenu navigationMenu)
{
// arrange
var rootContent = new Content()
{
SideMenu = sideMenu
Navigation = navigationMenu
};
SetContent(rootContent);

Expand Down
Loading

0 comments on commit 2b72e12

Please sign in to comment.