Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Net;
using System.Globalization;
using System.Net;
using FluentAssertions;
using HtmlAgilityPack;
using Microsoft.AspNetCore.TestHost;
Expand Down Expand Up @@ -59,6 +60,8 @@ public async Task SitecoreLayoutModelBinders_BindDataCorrectly()

HttpClient client = _server.CreateClient();

string expectedFormattedDate = DateTime.Parse("12.12.19", CultureInfo.InvariantCulture).ToString("d", CultureInfo.CurrentCulture);

// Act
string response = await client.GetStringAsync(new Uri("/", UriKind.Relative));

Expand All @@ -75,7 +78,7 @@ public async Task SitecoreLayoutModelBinders_BindDataCorrectly()
sectionNode.ChildNodes.First(n => n.Name.Equals("p", StringComparison.OrdinalIgnoreCase)).InnerText
.Should().BeEmpty();

sectionNode.ChildNodes.First(n => n.Name.Equals("textarea", StringComparison.OrdinalIgnoreCase)).InnerText.Should().Contain("12/12/2019");
sectionNode.ChildNodes.First(n => n.Name.Equals("textarea", StringComparison.OrdinalIgnoreCase)).InnerText.Should().Contain(expectedFormattedDate);

sectionNode.ChildNodes.First(n => n.Name.Equals("span", StringComparison.OrdinalIgnoreCase)).InnerHtml
.Should().Be(TestConstants.TestMultilineFieldValue.Replace(Environment.NewLine, "<br>", StringComparison.OrdinalIgnoreCase));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,14 @@ public async Task DateTagHelper_GeneratesProperDate()
doc.LoadHtml(response);
HtmlNode? sectionNode = doc.DocumentNode.ChildNodes.First(n => n.HasClass("component-with-dates"));

// Assert
sectionNode.ChildNodes[1].InnerHtml.Should().Be("05/04/2012");
sectionNode.ChildNodes[3].InnerHtml.Should().Be("05/04/2012 00:00:00");
// Assert - Use culture-aware date formatting instead of hardcoded values
sectionNode.ChildNodes[1].InnerHtml.Should().Be(TestConstants.DateTimeValue.ToString("d", CultureInfo.CurrentCulture));
sectionNode.ChildNodes[3].InnerHtml.Should().Be(TestConstants.DateTimeValue.ToString("G", CultureInfo.CurrentCulture));
sectionNode.ChildNodes[5].InnerHtml.Should().Be(TestConstants.DateTimeValue.ToString(CultureInfo.CurrentCulture));
sectionNode.ChildNodes[9].InnerHtml.Should().Contain("04.05.2012");

// For the custom format, use the specific culture format expected
string expectedCustomFormat = TestConstants.DateTimeValue.ToString("dd.MM.yyyy", CultureInfo.InvariantCulture);
sectionNode.ChildNodes[9].InnerHtml.Should().Contain(expectedCustomFormat);
}

public void Dispose()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Net;
using System.Globalization;
using System.Net;
using System.Text.Encodings.Web;
using FluentAssertions;
using HtmlAgilityPack;
Expand Down Expand Up @@ -70,7 +71,7 @@ public async Task RichTextFieldTagHelper_DoesNotResetOtherTagHelperOutput()

// Assert
// check scenario that RichTextTagHelper does not reset values of another helpers.
sectionNode.ChildNodes.First(n => n.Name.Equals("textarea", StringComparison.OrdinalIgnoreCase)).InnerText.Should().Contain("12/12/2019");
sectionNode.ChildNodes.First(n => n.Name.Equals("textarea", StringComparison.OrdinalIgnoreCase)).InnerText.Should().Contain(DateTime.Parse("2019-12-12").ToString("d", CultureInfo.CurrentCulture));
}

[Fact]
Expand Down
4 changes: 3 additions & 1 deletion tests/data/Sitecore.AspNetCore.SDK.TestData/TestConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public static class TestConstants
public const string RichTextFieldValue1 = "<p>This is a test</p>";
public const string RichTextFieldValue2 = "<p>This is another test</p>";
public const string LinkFieldValue = "<a class=\"sample\" href=\"/\" rel=\"noopener noreferrer\" target=\"_blank\" title=\"title\">Sample Link</a>";
public const string DateFieldValue = "05/04/2012";
public const string ImageFieldValue = "<img alt=\"sample\" src=\"sample.png\">";
public const string AllFieldsImageValue = "<img src=\"sample.png\" alt=\"sample\">";
public const string MediaLibraryItemImageFieldValue = "<figure style='background-image: url(https://cdinstance/en/-/jssmedia/094AED0302E7486880CB19926661FB77.ashx?mw=100&amp;mh=50)'>Text</figure>";
Expand Down Expand Up @@ -90,6 +89,9 @@ public static class TestConstants
public const string HeadlessSxaLayoutId = "96e5f4ba-a2cf-4a4c-a4e7-64da88226362";

public const string PagesSampleConfigRequest = "{}";
public static readonly DateTime DateFieldValueAsDateTime = new DateTime(2012, 5, 4);

public static string DateFieldValue => DateTimeValue.ToString("d", CultureInfo.CurrentCulture);

public static GraphQLResponse<EditingLayoutQueryResponse> SimpleEditingLayoutQueryResponse
{
Expand Down