Skip to content

Commit

Permalink
#140 Start hour of a day option
Browse files Browse the repository at this point in the history
  • Loading branch information
yvolk committed Jan 8, 2025
1 parent 46fea2b commit 5facb07
Show file tree
Hide file tree
Showing 24 changed files with 1,937 additions and 145 deletions.
41 changes: 21 additions & 20 deletions app/src/androidTest/kotlin/org/andstatus/todoagenda/BirthdayTest.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.andstatus.todoagenda

import org.andstatus.todoagenda.prefs.AllDayEventsPlacement
import org.andstatus.todoagenda.prefs.ApplicationPreferences
import org.andstatus.todoagenda.prefs.EndedSomeTimeAgo
import org.andstatus.todoagenda.prefs.dateformat.DateFormatType
import org.andstatus.todoagenda.prefs.dateformat.DateFormatValue
Expand All @@ -21,16 +20,13 @@ class BirthdayTest : BaseWidgetTest() {
val inputs = provider.loadResultsAndSettings(
org.andstatus.todoagenda.test.R.raw.birthday
)
provider.startEditingPreferences()
ApplicationPreferences.setWidgetHeaderDateFormat(
provider.context,
DateFormatValue.of(DateFormatType.CUSTOM, "YYYY-MM-dd")
provider.settings = settings.copy(
widgetHeaderDateFormat = DateFormatValue.of(DateFormatType.CUSTOM, "YYYY-MM-dd"),
allDayEventsPlacement = AllDayEventsPlacement.TOP_DAY,
eventsEnded = EndedSomeTimeAgo.NONE,
showPastEventsWithDefaultColor = false,
eventRange = 30
)
ApplicationPreferences.setAllDayEventsPlacement(provider.context, AllDayEventsPlacement.TOP_DAY)
ApplicationPreferences.setEventsEnded(provider.context, EndedSomeTimeAgo.NONE)
ApplicationPreferences.setShowPastEventsWithDefaultColor(provider.context, false)
ApplicationPreferences.setEventRange(provider.context, 30)
provider.savePreferences()
playAtOneTime(inputs, dateTime(2015, 8, 1, 17, 0), 0)
playAtOneTime(inputs, dateTime(2015, 8, 9, 23, 59), 0)
playAtOneTime(inputs, dateTime(2015, 8, 10, 0, 0).plusMillis(1), 2)
Expand All @@ -43,28 +39,33 @@ class BirthdayTest : BaseWidgetTest() {
playAtOneTime(inputs, dateTime(2015, 9, 9, 23, 30), 2)
playAtOneTime(inputs, dateTime(2015, 9, 10, 0, 30), 0)
playAtOneTime(inputs, dateTime(2015, 9, 10, 11, 0), 0)
ApplicationPreferences.setEventsEnded(provider.context, EndedSomeTimeAgo.ONE_HOUR)
provider.savePreferences()
provider.settings = settings.copy(
eventsEnded = EndedSomeTimeAgo.ONE_HOUR
)
playAtOneTime(inputs, dateTime(2015, 9, 10, 0, 30), 2)
playAtOneTime(inputs, dateTime(2015, 9, 10, 1, 30), 0)
ApplicationPreferences.setEventsEnded(provider.context, EndedSomeTimeAgo.TODAY)
provider.savePreferences()
provider.settings = settings.copy(
eventsEnded = EndedSomeTimeAgo.TODAY
)
playAtOneTime(inputs, dateTime(2015, 9, 10, 1, 30), 0)
ApplicationPreferences.setEventsEnded(provider.context, EndedSomeTimeAgo.FOUR_HOURS)
provider.savePreferences()
provider.settings = settings.copy(
eventsEnded = EndedSomeTimeAgo.FOUR_HOURS
)
playAtOneTime(inputs, dateTime(2015, 9, 10, 1, 30), 2)
playAtOneTime(inputs, dateTime(2015, 9, 10, 3, 59), 2)
playAtOneTime(inputs, dateTime(2015, 9, 10, 4, 0), 0)
ApplicationPreferences.setEventsEnded(provider.context, EndedSomeTimeAgo.YESTERDAY)
provider.savePreferences()
provider.settings = settings.copy(
eventsEnded = EndedSomeTimeAgo.YESTERDAY
)
playAtOneTime(inputs, dateTime(2015, 9, 10, 4, 0), 2)
playAtOneTime(inputs, dateTime(2015, 9, 10, 11, 0), 2)
playAtOneTime(inputs, dateTime(2015, 9, 10, 17, 0), 2)
playAtOneTime(inputs, dateTime(2015, 9, 10, 23, 30), 2)
playAtOneTime(inputs, dateTime(2015, 9, 11, 0, 0), 0)
playAtOneTime(inputs, dateTime(2015, 9, 11, 0, 30), 0)
ApplicationPreferences.setShowPastEventsWithDefaultColor(provider.context, true)
provider.savePreferences()
provider.settings = settings.copy(
showPastEventsWithDefaultColor = true
)
playAtOneTime(inputs, dateTime(2015, 9, 11, 0, 30), 0)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ class DuplicateEventsTest : BaseWidgetTest() {
@Test
fun testIssue354() {
val method = "testIssue354"
val inputs = provider!!.loadResultsAndSettings(
val inputs = provider.loadResultsAndSettings(
org.andstatus.todoagenda.test.R.raw.duplicates
)
provider!!.addResults(inputs)
provider.addResults(inputs)
playResults(method)
Assert.assertEquals("Number of entries", 40, factory.widgetEntries.size.toLong())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.andstatus.todoagenda

import org.andstatus.todoagenda.prefs.ApplicationPreferences
import org.andstatus.todoagenda.widget.DayHeader
import org.andstatus.todoagenda.widget.LastEntry
import org.joda.time.DateTime
Expand All @@ -21,9 +20,7 @@ class MultidayAllDayEventTest : BaseWidgetTest() {
inputs.executedAt.set(now)
provider.addResults(inputs)
val dateRange = 30
provider.startEditingPreferences()
ApplicationPreferences.setEventRange(provider.context, dateRange)
provider.savePreferences()
provider.settings = settings.copy(eventRange = dateRange)
playResults(method)
val today = now.withTimeAtStartOfDay()
val endOfRangeTime = today.plusDays(dateRange)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.andstatus.todoagenda

import org.andstatus.todoagenda.prefs.ApplicationPreferences
import org.andstatus.todoagenda.provider.QueryRow
import org.andstatus.todoagenda.widget.CalendarEntry
import org.junit.Assert
Expand All @@ -21,9 +20,9 @@ class RecurringEventsTest : BaseWidgetTest() {
fun testShowRecurringEvents() {
generateEventInstances()
Assert.assertEquals("Entries: " + factory.widgetEntries.size, 15, countCalendarEntries().toLong())
provider.startEditingPreferences()
ApplicationPreferences.setShowOnlyClosestInstanceOfRecurringEvent(provider.context, true)
provider.savePreferences()
provider.settings = settings.copy(
showOnlyClosestInstanceOfRecurringEvent = true
)
generateEventInstances()
Assert.assertEquals("Entries: " + factory.widgetEntries.size, 1, countCalendarEntries().toLong())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.andstatus.todoagenda

import junit.framework.TestCase.assertEquals
import junit.framework.TestCase.assertTrue
import org.andstatus.todoagenda.provider.QueryResultsStorage
import org.andstatus.todoagenda.widget.CalendarEntry
import org.joda.time.DateTime
import org.joda.time.DateTimeZone
import org.junit.Test

/**
* @author [email protected]
*/
class StartHourOfDayTest : BaseWidgetTest() {
@Test
fun startHourOfDayTest() {
val method = "startHourOfDayTest"
provider.loadResultsAndSettings(org.andstatus.todoagenda.test.R.raw.start_hour_of_day)

assertSplitEvent(method, DateTime(2024, 12, 22, 23, 30, DateTimeZone.UTC))

provider.settings = settings.copy(startHourOfDayIn = 4)
assertSplitEvent(method, DateTime(2024, 12, 23, 3, 30, DateTimeZone.UTC))
}

private fun assertSplitEvent(
methodIn: String,
entryStartDate: DateTime
) {
val method = "$methodIn $entryStartDate"
val inputs: QueryResultsStorage = settings.resultsStorage!!
val thisDay: DateTime = inputs.executedAt.get().withTimeAtStartOfDay()

provider.addResults(inputs)
playResults(method)
val indLastDec22 = factory.widgetEntries.indexOfLast {
it.entryDay == thisDay && it is CalendarEntry
}
assertTrue(
"Should exist Dec 22 entry ${factory.widgetEntries}",
indLastDec22 > 0
)
val lastDec22Entry: CalendarEntry = factory.widgetEntries[indLastDec22] as CalendarEntry
assertEquals(
"Last day entry start date $lastDec22Entry", entryStartDate, lastDec22Entry.event.startDate
)
assertTrue(
"Entry should continue on the next day ${lastDec22Entry.eventTimeString}, $lastDec22Entry",
lastDec22Entry.eventTimeString.endsWith("")
)
val firstDec23Entry: CalendarEntry = factory.widgetEntries[indLastDec22 + 2] as CalendarEntry
assertEquals(
"Next day entry start date $firstDec23Entry", entryStartDate, firstDec23Entry.event.startDate
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class FakeCalendarContentProvider private constructor(val context: Context) {
?: throw java.lang.IllegalStateException("No settings stored")
set(value) {
settingsRef.set(value)
AllSettings.addNew(TAG, context, value)
AllSettings.addOrReplace(TAG, context, value)
}

init {
Expand All @@ -51,10 +51,11 @@ class FakeCalendarContentProvider private constructor(val context: Context) {

fun updateAppSettings(tag: String) {
settings = settings.copy(
logEvents = true,
resultsStorage = results,
snapshotModeIn = SnapshotMode.SNAPSHOT_TIME
)
AllSettings.addNew(tag, context, settings)
AllSettings.addOrReplace(tag, context, settings)
if (results.results.isNotEmpty()) {
Log.d(tag, "Results executed at " + settings.clock.now())
}
Expand Down Expand Up @@ -136,7 +137,8 @@ class FakeCalendarContentProvider private constructor(val context: Context) {
val widgetData = WidgetData.fromJson(json)
settings = widgetData.getSettingsForWidget(
context,
settings, widgetId
settings,
widgetId
)
return settings.resultsStorage ?: throw IllegalStateException("No results storage")
} catch (e: Exception) {
Expand Down
Loading

0 comments on commit 5facb07

Please sign in to comment.