-
-
Notifications
You must be signed in to change notification settings - Fork 382
Expand file tree
/
Copy pathDynamicElementTest.cs
More file actions
64 lines (56 loc) · 2 KB
/
DynamicElementTest.cs
File metadata and controls
64 lines (56 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License
// See the LICENSE file in the project root for more information.
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
using Microsoft.AspNetCore.Components.Web;
namespace UnitTest.Components;
public class DynamicElementTest
{
[Fact]
public void Key_OK()
{
var context = new BunitContext();
var cut = context.Render<DynamicElement>(pb =>
{
pb.Add(s => s.Key, Guid.NewGuid());
});
Assert.Equal("<div></div>", cut.Markup);
}
[Fact]
public void TouchEvents_Ok()
{
var context = new BunitContext();
TouchEventArgs? touchStartArgs = null;
TouchEventArgs? touchEndArgs = null;
var touchStartEventArgs = new TouchEventArgs
{
Touches = [new TouchPoint { ClientX = 10, ClientY = 20, ScreenX = 30, ScreenY = 40 }]
};
var touchEndEventArgs = new TouchEventArgs
{
ChangedTouches = [new TouchPoint { ClientX = 11, ClientY = 21, ScreenX = 31, ScreenY = 41 }]
};
var cut = context.Render<DynamicElement>(pb =>
{
pb.Add(a => a.TagName, "span");
pb.Add(a => a.TriggerTouchStart, true);
pb.Add(a => a.OnTouchStart, e =>
{
touchStartArgs = e;
return Task.CompletedTask;
});
pb.Add(a => a.TriggerTouchEnd, true);
pb.Add(a => a.OnTouchEnd, e =>
{
touchEndArgs = e;
return Task.CompletedTask;
});
pb.AddChildContent("Touch");
});
var element = cut.Find("span");
element.TriggerEvent("ontouchstart", touchStartEventArgs);
element.TriggerEvent("ontouchend", touchEndEventArgs);
Assert.Same(touchStartEventArgs, touchStartArgs);
Assert.Same(touchEndEventArgs, touchEndArgs);
}
}