@@ -1012,6 +1012,51 @@ class InputTest {
10121012 assertThat(capture1, `is `(not (capture3)))
10131013 }
10141014
1015+ @Test
1016+ fun `Double press action` () {
1017+ var calls = 0
1018+
1019+ val action = object : UserAction (" Action1" ) {
1020+ override fun onDoubleActionBegin () {
1021+ calls++
1022+ }
1023+ }
1024+
1025+ input.addAction(action, KeyCode .A )
1026+
1027+ input.mockKeyPress(KeyCode .A )
1028+ input.mockKeyRelease(KeyCode .A )
1029+ assertThat(calls, `is `(0 ))
1030+
1031+ // within threshold, so 2nd press triggers it
1032+ input.mockKeyPress(KeyCode .A )
1033+ input.mockKeyRelease(KeyCode .A )
1034+ assertThat(calls, `is `(1 ))
1035+
1036+ // 3rd press should not trigger since action should be reset
1037+ input.mockKeyPress(KeyCode .A )
1038+ input.mockKeyRelease(KeyCode .A )
1039+ assertThat(calls, `is `(1 ))
1040+
1041+ // 4th press should trigger as normal
1042+ input.mockKeyPress(KeyCode .A )
1043+ input.mockKeyRelease(KeyCode .A )
1044+ assertThat(calls, `is `(2 ))
1045+
1046+ input.doublePressTimeThreshold = 0.1
1047+
1048+ input.mockKeyPress(KeyCode .A )
1049+ input.mockKeyRelease(KeyCode .A )
1050+ assertThat(calls, `is `(2 ))
1051+
1052+ input.update(0.2 )
1053+
1054+ // does not trigger it since more time has passed than threshold
1055+ input.mockKeyPress(KeyCode .A )
1056+ input.mockKeyRelease(KeyCode .A )
1057+ assertThat(calls, `is `(2 ))
1058+ }
1059+
10151060// @Test
10161061// fun `Serialization`() {
10171062// val action = object : UserAction("Action") {}
0 commit comments