Skip to content

Commit

Permalink
revert prev next buttons from change record
Browse files Browse the repository at this point in the history
  • Loading branch information
Razeeman committed Jul 6, 2024
1 parent 76ba03f commit 1b2a72c
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 330 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,17 @@ import com.example.util.simpletimetracker.utils.clickOnRecyclerItem
import com.example.util.simpletimetracker.utils.clickOnView
import com.example.util.simpletimetracker.utils.clickOnViewWithId
import com.example.util.simpletimetracker.utils.clickOnViewWithText
import com.example.util.simpletimetracker.utils.getMillis
import com.example.util.simpletimetracker.utils.scrollRecyclerToView
import com.example.util.simpletimetracker.utils.tryAction
import com.example.util.simpletimetracker.utils.typeTextIntoView
import com.example.util.simpletimetracker.utils.withCardColor
import com.example.util.simpletimetracker.utils.withTag
import dagger.hilt.android.testing.HiltAndroidTest
import java.util.Calendar
import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.Matcher
import org.hamcrest.Matchers
import org.junit.Test
import org.junit.runner.RunWith
import java.util.concurrent.TimeUnit
import java.util.Calendar
import com.example.util.simpletimetracker.core.R as coreR
import com.example.util.simpletimetracker.feature_change_record.R as changeRecordR
import com.example.util.simpletimetracker.feature_dialogs.R as dialogsR
Expand Down Expand Up @@ -525,125 +521,6 @@ class AddRecordTest : BaseUiTest() {
)
}

