@@ -15,7 +15,7 @@ test('Test clicking.', { timeout: 10000 }, function(t)
15
15
var target = targetpractice . start ( ) ;
16
16
17
17
// Wait for the list of elements.
18
- target . on ( 'elements' , function ( elements )
18
+ target . once ( 'elements' , function ( elements )
19
19
{
20
20
// For this test we want a button.
21
21
var button_1 = elements . button_1 ;
@@ -26,14 +26,14 @@ test('Test clicking.', { timeout: 10000 }, function(t)
26
26
} ) ;
27
27
28
28
// Alright we got a click event, did we click the button we wanted?
29
- target . on ( 'click' , function ( e )
29
+ target . once ( 'click' , function ( e )
30
30
{
31
31
t . equal ( e . id , "button_1" , 'Confirm button_1 was clicked.' ) ;
32
32
t . equal ( e . type , "click" , 'Confirm event was a click.' ) ;
33
33
} ) ;
34
34
35
35
// Close the UI.
36
- t . on ( " end" , function ( )
36
+ t . once ( ' end' , function ( )
37
37
{
38
38
targetpractice . stop ( ) ;
39
39
} ) ;
@@ -55,13 +55,13 @@ test('Test typing.', { timeout: 10000 }, function(t)
55
55
} ) ;
56
56
57
57
// Currently Target Practice waits for the "user" to finish typing before sending the event.
58
- target . on ( 'type' , function ( element )
58
+ target . once ( 'type' , function ( element )
59
59
{
60
60
t . equal ( element . id , "input_1" , 'Confirm input_1 was used.' ) ;
61
61
t . equal ( element . text , stringToType , `Confirm that ${ stringToType } was typed.` ) ;
62
62
} ) ;
63
63
64
- t . on ( " end" , function ( )
64
+ t . once ( ' end' , function ( )
65
65
{
66
66
targetpractice . stop ( ) ;
67
67
} ) ;
@@ -73,24 +73,36 @@ test('Test scrolling.', { timeout: 10000 }, function(t)
73
73
74
74
var target = targetpractice . start ( ) ;
75
75
76
- target . on ( 'elements' , function ( elements )
76
+ target . once ( 'elements' , function ( elements )
77
77
{
78
78
var textarea_1 = elements . textarea_1 ;
79
79
robot . moveMouse ( textarea_1 . x , textarea_1 . y ) ;
80
80
robot . mouseClick ( ) ;
81
81
robot . scrollMouse ( 0 , - 10 ) ;
82
82
} ) ;
83
83
84
- target . on ( 'scroll' , function ( element )
84
+ target . once ( 'scroll' , function ( element )
85
85
{
86
- // On Linux the textarea scrolls more aggressively.
87
- // TODO: I couldn't find a way to make scrolling more accurate on Linux.
88
- const expectedScroll = os . platform ( ) === 'linux' ? 180 : 10 ;
86
+ /**
87
+ * TODO: This is gross! The scroll distance is different for each OS. I want
88
+ * to look into this further, but at least these numbers are consistent.
89
+ */
90
+ let expectedScroll ;
91
+ switch ( os . platform ( ) ) {
92
+ case 'linux' :
93
+ expectedScroll = 180 ;
94
+ break ;
95
+ case 'win32' :
96
+ expectedScroll = 8 ;
97
+ break ;
98
+ default :
99
+ expectedScroll = 10 ;
100
+ }
89
101
t . equal ( element . id , 'textarea_1' , 'Confirm textarea_1 was used.' ) ;
90
102
t . equal ( element . scroll_y , expectedScroll , 'Confirm scroll to 10.' ) ;
91
103
} ) ;
92
104
93
- t . on ( 'end' , function ( )
105
+ t . once ( 'end' , function ( )
94
106
{
95
107
targetpractice . stop ( ) ;
96
108
} ) ;
0 commit comments