Skip to content

Commit f9b3dee

Browse files
committed
Add tests
1 parent 7f2efb4 commit f9b3dee

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

saved-sites/saved-sites-impl/src/test/java/com/duckduckgo/savedsites/impl/newtab/FavouritesNewTabSectionViewModelTests.kt

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@ import com.duckduckgo.savedsites.api.models.SavedSite.Favorite
2626
import com.duckduckgo.savedsites.impl.SavedSitesPixelName
2727
import com.duckduckgo.savedsites.impl.newtab.FavouritesNewTabSectionViewModel.Command.DeleteFavoriteConfirmation
2828
import com.duckduckgo.savedsites.impl.newtab.FavouritesNewTabSectionViewModel.Command.ShowEditSavedSiteDialog
29+
import com.duckduckgo.savedsites.impl.newtab.FavouritesNewTabSectionViewModel.SwipeDecision
2930
import com.duckduckgo.sync.api.engine.SyncEngine
3031
import com.duckduckgo.sync.api.engine.SyncEngine.SyncTrigger.FEATURE_READ
3132
import kotlinx.coroutines.flow.flowOf
3233
import kotlinx.coroutines.test.runTest
34+
import org.junit.Assert.assertEquals
3335
import org.junit.Assert.assertFalse
36+
import org.junit.Assert.assertNull
3437
import org.junit.Assert.assertTrue
3538
import org.junit.Before
3639
import org.junit.Rule
@@ -201,4 +204,78 @@ class FavouritesNewTabSectionViewModelTests {
201204

202205
verify(pixel).fire(SavedSitesPixelName.FAVOURITES_LIST_COLLAPSED)
203206
}
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+
}
204281
}

0 commit comments

Comments
 (0)