33// See the LICENSE file in the project root for more information.
44// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
55
6+ using Microsoft . AspNetCore . Components . Web ;
7+
68namespace UnitTest . Components ;
79
810public class DynamicElementTest
@@ -18,4 +20,45 @@ public void Key_OK()
1820
1921 Assert . Equal ( "<div></div>" , cut . Markup ) ;
2022 }
23+
24+ [ Fact ]
25+ public void TouchEvents_Ok ( )
26+ {
27+ var context = new BunitContext ( ) ;
28+ TouchEventArgs ? touchStartArgs = null ;
29+ TouchEventArgs ? touchEndArgs = null ;
30+ var touchStartEventArgs = new TouchEventArgs
31+ {
32+ Touches = [ new TouchPoint { ClientX = 10 , ClientY = 20 , ScreenX = 30 , ScreenY = 40 } ]
33+ } ;
34+ var touchEndEventArgs = new TouchEventArgs
35+ {
36+ ChangedTouches = [ new TouchPoint { ClientX = 11 , ClientY = 21 , ScreenX = 31 , ScreenY = 41 } ]
37+ } ;
38+
39+ var cut = context . Render < DynamicElement > ( pb =>
40+ {
41+ pb . Add ( a => a . TagName , "span" ) ;
42+ pb . Add ( a => a . TriggerTouchStart , true ) ;
43+ pb . Add ( a => a . OnTouchStart , e =>
44+ {
45+ touchStartArgs = e ;
46+ return Task . CompletedTask ;
47+ } ) ;
48+ pb . Add ( a => a . TriggerTouchEnd , true ) ;
49+ pb . Add ( a => a . OnTouchEnd , e =>
50+ {
51+ touchEndArgs = e ;
52+ return Task . CompletedTask ;
53+ } ) ;
54+ pb . AddChildContent ( "Touch" ) ;
55+ } ) ;
56+
57+ var element = cut . Find ( "span" ) ;
58+ element . TriggerEvent ( "ontouchstart" , touchStartEventArgs ) ;
59+ element . TriggerEvent ( "ontouchend" , touchEndEventArgs ) ;
60+
61+ Assert . Same ( touchStartEventArgs , touchStartArgs ) ;
62+ Assert . Same ( touchEndEventArgs , touchEndArgs ) ;
63+ }
2164}
0 commit comments