Skip to content

Commit

Permalink
Updates in samples + added UI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasherceg committed Feb 8, 2024
1 parent 8121e7a commit 6d676be
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ namespace DotVVM.Samples.Common.Views.FeatureSamples.MarkupControl
public class CommandAsProperty : DotvvmMarkupControl
{

public Func<string, bool, Task> Click
public Func<Task> Click
{
get => (Func<string, bool, Task>)GetValue(ClickProperty)!;
get => (Func<Task>)GetValue(ClickProperty)!;
set => SetValue(ClickProperty, value);
}
public static readonly DotvvmProperty ClickProperty
= DotvvmProperty.Register<Func<string, bool, Task>, CommandAsProperty>(c => c.Click, null);
= DotvvmProperty.Register<Func<Task>, CommandAsProperty>(c => c.Click, null);

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@


<%--The following with ToString works somehow and I am not sure by what magic--%>
<dot:Button Text="{value: _this}" Click="{command: _control.Click.ToString()}" />
<dot:Button Text="{value: _this}" Click="{command: _control.Click}" />
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,23 @@
</head>
<body>

<h1>Pass as command</h1>
<cc:CommandAsPropertyWrapper Click="{command: (string name, bool isTrue) => _root.MyFunction(name, isTrue)}" />
<hr />

<p DataContext="{value: SelectedItem}">Selected item: {{value: Name}}, {{value: IsTrue}}</p>
<%--<h1>Pass as static command</h1>
<cc:CommandAsPropertyWrapper Click="{staticCommand: (string name, bool isTrue) => (_root.Name = name; _root.IsTrue = isTrue)}" />
<hr />--%>

<%--<h1>Pass as value</h1>
<cc:CommandAsPropertyWrapper Click="{value: (string name, bool isTrue) => _root.MyFunction(name, isTrue)}" />
<hr />--%>

<%--<h1>Pass as resource</h1>
<cc:CommandAsPropertyWrapper Click="{resource: (string name, bool isTrue) => _root.MyFunction(name, isTrue)}" />
<hr />--%>

<p DataContext="{value: SelectedItem}" data-ui="result">Selected item: {{value: Name}}, {{value: IsTrue}}</p>

</body>
</html>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@
@baseType DotVVM.Samples.Common.Views.FeatureSamples.MarkupControl.CommandAsPropertyWrapper, DotVVM.Samples.Common

<dot:Repeater DataSource="{value: Items}">
<%--
The correct syntax would be Click="{value: _control.Click(_parent.Name, _parent.IsTrue)}"
Btw is value binding the right thing, or shall we use resource binding here?
--%>
<cc:CommandAsProperty Click="{value: _control.Click(_parent.Name, _parent.IsTrue)}" DataContext="{value: Name}" />
<div style="display: flex; flex-direction: row; gap: 4em" data-ui="button-list">
<div>
<h2>Passed as command</h2>
<cc:CommandAsProperty Click="{command: _control.Click(_parent.Name, _parent.IsTrue)}" DataContext="{value: Name}" />
</div>
<div>
<h2>Passed as static command</h2>
<cc:CommandAsProperty Click="{staticCommand: _control.Click(_parent.Name, _parent.IsTrue)}" DataContext="{value: Name}" />
</div>
<div>
<h2>Passed as value</h2>
<cc:CommandAsProperty Click="{value: _control.Click(_parent.Name, _parent.IsTrue)}" DataContext="{value: Name}" />
</div>
<div>
<h2>Passed as resource</h2>
<cc:CommandAsProperty Click="{resource: _control.Click(_parent.Name, _parent.IsTrue)}" DataContext="{value: Name}" />
</div>
</div>
</dot:Repeater>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions src/Samples/Tests/Tests/Feature/MarkupControlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -409,5 +409,29 @@ public void Feature_MarkupControl_MarkupDeclaredProperties()
browser.WaitFor(() => AssertUI.InnerTextEquals(browser.First("[data-ui=counter]"), "2"), 2000);
});
}

[Fact]
public void Feature_MarkupControl_CommandAsPropertyPage()
{
RunInAllBrowsers(browser => {
browser.NavigateToUrl(SamplesRouteUrls.FeatureSamples_MarkupControl_CommandAsPropertyPage);

var lists = browser.FindElements("div[data-ui=button-list]");
for (var j = 0; j < 4; j++)
{
for (var i = 0; i < lists.Count; i++)
{
lists[i].ElementAt("input[type=button]", j).Click();
AssertUI.InnerTextEquals(browser.Single("p[data-ui=result]"), (i % 3) switch {
0 => "Selected item: One, true",
1 => "Selected item: Two, false",
_ => "Selected item: Three, true"
});

i++;
}
}
});
}
}
}

0 comments on commit 6d676be

Please sign in to comment.