@Test
fun addRecordPrevNext() {
// Add data
val type1 = "type1"
val type2 = "type2"
val calendar = Calendar.getInstance()

testUtils.addActivity(type1)
testUtils.addActivity(type2)

testUtils.addRecord(
typeName = type1,
timeStarted = calendar.getMillis(hour = 10),
timeEnded = calendar.getMillis(hour = 11),
)
testUtils.addRecord(
typeName = type1,
timeStarted = calendar.getMillis(hour = 12),
timeEnded = calendar.getMillis(hour = 13),
)
testUtils.addRecord(
typeName = type2,
timeStarted = calendar.getMillis(hour = 14),
timeEnded = calendar.getMillis(hour = 15),
)
testUtils.addRecord(
typeName = type1,
timeStarted = calendar.getMillis(hour = 16),
timeEnded = calendar.getMillis(hour = 17),
)
testUtils.addRecord(
typeName = type1,
timeStarted = calendar.getMillis(hour = 18),
timeEnded = calendar.getMillis(hour = 19),
)

NavUtils.openRecordsScreen()
clickOnView(allOf(withText(type2), isCompletelyDisplayed()))

// Check visibility
checkViewIsDisplayed(withId(changeRecordR.id.btnChangeRecordTimeStartedPrev))
checkViewIsDisplayed(withId(changeRecordR.id.btnChangeRecordTimeStartedNext))
checkViewIsDisplayed(withId(changeRecordR.id.btnChangeRecordTimeEndedPrev))
checkViewIsDisplayed(withId(changeRecordR.id.btnChangeRecordTimeEndedNext))

fun checkTimes(started: Int, ended: Int) {
checkAfterTimeAdjustment(
calendar.getMillis(started).formatTime(),
calendar.getMillis(ended).formatTime(),
TimeUnit.HOURS.toMillis(ended.toLong() - started).formatInterval(),
)
}

// Check times
checkTimes(14, 15)

clickOnViewWithId(changeRecordR.id.btnChangeRecordTimeStartedPrev)
checkTimes(13, 15)
clickOnViewWithId(changeRecordR.id.btnChangeRecordTimeStartedPrev)
checkTimes(11, 15)
clickOnViewWithId(changeRecordR.id.btnChangeRecordTimeStartedPrev)
checkViewIsDisplayed(
Matchers.allOf(
withText(coreR.string.change_record_previous_not_found),
withId(com.google.android.material.R.id.snackbar_text),
),
)

clickOnViewWithId(changeRecordR.id.btnChangeRecordTimeStartedNext)
checkTimes(13, 15)
clickOnViewWithId(changeRecordR.id.btnChangeRecordTimeStartedNext)
checkTimes(15, 15)
clickOnViewWithId(changeRecordR.id.btnChangeRecordTimeStartedNext)
checkTimes(17, 17)
clickOnViewWithId(changeRecordR.id.btnChangeRecordTimeStartedNext)
checkTimes(19, 19)
clickOnViewWithId(changeRecordR.id.btnChangeRecordTimeStartedNext)
checkViewIsDisplayed(
Matchers.allOf(
withText(coreR.string.change_record_next_not_found),
withId(com.google.android.material.R.id.snackbar_text),
),
)

clickOnViewWithId(changeRecordR.id.btnChangeRecordTimeEndedPrev)
checkTimes(18, 18)
clickOnViewWithId(changeRecordR.id.btnChangeRecordTimeEndedPrev)
checkTimes(16, 16)
clickOnViewWithId(changeRecordR.id.btnChangeRecordTimeEndedPrev)
checkTimes(14, 14)
clickOnViewWithId(changeRecordR.id.btnChangeRecordTimeEndedPrev)
checkTimes(12, 12)
clickOnViewWithId(changeRecordR.id.btnChangeRecordTimeEndedPrev)
checkTimes(10, 10)
clickOnViewWithId(changeRecordR.id.btnChangeRecordTimeEndedPrev)
checkViewIsDisplayed(
Matchers.allOf(
withText(coreR.string.change_record_previous_not_found),
withId(com.google.android.material.R.id.snackbar_text),
),
)

clickOnViewWithId(changeRecordR.id.btnChangeRecordTimeEndedNext)
checkTimes(10, 12)
clickOnViewWithId(changeRecordR.id.btnChangeRecordTimeEndedNext)
checkTimes(10, 14)
clickOnViewWithId(changeRecordR.id.btnChangeRecordTimeEndedNext)
checkTimes(10, 16)
clickOnViewWithId(changeRecordR.id.btnChangeRecordTimeEndedNext)
checkTimes(10, 18)
clickOnViewWithId(changeRecordR.id.btnChangeRecordTimeEndedNext)
checkViewIsDisplayed(
Matchers.allOf(
withText(coreR.string.change_record_next_not_found),
withId(com.google.android.material.R.id.snackbar_text),
),
)
}

