Skip to content

Commit

Permalink
Add unit test for HierarchyRepeater+markup control+command
Browse files Browse the repository at this point in the history
  • Loading branch information
exyi committed Dec 21, 2022
1 parent 9b79772 commit 552df20
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</PropertyGroup>

<PropertyGroup Label="Building">
<LangVersion>10.0</LangVersion>
<LangVersion>11.0</LangVersion>
<!-- Disable warning for missing XML doc comments. -->
<NoWarn>$(NoWarn);CS1591;CS1573</NoWarn>
<Deterministic>true</Deterministic>
Expand Down
39 changes: 39 additions & 0 deletions src/Tests/ControlTests/HierarchyRepeaterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class HierarchyRepeaterTests
{
static readonly ControlTestHelper cth = new ControlTestHelper(config: config => {
config.RouteTable.Add("Simple", "Simple", "Simple.dothtml");
config.Markup.AddMarkupControl("cc", "ButtonControl", "ButtonControl.dotcontrol");
});
OutputChecker check = new OutputChecker("testoutputs");

Expand All @@ -40,6 +41,42 @@ public async Task UsageWithThisInBindings()
check.CheckString(r.FormattedHtml, fileExtension: "html");
}

[TestMethod]
[DataRow(true)]
[DataRow(false)]
public async Task CommandInMarkupControl(bool clientRendering)
{
var r = await cth.RunPage(typeof(BasicTestViewModel), $$"""
<dot:HierarchyRepeater DataSource={value: HItems}
ItemChildrenBinding={value: Children}
RenderSettings.Mode={{(clientRendering ? "Client" : "Server")}}>
<ItemTemplate>
<cc:ButtonControl DataContext={value: _this} Click={command: _root.SelectedLabel = _this.Label} />
</ItemTemplate>
</dot:HierarchyRepeater>
""",
directives: $"@service s = {typeof(TestService)}",
markupFiles: new Dictionary<string, string> {
["ButtonControl.dotcontrol"] = """
@viewModel DotVVM.Framework.Tests.ControlTests.HierarchyRepeaterTests.BasicTestViewModel.SaneHierarchicalItem
@property DotVVM.Framework.Binding.Expressions.Command Click
<dot:Button Click={command: _control.Click()} Text={value: _this.Label} />
"""
},
fileName: "CommandInMarkupControl" + (clientRendering ? "Client" : "Server")
);

// await r.RunCommand("_control.Click()", vm => vm is BasicTestViewModel.SaneHierarchicalItem { Label: "A_1_2" });
// Assert.AreEqual("A_1_2", (string)r.ViewModel.SelectedLabel);
check.CheckString(
r.OutputString,
checkName: clientRendering ? "client" : "server",
fileExtension: "html"
);
}

public class BasicTestViewModel: DotvvmViewModelBase
{
public List<SaneHierarchicalItem> HItems { get; set; } = new () {
Expand All @@ -63,6 +100,8 @@ public class SaneHierarchicalItem
public string Label { get; set; }
public List<SaneHierarchicalItem> Children { get; set; } = new List<SaneHierarchicalItem>();
}

public string SelectedLabel { get; set; }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

<head></head>
<body>

<div><!-- ko template: { foreach: HItems, name: "c7-item", hierarchyRole: "Root" } --><!-- /ko --></div>

<!-- Resource c7-item of type TemplateResource. -->
<template id=c7-item><!-- ko with: $item -->
<!-- ko with: $rawData --><div>
<input type=button onclick='dotvvm.postBack(this,["HItems/[$indexPath]","$parent"],"RR93KduwUKJIXxFp","c7"+&#39;_&#39;+(ko.contextFor(this).$parentContext.$indexPath.map(ko.unwrap).join("_")+"L")+&#39;_&#39;+"c9",null,[],[],undefined).catch(dotvvm.log.logPostBackScriptError);event.stopPropagation();return false;' data-bind="value: Label" /></div><!-- /ko -->
<!-- /ko --><!-- ko template: { foreach: $item().Children, name: "c7-item", hierarchyRole: "Child" } --><!-- ko if: Children()?.length --><!-- /ko --><!-- /ko --></template>

</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

<head></head>
<body>

<div><!-- ko dotvvm-SSR-foreach: { data: HItems } --><!-- ko dotvvm-SSR-item: 0 -->
<!-- ko with: $rawData --><div>
<input type=button value=A onclick='dotvvm.postBack(this,["HItems/[0]","$parents[1]"],"RR93KduwUKJIXxFp","c7_0L_c9",null,[],[],undefined).catch(dotvvm.log.logPostBackScriptError);event.stopPropagation();return false;' /></div><!-- /ko -->
<!-- /ko --><!-- ko dotvvm-SSR-foreach: { data: ko.unwrap($foreachCollectionSymbol)[0]().Children } --><!-- ko dotvvm-SSR-item: 0 -->
<!-- ko with: $rawData --><div>
<input type=button value=A_1 onclick='dotvvm.postBack(this,["HItems/[0]/[0]","$parents[1]"],"RR93KduwUKJIXxFp","c7_0_0L_c9",null,[],[],undefined).catch(dotvvm.log.logPostBackScriptError);event.stopPropagation();return false;' /></div><!-- /ko -->
<!-- /ko --><!-- ko dotvvm-SSR-foreach: { data: ko.unwrap($foreachCollectionSymbol)[0]().Children } --><!-- ko dotvvm-SSR-item: 0 -->
<!-- ko with: $rawData --><div>
<input type=button value=A_1_1 onclick='dotvvm.postBack(this,["HItems/[0]/[0]/[0]","$parents[1]"],"RR93KduwUKJIXxFp","c7_0_0_0L_c9",null,[],[],undefined).catch(dotvvm.log.logPostBackScriptError);event.stopPropagation();return false;' /></div><!-- /ko -->
<!-- /ko --><!-- ko dotvvm-SSR-item: 1 -->
<!-- ko with: $rawData --><div>
<input type=button value=A_1_2 onclick='dotvvm.postBack(this,["HItems/[0]/[0]/[1]","$parents[1]"],"RR93KduwUKJIXxFp","c7_0_0_1L_c9",null,[],[],undefined).catch(dotvvm.log.logPostBackScriptError);event.stopPropagation();return false;' /></div><!-- /ko -->
<!-- /ko --><!-- /ko --><!-- /ko --><!-- ko dotvvm-SSR-item: 1 -->
<!-- ko with: $rawData --><div>
<input type=button value=B onclick='dotvvm.postBack(this,["HItems/[1]","$parents[1]"],"RR93KduwUKJIXxFp","c7_1L_c9",null,[],[],undefined).catch(dotvvm.log.logPostBackScriptError);event.stopPropagation();return false;' /></div><!-- /ko -->
<!-- /ko --><!-- /ko --></div>


</body>

0 comments on commit 552df20

Please sign in to comment.