@@ -26,11 +26,14 @@ import com.duckduckgo.savedsites.api.models.SavedSite.Favorite
26
26
import com.duckduckgo.savedsites.impl.SavedSitesPixelName
27
27
import com.duckduckgo.savedsites.impl.newtab.FavouritesNewTabSectionViewModel.Command.DeleteFavoriteConfirmation
28
28
import com.duckduckgo.savedsites.impl.newtab.FavouritesNewTabSectionViewModel.Command.ShowEditSavedSiteDialog
29
+ import com.duckduckgo.savedsites.impl.newtab.FavouritesNewTabSectionViewModel.SwipeDecision
29
30
import com.duckduckgo.sync.api.engine.SyncEngine
30
31
import com.duckduckgo.sync.api.engine.SyncEngine.SyncTrigger.FEATURE_READ
31
32
import kotlinx.coroutines.flow.flowOf
32
33
import kotlinx.coroutines.test.runTest
34
+ import org.junit.Assert.assertEquals
33
35
import org.junit.Assert.assertFalse
36
+ import org.junit.Assert.assertNull
34
37
import org.junit.Assert.assertTrue
35
38
import org.junit.Before
36
39
import org.junit.Rule
@@ -201,4 +204,78 @@ class FavouritesNewTabSectionViewModelTests {
201
204
202
205
verify(pixel).fire(SavedSitesPixelName .FAVOURITES_LIST_COLLAPSED )
203
206
}
207
+
208
+ @Test
209
+ fun `when onLongPressTriggered then isLongPressActive returns true` () {
210
+ assertFalse(testee.isLongPressActive())
211
+
212
+ testee.onLongPressTriggered()
213
+
214
+ assertTrue(testee.isLongPressActive())
215
+ }
216
+
217
+ @Test
218
+ fun `when onTouchDown then isLongPressActive returns false` () {
219
+ testee.onLongPressTriggered()
220
+ assertTrue(testee.isLongPressActive())
221
+
222
+ testee.onTouchDown(0f , 0f )
223
+
224
+ assertFalse(testee.isLongPressActive())
225
+ }
226
+
227
+ @Test
228
+ fun `when onTouchUp then isLongPressActive returns false` () {
229
+ testee.onLongPressTriggered()
230
+ assertTrue(testee.isLongPressActive())
231
+
232
+ testee.onTouchUp()
233
+
234
+ assertFalse(testee.isLongPressActive())
235
+ }
236
+
237
+ @Test
238
+ fun `when onTouchMove and dx greater than dy and touchSlop then return HORIZONTAL swipe` () {
239
+ testee.onTouchDown(0f , 0f )
240
+
241
+ val decision = testee.onTouchMove(x = 3f , y = 1f , touchSlop = 2 )
242
+
243
+ assertEquals(SwipeDecision .HORIZONTAL , decision)
244
+ }
245
+
246
+ @Test
247
+ fun `when onTouchMove and dy greater than dx and touchSlop then return VERTICAL swipe` () {
248
+ testee.onTouchDown(0f , 0f )
249
+
250
+ val decision = testee.onTouchMove(x = 1f , y = 3f , touchSlop = 2 )
251
+
252
+ assertEquals(SwipeDecision .VERTICAL , decision)
253
+ }
254
+
255
+ @Test
256
+ fun `when onTouchMove and dx and dy are equal and greater than touchSlop then return CANCEL_LONG_PRESS` () {
257
+ testee.onTouchDown(0f , 0f )
258
+
259
+ val decision = testee.onTouchMove(x = 2f , y = 2f , touchSlop = 1 )
260
+
261
+ assertEquals(SwipeDecision .CANCEL_LONG_PRESS , decision)
262
+ }
263
+
264
+ @Test
265
+ fun `when onTouchMove and dx and dy are less than touchSlop then return null` () {
266
+ testee.onTouchDown(0f , 0f )
267
+
268
+ val decision = testee.onTouchMove(x = 1f , y = 1f , touchSlop = 2 )
269
+
270
+ assertNull(decision)
271
+ }
272
+
273
+ @Test
274
+ fun `when onTouchMove and dx and dy and touchSlop are equal then return null` () {
275
+ testee.onTouchDown(0f , 0f )
276
+
277
+ val decision = testee.onTouchMove(x = 1f , y = 1f , touchSlop = 1 )
278
+
279
+ assertNull(decision)
280
+ }
204
281
}
0 commit comments