Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finally solved issue #1734 #1766

Merged
merged 4 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,13 @@ abstract class AbstractEventCreationFragment : Fragment() {

private fun onStartDate(bundle: Bundle) {
val newDate = getSelection(bundle)
val daysFromNow = compareWithNowByDay(newDate)
startDateEditText?.setText("")
startDate = null

if (compareWithNowByDay(newDate) < 0) {
// let the comparison go to -1 for cases where the time is just after midnight
// this is handled just fine by computeTimeInSeconds() as an Instant also contains the date
if (daysFromNow < -1) {
showToast(R.string.past_date_not_allowed)
return
}
Expand All @@ -219,7 +222,7 @@ abstract class AbstractEventCreationFragment : Fragment() {
endTimeEditText?.setText("")
}

if (compareWithNowByDay(newDate) == 0) {
if (daysFromNow <= 0) {
computeTimesInSeconds()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import io.reactivex.Completable
import io.reactivex.subjects.BehaviorSubject
import java.text.DateFormat
import java.text.SimpleDateFormat
import java.time.Instant
import java.util.Calendar
import java.util.Locale
import javax.inject.Inject
import org.hamcrest.MatcherAssert
import org.hamcrest.Matchers
import org.junit.Assert
Expand All @@ -54,26 +48,44 @@ import org.mockito.Mock
import org.mockito.Mockito
import org.mockito.junit.MockitoJUnit
import org.mockito.junit.MockitoTestRule
import java.text.DateFormat
import java.text.SimpleDateFormat
import java.time.Instant
import java.util.Calendar
import java.util.Locale
import javax.inject.Inject

@LargeTest
@HiltAndroidTest
@RunWith(AndroidJUnit4::class)
class ElectionSetupFragmentTest {
@Inject lateinit var keyManager: KeyManager
@Inject
lateinit var keyManager: KeyManager

@Inject lateinit var messageHandler: MessageHandler
@Inject
lateinit var messageHandler: MessageHandler

@Inject lateinit var gson: Gson
@Inject
lateinit var gson: Gson

@BindValue @Mock lateinit var repository: LAORepository
@BindValue
@Mock
lateinit var repository: LAORepository

@BindValue @Mock lateinit var globalNetworkManager: GlobalNetworkManager
@BindValue
@Mock
lateinit var globalNetworkManager: GlobalNetworkManager

@Mock lateinit var messageSender: MessageSender
@Mock
lateinit var messageSender: MessageSender

@JvmField @Rule(order = 0) val mockitoRule: MockitoTestRule = MockitoJUnit.testRule(this)
@JvmField
@Rule(order = 0)
val mockitoRule: MockitoTestRule = MockitoJUnit.testRule(this)

@JvmField @Rule(order = 1) val hiltRule = HiltAndroidRule(this)
@JvmField
@Rule(order = 1)
val hiltRule = HiltAndroidRule(this)

@JvmField
@Rule(order = 2)
Expand Down Expand Up @@ -325,7 +337,6 @@ class ElectionSetupFragmentTest {
)
}

// @matteosz: This test will fail if executed between 00:00 and 00:10! TO-FIX
@Test
fun cannotChooseStartTimeTooFarInPast() {
val today = Calendar.getInstance()
Expand All @@ -347,6 +358,27 @@ class ElectionSetupFragmentTest {
EventCreationPageObject.startTimeView().check(ViewAssertions.matches(ViewMatchers.withText("")))
}

@Test
fun cannotChooseStartTimeInPastDay() {
val today = Calendar.getInstance()
today.add(Calendar.MINUTE, -1430)
val year = today[Calendar.YEAR]
val monthOfYear = today[Calendar.MONTH]
val dayOfMonth = today[Calendar.DAY_OF_MONTH]
val hourOfDay = today[Calendar.HOUR_OF_DAY]
val minutes = today[Calendar.MINUTE]

EventCreationPageObject.startDateView().perform(ViewActions.click())
getLastDialog(DatePickerDialog::class.java).updateDate(year, monthOfYear, dayOfMonth)
dialogPositiveButton().performClick()

EventCreationPageObject.startTimeView().perform(ViewActions.click())
getLastDialog(TimePickerDialog::class.java).updateTime(hourOfDay, minutes)
dialogPositiveButton().performClick()

EventCreationPageObject.startTimeView().check(ViewAssertions.matches(ViewMatchers.withText("")))
}

@Test
@Ignore("Not implemented")
fun choosingStartDateInvalidateAStartTimeInPast() {
Expand Down
Loading