11import { HButton } from './'
22import { Meta , StoryObj } from 'storybook-solidjs'
3- import { fn } from '@storybook/test'
3+ import { expect , fireEvent , fn , within } from '@storybook/test'
44
55const meta = {
66 argTypes : {
@@ -27,7 +27,13 @@ const meta = {
2727 } ,
2828 } ,
2929 } ,
30- args : { onClick : fn ( ) , onDoubleClick : fn ( ) } ,
30+ args : {
31+ children : 'Click me' ,
32+ onClick : fn ( ) ,
33+ onDoubleClick : fn ( ) ,
34+ onTouchEnd : fn ( ) ,
35+ onTouchStart : fn ( ) ,
36+ } ,
3137 component : HButton ,
3238 title : 'Solid/Components/Button/HButton' ,
3339} satisfies Meta < typeof HButton >
@@ -36,6 +42,65 @@ export default meta
3642
3743type Story = StoryObj < typeof meta >
3844
39- export const Default : Story = {
40- render : ( args ) => < HButton { ...args } > Click me</ HButton > ,
45+ export const Default : Story = { }
46+
47+ export const Click : Story = {
48+ play : async ( { canvasElement, args} ) => {
49+ const canvas = within ( canvasElement )
50+ const button = canvas . getByRole ( 'button' , { name : 'Click me' } )
51+
52+ await fireEvent . click ( button )
53+ expect ( args . onClick ) . toHaveBeenCalledTimes ( 1 )
54+ } ,
55+ }
56+
57+ export const TouchStart : Story = {
58+ play : async ( { canvasElement, args} ) => {
59+ const canvas = within ( canvasElement )
60+ const button = canvas . getByRole ( 'button' , { name : 'Click me' } )
61+
62+ await fireEvent . touchStart ( button )
63+ expect ( args . onTouchStart ) . toHaveBeenCalledTimes ( 1 )
64+ } ,
65+ }
66+
67+ export const TouchEnd : Story = {
68+ play : async ( { canvasElement, args} ) => {
69+ const canvas = within ( canvasElement )
70+ const button = canvas . getByRole ( 'button' , { name : 'Click me' } )
71+
72+ await fireEvent . touchEnd ( button )
73+ expect ( args . onTouchEnd ) . toHaveBeenCalledTimes ( 1 )
74+ } ,
75+ }
76+
77+ export const DoubleClick : Story = {
78+ play : async ( { canvasElement, args} ) => {
79+ const canvas = within ( canvasElement )
80+ const button = canvas . getByRole ( 'button' , { name : 'Click me' } )
81+
82+ // first click
83+ await fireEvent . click ( button )
84+ // double click
85+ await fireEvent . click ( button )
86+ // check double click event
87+ expect ( args . onDoubleClick ) . toHaveBeenCalledTimes ( 1 )
88+ } ,
89+ }
90+
91+ export const DoubleClickWithTouch : Story = {
92+ play : async ( { canvasElement, args} ) => {
93+ const canvas = within ( canvasElement )
94+ const button = canvas . getByRole ( 'button' , { name : 'Click me' } )
95+
96+ // first touch start and touch end
97+ // 첫 번째 터치 이벤트 (touchstart)
98+ await fireEvent . touchStart ( button )
99+ await fireEvent . touchEnd ( button )
100+ // double click
101+ await fireEvent . touchStart ( button )
102+ await fireEvent . touchEnd ( button )
103+ // check double click event
104+ expect ( args . onDoubleClick ) . toHaveBeenCalledTimes ( 1 )
105+ } ,
41106}
0 commit comments