예제 #1
0
        public async Task ProcessAsync_AddsActionToContext()
        {
            // Arrange
            var summaryListContext = new SummaryListContext();

            var rowContext = new SummaryListRowContext();

            var context = new TagHelperContext(
                tagName: "govuk-summary-list-row-action",
                allAttributes: new TagHelperAttributeList(),
                items: new Dictionary <object, object>()
            {
                { typeof(SummaryListContext), summaryListContext },
                { typeof(SummaryListRowContext), rowContext }
            },
                uniqueId: "test");

            var output = new TagHelperOutput(
                "govuk-summary-list-row-actions",
                attributes: new TagHelperAttributeList()
            {
                { "href", "#" }
            },
                getChildContentAsync: (useCachedResult, encoder) =>
            {
                var tagHelperContent = new DefaultTagHelperContent();
                tagHelperContent.SetContent("Change");
                return(Task.FromResult <TagHelperContent>(tagHelperContent));
            });

            var tagHelper = new SummaryListRowActionTagHelper()
            {
                VisuallyHiddenText = "vht"
            };

            // Act
            await tagHelper.ProcessAsync(context, output);

            // Assert
            Assert.Collection(
                rowContext.Actions,
                action =>
            {
                Assert.Equal("Change", action.Content.RenderToString());
                Assert.Equal("vht", action.VisuallyHiddenText);

                Assert.Collection(
                    action.Attributes,
                    kvp =>
                {
                    Assert.Equal("href", kvp.Key);
                    Assert.Equal("#", kvp.Value);
                });
            });
        }
예제 #2
0
        public async Task ProcessAsync_AddsActionToContext()
        {
            // Arrange
            var summaryListContext = new SummaryListContext();
            var rowContext         = new SummaryListRowContext();

            var context = new TagHelperContext(
                tagName: "govuk-summary-list-row-action",
                allAttributes: new TagHelperAttributeList(),
                items: new Dictionary <object, object>()
            {
                { typeof(SummaryListContext), summaryListContext },
                { typeof(SummaryListRowContext), rowContext }
            },
                uniqueId: "test");

            var output = new TagHelperOutput(
                "govuk-summary-list-row-action",
                attributes: new TagHelperAttributeList(),
                getChildContentAsync: (useCachedResult, encoder) =>
            {
                var tagHelperContent = new DefaultTagHelperContent();
                tagHelperContent.SetContent("Action content");
                return(Task.FromResult <TagHelperContent>(tagHelperContent));
            });

            var tagHelper = new SummaryListRowActionTagHelper(
                new DefaultGovUkHtmlGenerator(),
                Mock.Of <IUrlHelperFactory>())
            {
                Href = "href",
                VisuallyHiddenText = "vht"
            };

            // Act
            await tagHelper.ProcessAsync(context, output);

            // Assert
            Assert.Equal(1, rowContext.Actions.Count);

            var firstAction = rowContext.Actions.First();

            Assert.Equal("vht", firstAction.VisuallyHiddenText);
            Assert.Equal("href", firstAction.Href);
            Assert.Equal("Action content", firstAction.Content.AsString());
        }