Skip to content

Commit

Permalink
Add test to check that position is retained if setup is called multip…
Browse files Browse the repository at this point in the history
…le times.
  • Loading branch information
kizitonwose committed Aug 25, 2019
1 parent b130887 commit 81969e3
Showing 1 changed file with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class CalenderViewTests {

homeScreenRule.runOnUiThread {
// Scroll to a random date
calendarView.scrollToDate( LocalDate.now().plusDays(120))
calendarView.scrollToDate(LocalDate.now().plusDays(120))
}

sleep(2000)
Expand All @@ -280,6 +280,38 @@ class CalenderViewTests {
assertTrue(daysWIthSameDayOfWeekAsLastDay.last() == lastVisibleDay)
}

@Test
fun multipleSetupCallsRetainPositionIfCalendarHasBoundaries() {
onView(withId(R.id.examplesRv)).perform(actionOnItemAtPosition<RecyclerView.ViewHolder>(0, click()))

val calendarView = findFragment(Example1Fragment::class.java).exOneCalendar

val targetVisibleMonth = currentMonth.plusMonths(2)

var targetVisibleCalMonth: CalendarMonth? = null
calendarView.monthScrollListener = { month ->
targetVisibleCalMonth = month
}

homeScreenRule.runOnUiThread {
calendarView.smoothScrollToMonth(targetVisibleMonth)
}

sleep(5000) // Enough time for smooth scrolling animation.

homeScreenRule.runOnUiThread {
calendarView.setup(
targetVisibleMonth.minusMonths(10),
targetVisibleMonth.plusMonths(10),
daysOfWeekFromLocale().first()
)
}

sleep(5000) // Enough time for setup to finish.

assertTrue(calendarView.findFirstVisibleMonth() == targetVisibleCalMonth)
}

private fun <T : Fragment> findFragment(clazz: Class<T>): T {
return homeScreenRule.activity.supportFragmentManager
.findFragmentByTag(clazz.simpleName) as T
Expand Down

0 comments on commit 81969e3

Please sign in to comment.