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() { fun testClick_shortToggleDisabled() {
prefs.isShortToggleEnabled = false prefs.isShortToggleEnabled = false
view.performClick() view.performClick()
assertFalse(edited) assertTrue(edited)
} }
@Test @Test

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

@ -1,10 +1,10 @@
package org.isoron.uhabits.activities.common.dialogs package org.isoron.uhabits.activities.common.dialogs
import androidx.appcompat.app.AlertDialog
import android.content.Context import android.content.Context
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE import android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE
import android.widget.EditText import android.widget.EditText
import androidx.appcompat.app.AlertDialog
import org.isoron.uhabits.R import org.isoron.uhabits.R
import org.isoron.uhabits.core.ui.screens.habits.list.ListHabitsBehavior import org.isoron.uhabits.core.ui.screens.habits.list.ListHabitsBehavior
import org.isoron.uhabits.inject.ActivityContext 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.InterfaceUtils.getDimension
import org.isoron.uhabits.utils.dim import org.isoron.uhabits.utils.dim
import org.isoron.uhabits.utils.getFontAwesome import org.isoron.uhabits.utils.getFontAwesome
import org.isoron.uhabits.utils.showMessage
import org.isoron.uhabits.utils.sres import org.isoron.uhabits.utils.sres
import java.lang.Double.max import java.lang.Double.max
import java.text.DecimalFormat import java.text.DecimalFormat

@ -102,7 +102,8 @@ class LoopDBImporter
for (r in entryRecords) { for (r in entryRecords) {
val t = Timestamp(r.timestamp!!) val t = Timestamp(r.timestamp!!)
val (_, value, notes) = habit!!.originalEntries.get(t) 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) runner.notifyListeners(command)

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

@ -56,7 +56,7 @@ open class ListHabitsBehavior @Inject constructor(
oldValue / 1000, oldValue / 1000,
habit.unit, habit.unit,
notes notes
) { newValue: Double, newNotes:String, -> ) { newValue: Double, newNotes: String, ->
val value = (newValue * 1000).roundToInt() val value = (newValue * 1000).roundToInt()
commandRunner.run(CreateRepetitionCommand(habitList, habit, timestamp, value, newNotes)) commandRunner.run(CreateRepetitionCommand(habitList, habit, timestamp, value, newNotes))
} }

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

@ -37,16 +37,20 @@ class WidgetBehavior @Inject constructor(
) { ) {
fun onAddRepetition(habit: Habit, timestamp: Timestamp?) { fun onAddRepetition(habit: Habit, timestamp: Timestamp?) {
notificationTray.cancel(habit) 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?) { fun onRemoveRepetition(habit: Habit, timestamp: Timestamp?) {
notificationTray.cancel(habit) 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) { fun onToggleRepetition(habit: Habit, timestamp: Timestamp) {
val entry = habit.computedEntries.get(timestamp) val entry = habit.originalEntries.get(timestamp)
val currentValue = entry.value val currentValue = entry.value
val notes = entry.notes val notes = entry.notes
val newValue = nextToggleValue( val newValue = nextToggleValue(
@ -74,7 +78,7 @@ class WidgetBehavior @Inject constructor(
notificationTray.cancel(habit) 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( commandRunner.run(
CreateRepetitionCommand(habitList, habit, timestamp!!, newValue, notes) CreateRepetitionCommand(habitList, habit, timestamp!!, newValue, notes)
) )

@ -70,7 +70,7 @@ class HabitCardListCacheTest : BaseUnitTest() {
@Test @Test
fun testCommandListener_single() { fun testCommandListener_single() {
val h2 = habitList.getByPosition(2) 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).onItemChanged(2)
verify(listener).onRefreshFinished() verify(listener).onRefreshFinished()
verifyNoMoreInteractions(listener) verifyNoMoreInteractions(listener)

@ -79,7 +79,7 @@ class ListHabitsBehaviorTest : BaseUnitTest() {
@Test @Test
fun testOnEdit() { fun testOnEdit() {
behavior.onEdit(habit2, getToday()) 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, "") picker.lastValue.onNumberPicked(100.0, "")
val today = getTodayWithOffset() val today = getTodayWithOffset()
assertThat(habit2.computedEntries.get(today).value, equalTo(100000)) assertThat(habit2.computedEntries.get(today).value, equalTo(100000))
@ -160,7 +160,7 @@ class ListHabitsBehaviorTest : BaseUnitTest() {
@Test @Test
fun testOnToggle() { fun testOnToggle() {
assertTrue(habit1.isCompletedToday()) assertTrue(habit1.isCompletedToday())
behavior.onToggle(habit1, getToday(), Entry.NO, "") behavior.onToggle(habit1, getToday(), Entry.NO)
assertFalse(habit1.isCompletedToday()) assertFalse(habit1.isCompletedToday())
} }
} }

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

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

Loading…
Cancel
Save