4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
6
import assert from 'assert' ;
7
+ import { spy } from 'sinon' ;
7
8
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js' ;
8
9
import { MiddleScrollController } from '../../browser/middleScroll.js' ;
9
10
import { withTestCodeEditor } from '../../../../test/browser/testCodeEditor.js' ;
@@ -18,9 +19,162 @@ suite('middleScroll', () => {
18
19
19
20
middleScrollController . startScroll ( 10 , 10 ) ;
20
21
21
- assert . equal ( getActiveWindow ( ) . document . body . classList . contains ( 'scroll-editor-on-middle-click-editor' ) , true ) ;
22
+ assert . ok ( getActiveWindow ( ) . document . body . classList . contains ( 'scroll-editor-on-middle-click-editor' ) ) ;
22
23
23
24
middleScrollController . dispose ( ) ;
24
25
} ) ;
25
26
} ) ;
27
+
28
+ test ( 'Removes the class from body' , ( ) => {
29
+ withTestCodeEditor ( 'test' , { } , ( editor ) => {
30
+ const middleScrollController = editor . registerAndInstantiateContribution ( MiddleScrollController . ID , MiddleScrollController ) ;
31
+
32
+ middleScrollController . startScroll ( 10 , 10 ) ;
33
+
34
+ middleScrollController . stopScroll ( ) ;
35
+
36
+ assert . ok ( ! getActiveWindow ( ) . document . body . classList . contains ( 'scroll-editor-on-middle-click-editor' ) ) ;
37
+
38
+ middleScrollController . dispose ( ) ;
39
+ } ) ;
40
+ } ) ;
41
+
42
+ suite ( "directions" , ( ) => {
43
+ test ( 'n' , ( ) => {
44
+ withTestCodeEditor ( 'test' , { } , ( editor ) => {
45
+ const setScrollTopSpy = spy ( editor , "setScrollTop" ) ;
46
+ const setScrollLeftSpy = spy ( editor , "setScrollLeft" ) ;
47
+ const middleScrollController = editor . registerAndInstantiateContribution ( MiddleScrollController . ID , MiddleScrollController ) ;
48
+
49
+ middleScrollController . startScroll ( 10 , 10 ) ;
50
+ middleScrollController . setCurrent ( 10 , 0 ) ;
51
+ middleScrollController . scrollPane ( ) ;
52
+
53
+ assert . equal ( getActiveWindow ( ) . document . body . getAttribute ( 'data-scroll-direction' ) , 'n' ) ;
54
+ assert . ok ( setScrollTopSpy . lastCall . calledWithExactly ( - 2 ) ) ;
55
+ assert . ok ( setScrollLeftSpy . lastCall . calledWithExactly ( 0 ) ) ;
56
+
57
+ middleScrollController . dispose ( ) ;
58
+ } ) ;
59
+ } ) ;
60
+ test ( 'ne' , ( ) => {
61
+ withTestCodeEditor ( 'test' , { } , ( editor ) => {
62
+ const setScrollTopSpy = spy ( editor , "setScrollTop" ) ;
63
+ const setScrollLeftSpy = spy ( editor , "setScrollLeft" ) ;
64
+ const middleScrollController = editor . registerAndInstantiateContribution ( MiddleScrollController . ID , MiddleScrollController ) ;
65
+
66
+ middleScrollController . startScroll ( 10 , 10 ) ;
67
+ middleScrollController . setCurrent ( 20 , 0 ) ;
68
+ middleScrollController . scrollPane ( ) ;
69
+
70
+ assert . equal ( getActiveWindow ( ) . document . body . getAttribute ( 'data-scroll-direction' ) , 'ne' ) ;
71
+ assert . ok ( setScrollTopSpy . lastCall . calledWithExactly ( - 2 ) ) ;
72
+ assert . ok ( setScrollLeftSpy . lastCall . calledWithExactly ( 3 ) ) ;
73
+
74
+ middleScrollController . dispose ( ) ;
75
+ } ) ;
76
+ } ) ;
77
+ test ( 'e' , ( ) => {
78
+ withTestCodeEditor ( 'test' , { } , ( editor ) => {
79
+ const setScrollTopSpy = spy ( editor , "setScrollTop" ) ;
80
+ const setScrollLeftSpy = spy ( editor , "setScrollLeft" ) ;
81
+ const middleScrollController = editor . registerAndInstantiateContribution ( MiddleScrollController . ID , MiddleScrollController ) ;
82
+
83
+ middleScrollController . startScroll ( 10 , 10 ) ;
84
+ middleScrollController . setCurrent ( 20 , 10 ) ;
85
+ middleScrollController . scrollPane ( ) ;
86
+
87
+ assert . equal ( getActiveWindow ( ) . document . body . getAttribute ( 'data-scroll-direction' ) , 'e' ) ;
88
+ assert . ok ( setScrollTopSpy . lastCall . calledWithExactly ( 0 ) ) ;
89
+ assert . ok ( setScrollLeftSpy . lastCall . calledWithExactly ( 3 ) ) ;
90
+
91
+ middleScrollController . dispose ( ) ;
92
+ } ) ;
93
+ } ) ;
94
+ test ( 'se' , ( ) => {
95
+ withTestCodeEditor ( 'test' , { } , ( editor ) => {
96
+ const setScrollTopSpy = spy ( editor , "setScrollTop" ) ;
97
+ const setScrollLeftSpy = spy ( editor , "setScrollLeft" ) ;
98
+ const middleScrollController = editor . registerAndInstantiateContribution ( MiddleScrollController . ID , MiddleScrollController ) ;
99
+
100
+ middleScrollController . startScroll ( 10 , 10 ) ;
101
+ middleScrollController . setCurrent ( 20 , 20 ) ;
102
+ middleScrollController . scrollPane ( ) ;
103
+
104
+ assert . equal ( getActiveWindow ( ) . document . body . getAttribute ( 'data-scroll-direction' ) , 'se' ) ;
105
+ assert . ok ( setScrollTopSpy . lastCall . calledWithExactly ( 3 ) ) ;
106
+ assert . ok ( setScrollLeftSpy . lastCall . calledWithExactly ( 3 ) ) ;
107
+
108
+ middleScrollController . dispose ( ) ;
109
+ } ) ;
110
+ } ) ;
111
+ test ( 's' , ( ) => {
112
+ withTestCodeEditor ( 'test' , { } , ( editor ) => {
113
+ const setScrollTopSpy = spy ( editor , "setScrollTop" ) ;
114
+ const setScrollLeftSpy = spy ( editor , "setScrollLeft" ) ;
115
+ const middleScrollController = editor . registerAndInstantiateContribution ( MiddleScrollController . ID , MiddleScrollController ) ;
116
+
117
+ middleScrollController . startScroll ( 10 , 10 ) ;
118
+ middleScrollController . setCurrent ( 10 , 20 ) ;
119
+ middleScrollController . scrollPane ( ) ;
120
+
121
+ assert . equal ( getActiveWindow ( ) . document . body . getAttribute ( 'data-scroll-direction' ) , 's' ) ;
122
+ assert . ok ( setScrollTopSpy . lastCall . calledWithExactly ( 3 ) ) ;
123
+ assert . ok ( setScrollLeftSpy . lastCall . calledWithExactly ( 0 ) ) ;
124
+
125
+ middleScrollController . dispose ( ) ;
126
+ } ) ;
127
+ } ) ;
128
+ test ( 'sw' , ( ) => {
129
+ withTestCodeEditor ( 'test' , { } , ( editor ) => {
130
+ const setScrollTopSpy = spy ( editor , "setScrollTop" ) ;
131
+ const setScrollLeftSpy = spy ( editor , "setScrollLeft" ) ;
132
+ const middleScrollController = editor . registerAndInstantiateContribution ( MiddleScrollController . ID , MiddleScrollController ) ;
133
+
134
+ middleScrollController . startScroll ( 10 , 10 ) ;
135
+ middleScrollController . setCurrent ( 0 , 20 ) ;
136
+ middleScrollController . scrollPane ( ) ;
137
+
138
+ assert . equal ( getActiveWindow ( ) . document . body . getAttribute ( 'data-scroll-direction' ) , 'sw' ) ;
139
+ assert . ok ( setScrollTopSpy . lastCall . calledWithExactly ( 3 ) ) ;
140
+ assert . ok ( setScrollLeftSpy . lastCall . calledWithExactly ( - 2 ) ) ;
141
+
142
+ middleScrollController . dispose ( ) ;
143
+ } ) ;
144
+ } ) ;
145
+ test ( 'w' , ( ) => {
146
+ withTestCodeEditor ( 'test' , { } , ( editor ) => {
147
+ const setScrollTopSpy = spy ( editor , "setScrollTop" ) ;
148
+ const setScrollLeftSpy = spy ( editor , "setScrollLeft" ) ;
149
+ const middleScrollController = editor . registerAndInstantiateContribution ( MiddleScrollController . ID , MiddleScrollController ) ;
150
+
151
+ middleScrollController . startScroll ( 10 , 10 ) ;
152
+ middleScrollController . setCurrent ( 0 , 10 ) ;
153
+ middleScrollController . scrollPane ( ) ;
154
+
155
+ assert . equal ( getActiveWindow ( ) . document . body . getAttribute ( 'data-scroll-direction' ) , 'w' ) ;
156
+ assert . ok ( setScrollTopSpy . lastCall . calledWithExactly ( 0 ) ) ;
157
+ assert . ok ( setScrollLeftSpy . lastCall . calledWithExactly ( - 2 ) ) ;
158
+
159
+ middleScrollController . dispose ( ) ;
160
+ } ) ;
161
+ } ) ;
162
+ test ( 'nw' , ( ) => {
163
+ withTestCodeEditor ( 'test' , { } , ( editor ) => {
164
+ const setScrollTopSpy = spy ( editor , "setScrollTop" ) ;
165
+ const setScrollLeftSpy = spy ( editor , "setScrollLeft" ) ;
166
+ const middleScrollController = editor . registerAndInstantiateContribution ( MiddleScrollController . ID , MiddleScrollController ) ;
167
+
168
+ middleScrollController . startScroll ( 10 , 10 ) ;
169
+ middleScrollController . setCurrent ( 0 , 0 ) ;
170
+ middleScrollController . scrollPane ( ) ;
171
+
172
+ assert . equal ( getActiveWindow ( ) . document . body . getAttribute ( 'data-scroll-direction' ) , 'nw' ) ;
173
+ assert . ok ( setScrollTopSpy . lastCall . calledWithExactly ( - 2 ) ) ;
174
+ assert . ok ( setScrollLeftSpy . lastCall . calledWithExactly ( - 2 ) ) ;
175
+
176
+ middleScrollController . dispose ( ) ;
177
+ } ) ;
178
+ } ) ;
179
+ } ) ;
26
180
} ) ;
0 commit comments