From 81969e3cd89bf742b75c60a93d16c26344d64833 Mon Sep 17 00:00:00 2001 From: Kizito Nwose Date: Sun, 25 Aug 2019 14:03:24 +0100 Subject: [PATCH] Add test to check that position is retained if setup is called multiple times. --- .../calenderviewsample/CalenderViewTests.kt | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/sample/src/androidTest/java/com/kizitonwose/calenderviewsample/CalenderViewTests.kt b/sample/src/androidTest/java/com/kizitonwose/calenderviewsample/CalenderViewTests.kt index aa994953..3105a756 100644 --- a/sample/src/androidTest/java/com/kizitonwose/calenderviewsample/CalenderViewTests.kt +++ b/sample/src/androidTest/java/com/kizitonwose/calenderviewsample/CalenderViewTests.kt @@ -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) @@ -280,6 +280,38 @@ class CalenderViewTests { assertTrue(daysWIthSameDayOfWeekAsLastDay.last() == lastVisibleDay) } + @Test + fun multipleSetupCallsRetainPositionIfCalendarHasBoundaries() { + onView(withId(R.id.examplesRv)).perform(actionOnItemAtPosition(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 findFragment(clazz: Class): T { return homeScreenRule.activity.supportFragmentManager .findFragmentByTag(clazz.simpleName) as T