comboctl-main: Check for unchanging screen type in navigateToRTScreen()
Signed-off-by: Carlos Rafael Giani <crg7475@mailbox.org>
This commit is contained in:
parent
5aeb401cc0
commit
605fe04d74
2 changed files with 55 additions and 0 deletions
|
@ -986,6 +986,7 @@ suspend fun navigateToRTScreen(
|
|||
var cycleCount = 0
|
||||
val pathIt = path.iterator()
|
||||
var nextPathItem = pathIt.next()
|
||||
var previousScreenType: KClassifier? = null
|
||||
while (true) {
|
||||
if (cycleCount >= rtNavigationContext.maxNumCycleAttempts)
|
||||
throw CouldNotFindRTScreenException(targetScreenType)
|
||||
|
@ -993,6 +994,16 @@ suspend fun navigateToRTScreen(
|
|||
val parsedDisplayFrame = rtNavigationContext.getParsedDisplayFrame(filterDuplicates = true) ?: continue
|
||||
val parsedScreen = parsedDisplayFrame.parsedScreen
|
||||
|
||||
// Check if we got the same screen with different content, for example
|
||||
// when remaining TBR duration is shown on the main screen and the
|
||||
// duration happens to change during this loop. If this occurs,
|
||||
// skip the redundant screen.
|
||||
if ((previousScreenType != null) && (previousScreenType == parsedScreen::class)) {
|
||||
logger(LogLevel.DEBUG) { "Got a screen of the same type ${parsedScreen::class}; skipping" }
|
||||
continue
|
||||
}
|
||||
previousScreenType = parsedScreen::class
|
||||
|
||||
// A path item's targetNodeValue is the screen type we are trying
|
||||
// to reach, and the edgeValue is the RT button to press to reach it.
|
||||
// We stay at the same path item until we reach the screen type that
|
||||
|
|
|
@ -597,6 +597,50 @@ class RTNavigationTest {
|
|||
assertContentEquals(expectedShortRTButtonPressSequence, rtNavigationContext.shortPressedRTButtons)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun checkRTNavigationFromMainToQuickinfoWithChangingRemainingTbrDuration() {
|
||||
// Check that RT screen navigation skips a newly received screen
|
||||
// if it is of the same type as the previously observed screen.
|
||||
// This typically happens because a quantity like the remaining
|
||||
// TBR duration changes on screen. The navigation code has to
|
||||
// check that the _type_ of the screen changed, and if not, it
|
||||
// must skip the screen. Here, we simulate a main TBR screen
|
||||
// whose remaining TBR duration changes. We expect the navigation
|
||||
// code to detect this and press CHECK just _once_ (because the
|
||||
// second TBR main screen is skipped by the detection). Without
|
||||
// the screen type check, it would press CHECK _twice_.
|
||||
|
||||
val rtNavigationContext = TestRTNavigationContext(listOf(
|
||||
ParsedScreen.MainScreen(MainScreenContent.Tbr(
|
||||
currentTime = LocalDateTime(year = 2020, monthNumber = 10, dayOfMonth = 4, hour = 0, minute = 0),
|
||||
remainingTbrDurationInMinutes = 28,
|
||||
tbrPercentage = 110,
|
||||
activeBasalProfileNumber = 1,
|
||||
currentBasalRateFactor = 300,
|
||||
batteryState = BatteryState.FULL_BATTERY
|
||||
)),
|
||||
ParsedScreen.MainScreen(MainScreenContent.Tbr(
|
||||
currentTime = LocalDateTime(year = 2020, monthNumber = 10, dayOfMonth = 4, hour = 0, minute = 0),
|
||||
remainingTbrDurationInMinutes = 27,
|
||||
tbrPercentage = 110,
|
||||
activeBasalProfileNumber = 1,
|
||||
currentBasalRateFactor = 300,
|
||||
batteryState = BatteryState.FULL_BATTERY
|
||||
)),
|
||||
ParsedScreen.QuickinfoMainScreen(Quickinfo(availableUnits = 105, reservoirState = ReservoirState.FULL))
|
||||
))
|
||||
|
||||
runBlockingWithWatchdog(6000) {
|
||||
navigateToRTScreen(rtNavigationContext, ParsedScreen.QuickinfoMainScreen::class, isComboStopped = false)
|
||||
}
|
||||
|
||||
val expectedShortRTButtonPressSequence = listOf(
|
||||
RTNavigationButton.CHECK
|
||||
)
|
||||
|
||||
assertContentEquals(expectedShortRTButtonPressSequence, rtNavigationContext.shortPressedRTButtons)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun checkLongPressRTButtonUntil() {
|
||||
// Test long RT button presses by simulating transitions
|
||||
|
|
Loading…
Reference in a new issue