private fun checkAfterTimeAdjustment(
timeStarted: String,
timeEnded: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,14 @@ import com.example.util.simpletimetracker.utils.checkViewIsNotDisplayed
import com.example.util.simpletimetracker.utils.clickOnRecyclerItem
import com.example.util.simpletimetracker.utils.clickOnViewWithId
import com.example.util.simpletimetracker.utils.clickOnViewWithText
import com.example.util.simpletimetracker.utils.getMillis
import com.example.util.simpletimetracker.utils.longClickOnView
import com.example.util.simpletimetracker.utils.tryAction
import com.example.util.simpletimetracker.utils.typeTextIntoView
import com.example.util.simpletimetracker.utils.withCardColor
import com.example.util.simpletimetracker.utils.withTag
import com.google.android.material.R
import dagger.hilt.android.testing.HiltAndroidTest
import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.Matcher
import org.hamcrest.Matchers
import org.hamcrest.Matchers.allOf
import org.junit.Test
import org.junit.runner.RunWith
Expand Down Expand Up @@ -106,11 +102,7 @@ class ChangeRunningRecordTest : BaseUiTest() {
checkViewIsNotDisplayed(withId(changeRecordR.id.rvChangeRecordType))
checkViewIsNotDisplayed(withId(changeRecordR.id.rvChangeRecordCategories))
checkViewIsDisplayed(withId(changeRecordR.id.containerChangeRecordTimeStartedAdjust))
checkViewIsDisplayed(withId(changeRecordR.id.btnChangeRecordTimeStartedPrev))
checkViewIsDisplayed(withId(changeRecordR.id.btnChangeRecordTimeStartedNext))
checkViewIsNotDisplayed(withId(changeRecordR.id.containerChangeRecordTimeEndedAdjust))
checkViewIsNotDisplayed(withId(changeRecordR.id.btnChangeRecordTimeEndedPrev))
checkViewIsNotDisplayed(withId(changeRecordR.id.btnChangeRecordTimeEndedNext))
checkViewIsNotDisplayed(allOf(withId(changeRecordR.id.etChangeRecordComment), withText("")))
checkViewIsDisplayed(allOf(withId(changeRecordR.id.tvChangeRecordTimeStartedDate), withText(timeStarted.date)))
checkViewIsDisplayed(allOf(withId(changeRecordR.id.tvChangeRecordTimeStartedTime), withText(timeStarted.time)))
Expand Down Expand Up @@ -316,75 +308,6 @@ class ChangeRunningRecordTest : BaseUiTest() {
)
}

@Test
fun changeRunningRecordPrevNext() {
// Add data
val type1 = "type1"
val type2 = "type2"
val calendar = Calendar.getInstance()
.apply { add(Calendar.DATE, -1) }

testUtils.addActivity(type1)
testUtils.addActivity(type2)

testUtils.addRecord(
typeName = type1,
timeStarted = calendar.getMillis(hour = 10),
timeEnded = calendar.getMillis(hour = 11),
)
testUtils.addRecord(
typeName = type1,
timeStarted = calendar.getMillis(hour = 12),
timeEnded = calendar.getMillis(hour = 13),
)
testUtils.addRecord(
typeName = type1,
timeStarted = calendar.getMillis(hour = 14),
timeEnded = calendar.getMillis(hour = 15),
)

Thread.sleep(1000)
tryAction { clickOnViewWithText(type2) }
longClickOnView(allOf(isDescendantOfA(withId(changeRecordR.id.viewRunningRecordItem)), withText(type2)))

// Check visibility
checkViewIsDisplayed(withId(changeRecordR.id.btnChangeRecordTimeStartedPrev))
checkViewIsDisplayed(withId(changeRecordR.id.btnChangeRecordTimeStartedNext))
checkViewIsNotDisplayed(withId(changeRecordR.id.btnChangeRecordTimeEndedPrev))
checkViewIsNotDisplayed(withId(changeRecordR.id.btnChangeRecordTimeEndedNext))

fun checkTimes(started: Int) {
checkAfterTimeAdjustment(calendar.getMillis(started).formatTime())
}

// Check times
clickOnViewWithId(changeRecordR.id.btnChangeRecordTimeStartedPrev)
checkTimes(15)
clickOnViewWithId(changeRecordR.id.btnChangeRecordTimeStartedPrev)
checkTimes(13)
clickOnViewWithId(changeRecordR.id.btnChangeRecordTimeStartedPrev)
checkTimes(11)
clickOnViewWithId(changeRecordR.id.btnChangeRecordTimeStartedPrev)
checkViewIsDisplayed(
allOf(
withText(coreR.string.change_record_previous_not_found),
withId(R.id.snackbar_text),
),
)

clickOnViewWithId(changeRecordR.id.btnChangeRecordTimeStartedNext)
checkTimes(13)
clickOnViewWithId(changeRecordR.id.btnChangeRecordTimeStartedNext)
checkTimes(15)
clickOnViewWithId(changeRecordR.id.btnChangeRecordTimeStartedNext)
checkViewIsDisplayed(
allOf(
withText(coreR.string.change_record_next_not_found),
withId(R.id.snackbar_text),
),
)
}

@Test
fun lastComments() {
val nameNoComments = "Name1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,6 @@ class ChangeRecordCore(
fieldChangeRecordAction.setOnClick(viewModel::onActionChooserClick)
fieldChangeRecordTimeStarted.setOnClick(viewModel::onTimeStartedClick)
fieldChangeRecordTimeEnded.setOnClick(viewModel::onTimeEndedClick)
btnChangeRecordTimeStartedPrev.setOnClick(viewModel::onTimeStartedPrevClick)
btnChangeRecordTimeStartedNext.setOnClick(viewModel::onTimeStartedNextClick)
btnChangeRecordTimeEndedPrev.setOnClick(viewModel::onTimeEndedPrevClick)
btnChangeRecordTimeEndedNext.setOnClick(viewModel::onTimeEndedNextClick)
fieldChangeRecordTimeSplit.setOnClick(viewModel::onTimeSplitClick)
containerChangeRecordTimeStartedAdjust.listener = viewModel::onAdjustTimeStartedItemClick
containerChangeRecordTimeEndedAdjust.listener = viewModel::onAdjustTimeEndedItemClick
Expand Down Expand Up @@ -374,8 +370,6 @@ class ChangeRecordCore(
binding: ChangeRecordCoreLayoutBinding,
) {
binding.fieldChangeRecordTimeEnded.isVisible = isVisible
binding.btnChangeRecordTimeEndedPrev.isVisible = isVisible
binding.btnChangeRecordTimeEndedNext.isVisible = isVisible
binding.containerChangeRecordTimeEndedAdjust.isVisible = isVisible

binding.fieldChangeRecordChangeCurrentPreviewTimeEnded.isVisible = isVisible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,42 +223,6 @@ abstract class ChangeRecordBaseViewModel(
onTimeClick(tag = TIME_SPLIT_TAG, timestamp = newTimeSplit)
}

fun onTimeStartedPrevClick() = viewModelScope.launch {
recordInteractor.getPrevTimeEnded(newTimeStarted)?.let {
newTimeStarted = it
onTimeStartedChanged()
} ?: run {
showMessage(R.string.change_record_previous_not_found)
}
}

fun onTimeStartedNextClick() = viewModelScope.launch {
recordInteractor.getNextTimeEnded(newTimeStarted)?.let {
newTimeStarted = it
onTimeStartedChanged()
} ?: run {
showMessage(R.string.change_record_next_not_found)
}
}

fun onTimeEndedPrevClick() = viewModelScope.launch {
recordInteractor.getPrevTimeStarted(newTimeEnded)?.let {
newTimeEnded = it
onTimeEndedChanged()
} ?: run {
showMessage(R.string.change_record_previous_not_found)
}
}

fun onTimeEndedNextClick() = viewModelScope.launch {
recordInteractor.getNextTimeStarted(newTimeEnded)?.let {
newTimeEnded = it
onTimeEndedChanged()
} ?: run {
showMessage(R.string.change_record_next_not_found)
}
}

fun onSaveClick() {
onRecordChangeButtonClick(
onProceed = ::onSaveClickDelegate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,17 @@ class ChangeRecordViewModel @Inject constructor(
return timeMapper.toTimestampShifted(daysFromToday, RangeLength.Day)
}

private fun getInitialTimeStarted(): Long {
return newTimeEnded - ONE_HOUR
private suspend fun getInitialTimeStarted(daysFromToday: Int): Long {
val default = newTimeEnded - ONE_HOUR

return if (daysFromToday == 0) {
recordInteractor.getPrev(newTimeEnded)
.firstOrNull()
?.timeEnded
?: default
} else {
default
}
}

override suspend fun updatePreview() {
Expand All @@ -245,7 +254,7 @@ class ChangeRecordViewModel @Inject constructor(
is ChangeRecordParams.New -> {
val daysFromToday = (extra as ChangeRecordParams.New).daysFromToday
newTimeEnded = getInitialTimeEnded(daysFromToday)
newTimeStarted = getInitialTimeStarted()
newTimeStarted = getInitialTimeStarted(daysFromToday)
}
}
newTimeSplit = newTimeStarted
Expand Down
Loading

0 comments on commit 1b2a72c

Please sign in to comment.