Update tests and fix formatting.

pull/1103/head
Bindu 4 years ago
parent 36c1504c6a
commit a9fddf9963

@ -119,7 +119,7 @@ class NumberButtonViewTest : BaseViewTest() {
fun testClick_shortToggleDisabled() {
prefs.isShortToggleEnabled = false
view.performClick()
assertFalse(edited)
assertTrue(edited)
}
@Test

@ -61,7 +61,7 @@ class PerformanceTest : BaseAndroidTest() {
val habit = fixtures.createEmptyHabit()
for (i in 0..4999) {
val timestamp: Timestamp = Timestamp(i * DAY_LENGTH)
CreateRepetitionCommand(habitList, habit, timestamp, 1).run()
CreateRepetitionCommand(habitList, habit, timestamp, 1, "").run()
}
db.setTransactionSuccessful()
db.endTransaction()

@ -1,10 +1,10 @@
package org.isoron.uhabits.activities.common.dialogs
import androidx.appcompat.app.AlertDialog
import android.content.Context
import android.view.LayoutInflater
import android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE
import android.widget.EditText
import androidx.appcompat.app.AlertDialog
import org.isoron.uhabits.R
import org.isoron.uhabits.core.ui.screens.habits.list.ListHabitsBehavior
import org.isoron.uhabits.inject.ActivityContext

@ -35,7 +35,6 @@ import org.isoron.uhabits.inject.ActivityContext
import org.isoron.uhabits.utils.InterfaceUtils.getDimension
import org.isoron.uhabits.utils.dim
import org.isoron.uhabits.utils.getFontAwesome
import org.isoron.uhabits.utils.showMessage
import org.isoron.uhabits.utils.sres
import java.lang.Double.max
import java.text.DecimalFormat

@ -102,7 +102,8 @@ class LoopDBImporter
for (r in entryRecords) {
val t = Timestamp(r.timestamp!!)
val (_, value, notes) = habit!!.originalEntries.get(t)
if (value != r.value || notes != r.notes) CreateRepetitionCommand(habitList, habit, t, r.value!!, r.notes!!).run()
val oldNotes = r.notes ?: ""
if (value != r.value || notes != oldNotes) CreateRepetitionCommand(habitList, habit, t, r.value!!, oldNotes).run()
}
runner.notifyListeners(command)

@ -51,6 +51,7 @@ class EntryRecord {
}
fun toEntry(): Entry {
return Entry(Timestamp(timestamp!!), value!!, notes!!)
val notes = notes ?: ""
return Entry(Timestamp(timestamp!!), value!!, notes)
}
}

@ -62,10 +62,10 @@ class HistoryCardPresenter(
override fun onDateClicked(date: LocalDate, isLongClick: Boolean) {
val timestamp = Timestamp.fromLocalDate(date)
screen.showFeedback()
if (habit.isNumerical) {
val entries = habit.computedEntries
val oldValue = entries.get(timestamp).value
val notes = entries.get(timestamp).notes
if (habit.isNumerical) {
screen.showNumberPicker(oldValue / 1000.0, habit.unit, notes) { newValue: Double, newNotes: String ->
val thousands = (newValue * 1000).roundToInt()
commandRunner.run(
@ -79,12 +79,9 @@ class HistoryCardPresenter(
)
}
} else {
val entry = habit.computedEntries.get(timestamp)
val currentValue = entry.value
val notes = entry.notes
if (!isLongClick) {
val nextValue = Entry.nextToggleValue(
value = currentValue,
value = oldValue,
isSkipEnabled = preferences.isSkipEnabled,
areQuestionMarksEnabled = preferences.areQuestionMarksEnabled
)
@ -105,7 +102,7 @@ class HistoryCardPresenter(
habitList,
habit,
timestamp,
currentValue,
oldValue,
newNotes,
),
)

@ -37,16 +37,20 @@ class WidgetBehavior @Inject constructor(
) {
fun onAddRepetition(habit: Habit, timestamp: Timestamp?) {
notificationTray.cancel(habit)
setValue(habit, timestamp, Entry.YES_MANUAL)
val entry = habit.originalEntries.get(timestamp!!)
val notes = entry.notes
setValue(habit, timestamp, Entry.YES_MANUAL, notes)
}
fun onRemoveRepetition(habit: Habit, timestamp: Timestamp?) {
notificationTray.cancel(habit)
setValue(habit, timestamp, Entry.NO)
val entry = habit.originalEntries.get(timestamp!!)
val notes = entry.notes
setValue(habit, timestamp, Entry.NO, notes)
}
fun onToggleRepetition(habit: Habit, timestamp: Timestamp) {
val entry = habit.computedEntries.get(timestamp)
val entry = habit.originalEntries.get(timestamp)
val currentValue = entry.value
val notes = entry.notes
val newValue = nextToggleValue(
@ -74,7 +78,7 @@ class WidgetBehavior @Inject constructor(
notificationTray.cancel(habit)
}
fun setValue(habit: Habit, timestamp: Timestamp?, newValue: Int, notes: String = "") {
fun setValue(habit: Habit, timestamp: Timestamp?, newValue: Int, notes: String) {
commandRunner.run(
CreateRepetitionCommand(habitList, habit, timestamp!!, newValue, notes)
)

@ -70,7 +70,7 @@ class HabitCardListCacheTest : BaseUnitTest() {
@Test
fun testCommandListener_single() {
val h2 = habitList.getByPosition(2)
commandRunner.run(CreateRepetitionCommand(habitList, h2, today, Entry.NO))
commandRunner.run(CreateRepetitionCommand(habitList, h2, today, Entry.NO, ""))
verify(listener).onItemChanged(2)
verify(listener).onRefreshFinished()
verifyNoMoreInteractions(listener)

@ -79,7 +79,7 @@ class ListHabitsBehaviorTest : BaseUnitTest() {
@Test
fun testOnEdit() {
behavior.onEdit(habit2, getToday())
verify(screen).showNumberPicker(eq(0.1), eq("miles"), "", picker.capture())
verify(screen).showNumberPicker(eq(0.1), eq("miles"), eq(""), picker.capture())
picker.lastValue.onNumberPicked(100.0, "")
val today = getTodayWithOffset()
assertThat(habit2.computedEntries.get(today).value, equalTo(100000))
@ -160,7 +160,7 @@ class ListHabitsBehaviorTest : BaseUnitTest() {
@Test
fun testOnToggle() {
assertTrue(habit1.isCompletedToday())
behavior.onToggle(habit1, getToday(), Entry.NO, "")
behavior.onToggle(habit1, getToday(), Entry.NO)
assertFalse(habit1.isCompletedToday())
}
}

@ -72,6 +72,10 @@ class HistoryChartTest {
1 -> DIMMED
else -> OFF
}
},
hasNotes = MutableList(85) {
index: Int ->
index % 3 == 0
}
)
@ -86,20 +90,20 @@ class HistoryChartTest {
// Click top left date
view.onClick(20.0, 46.0)
verify(dateClickedListener).onDateClicked(LocalDate(2014, 10, 26))
verify(dateClickedListener).onDateClicked(LocalDate(2014, 10, 26), false)
reset(dateClickedListener)
view.onClick(2.0, 28.0)
verify(dateClickedListener).onDateClicked(LocalDate(2014, 10, 26))
verify(dateClickedListener).onDateClicked(LocalDate(2014, 10, 26), false)
reset(dateClickedListener)
// Click date in the middle
view.onClick(163.0, 113.0)
verify(dateClickedListener).onDateClicked(LocalDate(2014, 12, 10))
verify(dateClickedListener).onDateClicked(LocalDate(2014, 12, 10), false)
reset(dateClickedListener)
// Click today
view.onClick(336.0, 37.0)
verify(dateClickedListener).onDateClicked(LocalDate(2015, 1, 25))
verify(dateClickedListener).onDateClicked(LocalDate(2015, 1, 25), false)
reset(dateClickedListener)
// Click header

@ -58,7 +58,7 @@ class WidgetBehaviorTest : BaseUnitTest() {
fun testOnAddRepetition() {
behavior.onAddRepetition(habit, today)
verify(commandRunner).run(
CreateRepetitionCommand(habitList, habit, today, Entry.YES_MANUAL)
CreateRepetitionCommand(habitList, habit, today, Entry.YES_MANUAL, "")
)
verify(notificationTray).cancel(habit)
verifyZeroInteractions(preferences)
@ -68,7 +68,7 @@ class WidgetBehaviorTest : BaseUnitTest() {
fun testOnRemoveRepetition() {
behavior.onRemoveRepetition(habit, today)
verify(commandRunner).run(
CreateRepetitionCommand(habitList, habit, today, Entry.NO)
CreateRepetitionCommand(habitList, habit, today, Entry.NO, "")
)
verify(notificationTray).cancel(habit)
verifyZeroInteractions(preferences)
@ -94,7 +94,7 @@ class WidgetBehaviorTest : BaseUnitTest() {
behavior.onToggleRepetition(habit, today)
verify(preferences).isSkipEnabled
verify(commandRunner).run(
CreateRepetitionCommand(habitList, habit, today, nextValue)
CreateRepetitionCommand(habitList, habit, today, nextValue, "")
)
verify(notificationTray).cancel(
habit
@ -110,7 +110,7 @@ class WidgetBehaviorTest : BaseUnitTest() {
habit.recompute()
behavior.onIncrement(habit, today, 100)
verify(commandRunner).run(
CreateRepetitionCommand(habitList, habit, today, 600)
CreateRepetitionCommand(habitList, habit, today, 600, "")
)
verify(notificationTray).cancel(habit)
verifyZeroInteractions(preferences)
@ -123,7 +123,7 @@ class WidgetBehaviorTest : BaseUnitTest() {
habit.recompute()
behavior.onDecrement(habit, today, 100)
verify(commandRunner).run(
CreateRepetitionCommand(habitList, habit, today, 400)
CreateRepetitionCommand(habitList, habit, today, 400, "")
)
verify(notificationTray).cancel(habit)
verifyZeroInteractions(preferences)

Loading…
Cancel
Save