Skip to content

Commit 6d676be

Browse files
committed
Updates in samples + added UI tests
1 parent 8121e7a commit 6d676be

File tree

6 files changed

+62
-10
lines changed

6 files changed

+62
-10
lines changed

src/Samples/Common/Views/FeatureSamples/MarkupControl/CommandAsProperty.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ namespace DotVVM.Samples.Common.Views.FeatureSamples.MarkupControl
1111
public class CommandAsProperty : DotvvmMarkupControl
1212
{
1313

14-
public Func<string, bool, Task> Click
14+
public Func<Task> Click
1515
{
16-
get => (Func<string, bool, Task>)GetValue(ClickProperty)!;
16+
get => (Func<Task>)GetValue(ClickProperty)!;
1717
set => SetValue(ClickProperty, value);
1818
}
1919
public static readonly DotvvmProperty ClickProperty
20-
= DotvvmProperty.Register<Func<string, bool, Task>, CommandAsProperty>(c => c.Click, null);
20+
= DotvvmProperty.Register<Func<Task>, CommandAsProperty>(c => c.Click, null);
2121

2222
}
2323
}

src/Samples/Common/Views/FeatureSamples/MarkupControl/CommandAsProperty.dotcontrol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77

88

99
<%--The following with ToString works somehow and I am not sure by what magic--%>
10-
<dot:Button Text="{value: _this}" Click="{command: _control.Click.ToString()}" />
10+
<dot:Button Text="{value: _this}" Click="{command: _control.Click}" />

src/Samples/Common/Views/FeatureSamples/MarkupControl/CommandAsPropertyPage.dothtml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,23 @@
99
</head>
1010
<body>
1111

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

14-
<p DataContext="{value: SelectedItem}">Selected item: {{value: Name}}, {{value: IsTrue}}</p>
16+
<%--<h1>Pass as static command</h1>
17+
<cc:CommandAsPropertyWrapper Click="{staticCommand: (string name, bool isTrue) => (_root.Name = name; _root.IsTrue = isTrue)}" />
18+
<hr />--%>
19+
20+
<%--<h1>Pass as value</h1>
21+
<cc:CommandAsPropertyWrapper Click="{value: (string name, bool isTrue) => _root.MyFunction(name, isTrue)}" />
22+
<hr />--%>
23+
24+
<%--<h1>Pass as resource</h1>
25+
<cc:CommandAsPropertyWrapper Click="{resource: (string name, bool isTrue) => _root.MyFunction(name, isTrue)}" />
26+
<hr />--%>
27+
28+
<p DataContext="{value: SelectedItem}" data-ui="result">Selected item: {{value: Name}}, {{value: IsTrue}}</p>
1529

1630
</body>
1731
</html>

src/Samples/Common/Views/FeatureSamples/MarkupControl/CommandAsPropertyWrapper.dotcontrol

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,22 @@
22
@baseType DotVVM.Samples.Common.Views.FeatureSamples.MarkupControl.CommandAsPropertyWrapper, DotVVM.Samples.Common
33

44
<dot:Repeater DataSource="{value: Items}">
5-
<%--
6-
The correct syntax would be Click="{value: _control.Click(_parent.Name, _parent.IsTrue)}"
7-
Btw is value binding the right thing, or shall we use resource binding here?
8-
--%>
9-
<cc:CommandAsProperty Click="{value: _control.Click(_parent.Name, _parent.IsTrue)}" DataContext="{value: Name}" />
5+
<div style="display: flex; flex-direction: row; gap: 4em" data-ui="button-list">
6+
<div>
7+
<h2>Passed as command</h2>
8+
<cc:CommandAsProperty Click="{command: _control.Click(_parent.Name, _parent.IsTrue)}" DataContext="{value: Name}" />
9+
</div>
10+
<div>
11+
<h2>Passed as static command</h2>
12+
<cc:CommandAsProperty Click="{staticCommand: _control.Click(_parent.Name, _parent.IsTrue)}" DataContext="{value: Name}" />
13+
</div>
14+
<div>
15+
<h2>Passed as value</h2>
16+
<cc:CommandAsProperty Click="{value: _control.Click(_parent.Name, _parent.IsTrue)}" DataContext="{value: Name}" />
17+
</div>
18+
<div>
19+
<h2>Passed as resource</h2>
20+
<cc:CommandAsProperty Click="{resource: _control.Click(_parent.Name, _parent.IsTrue)}" DataContext="{value: Name}" />
21+
</div>
22+
</div>
1023
</dot:Repeater>

src/Samples/Tests/Abstractions/SamplesRouteUrls.designer.cs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Samples/Tests/Tests/Feature/MarkupControlTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,5 +409,29 @@ public void Feature_MarkupControl_MarkupDeclaredProperties()
409409
browser.WaitFor(() => AssertUI.InnerTextEquals(browser.First("[data-ui=counter]"), "2"), 2000);
410410
});
411411
}
412+
413+
[Fact]
414+
public void Feature_MarkupControl_CommandAsPropertyPage()
415+
{
416+
RunInAllBrowsers(browser => {
417+
browser.NavigateToUrl(SamplesRouteUrls.FeatureSamples_MarkupControl_CommandAsPropertyPage);
418+
419+
var lists = browser.FindElements("div[data-ui=button-list]");
420+
for (var j = 0; j < 4; j++)
421+
{
422+
for (var i = 0; i < lists.Count; i++)
423+
{
424+
lists[i].ElementAt("input[type=button]", j).Click();
425+
AssertUI.InnerTextEquals(browser.Single("p[data-ui=result]"), (i % 3) switch {
426+
0 => "Selected item: One, true",
427+
1 => "Selected item: Two, false",
428+
_ => "Selected item: Three, true"
429+
});
430+
431+
i++;
432+
}
433+
}
434+
});
435+
}
412436
}
413437
}

0 commit comments

Comments
 (0)