|
|
|
|
@ -15,14 +15,6 @@ import org.tasks.data.Alarm.Companion.TYPE_SNOOZE
|
|
|
|
|
import org.tasks.date.DateTimeUtils.newDateTime
|
|
|
|
|
import org.tasks.injection.InjectingTestCase
|
|
|
|
|
import org.tasks.injection.ProductionModule
|
|
|
|
|
import org.tasks.makers.GeofenceMaker.ARRIVAL
|
|
|
|
|
import org.tasks.makers.GeofenceMaker.DEPARTURE
|
|
|
|
|
import org.tasks.makers.GeofenceMaker.PLACE
|
|
|
|
|
import org.tasks.makers.GeofenceMaker.TASK
|
|
|
|
|
import org.tasks.makers.GeofenceMaker.newGeofence
|
|
|
|
|
import org.tasks.makers.PlaceMaker.LATITUDE
|
|
|
|
|
import org.tasks.makers.PlaceMaker.LONGITUDE
|
|
|
|
|
import org.tasks.makers.PlaceMaker.newPlace
|
|
|
|
|
import org.tasks.makers.TaskMaker.COMPLETION_TIME
|
|
|
|
|
import org.tasks.makers.TaskMaker.DELETION_TIME
|
|
|
|
|
import org.tasks.makers.TaskMaker.DUE_TIME
|
|
|
|
|
@ -40,7 +32,7 @@ class LocationDaoTest : InjectingTestCase() {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun getExistingPlace() = runBlocking {
|
|
|
|
|
locationDao.insert(newPlace(with(LATITUDE, 48.067222), with(LONGITUDE, 12.863611)))
|
|
|
|
|
locationDao.insert(Place(latitude = 48.067222, longitude = 12.863611))
|
|
|
|
|
val place = locationDao.findPlace(48.067222.toLikeString(), 12.863611.toLikeString())
|
|
|
|
|
assertEquals(48.067222, place?.latitude)
|
|
|
|
|
assertEquals(12.863611, place?.longitude)
|
|
|
|
|
@ -48,7 +40,7 @@ class LocationDaoTest : InjectingTestCase() {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun getPlaceWithLessPrecision() = runBlocking {
|
|
|
|
|
locationDao.insert(newPlace(with(LATITUDE, 50.7547), with(LONGITUDE, -2.2279)))
|
|
|
|
|
locationDao.insert(Place(latitude = 50.7547, longitude = -2.2279))
|
|
|
|
|
val place = locationDao.findPlace(50.754712.toLikeString(), (-2.227945).toLikeString())
|
|
|
|
|
assertEquals(50.7547, place?.latitude)
|
|
|
|
|
assertEquals(-2.2279, place?.longitude)
|
|
|
|
|
@ -56,7 +48,7 @@ class LocationDaoTest : InjectingTestCase() {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun getPlaceWithMorePrecision() = runBlocking {
|
|
|
|
|
locationDao.insert(newPlace(with(LATITUDE, 36.246944), with(LONGITUDE, -116.816944)))
|
|
|
|
|
locationDao.insert(Place(latitude = 36.246944, longitude = -116.816944))
|
|
|
|
|
locationDao.getPlaces().forEach { println(it) }
|
|
|
|
|
val place = locationDao.findPlace(36.2469.toLikeString(), (-116.8169).toLikeString())
|
|
|
|
|
assertEquals(36.246944, place?.latitude)
|
|
|
|
|
@ -65,20 +57,20 @@ class LocationDaoTest : InjectingTestCase() {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun noActiveGeofences() = runBlocking {
|
|
|
|
|
val place = newPlace()
|
|
|
|
|
val place = Place()
|
|
|
|
|
locationDao.insert(place)
|
|
|
|
|
taskDao.createNew(newTask(with(ID, 1)))
|
|
|
|
|
locationDao.insert(newGeofence(with(TASK, 1), with(PLACE, place.uid)))
|
|
|
|
|
locationDao.insert(Geofence(task = 1, place = place.uid))
|
|
|
|
|
|
|
|
|
|
assertNull(locationDao.getGeofencesByPlace(place.uid!!))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun activeArrivalGeofence() = runBlocking {
|
|
|
|
|
val place = newPlace()
|
|
|
|
|
val place = Place()
|
|
|
|
|
locationDao.insert(place)
|
|
|
|
|
taskDao.createNew(newTask(with(ID, 1)))
|
|
|
|
|
locationDao.insert(newGeofence(with(TASK, 1), with(PLACE, place.uid), with(ARRIVAL, true)))
|
|
|
|
|
locationDao.insert(Geofence(task = 1, place = place.uid, isArrival = true))
|
|
|
|
|
|
|
|
|
|
val geofence = locationDao.getGeofencesByPlace(place.uid!!)
|
|
|
|
|
|
|
|
|
|
@ -88,10 +80,10 @@ class LocationDaoTest : InjectingTestCase() {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun activeDepartureGeofence() = runBlocking {
|
|
|
|
|
val place = newPlace()
|
|
|
|
|
val place = Place()
|
|
|
|
|
locationDao.insert(place)
|
|
|
|
|
taskDao.createNew(newTask(with(ID, 1)))
|
|
|
|
|
locationDao.insert(newGeofence(with(TASK, 1), with(PLACE, place.uid), with(DEPARTURE, true)))
|
|
|
|
|
locationDao.insert(Geofence(task = 1, place = place.uid, isDeparture = true))
|
|
|
|
|
|
|
|
|
|
val geofence = locationDao.getGeofencesByPlace(place.uid!!)
|
|
|
|
|
|
|
|
|
|
@ -101,20 +93,20 @@ class LocationDaoTest : InjectingTestCase() {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun geofenceInactiveForCompletedTask() = runBlocking {
|
|
|
|
|
val place = newPlace()
|
|
|
|
|
val place = Place()
|
|
|
|
|
locationDao.insert(place)
|
|
|
|
|
taskDao.createNew(newTask(with(ID, 1), with(COMPLETION_TIME, newDateTime())))
|
|
|
|
|
locationDao.insert(newGeofence(with(TASK, 1), with(PLACE, place.uid), with(ARRIVAL, true)))
|
|
|
|
|
locationDao.insert(Geofence(task = 1, place = place.uid, isArrival = true))
|
|
|
|
|
|
|
|
|
|
assertNull(locationDao.getGeofencesByPlace(place.uid!!))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun geofenceInactiveForDeletedTask() = runBlocking {
|
|
|
|
|
val place = newPlace()
|
|
|
|
|
val place = Place()
|
|
|
|
|
locationDao.insert(place)
|
|
|
|
|
taskDao.createNew(newTask(with(ID, 1), with(DELETION_TIME, newDateTime())))
|
|
|
|
|
locationDao.insert(newGeofence(with(TASK, 1), with(PLACE, place.uid), with(ARRIVAL, true)))
|
|
|
|
|
locationDao.insert(Geofence(task = 1, place = place.uid, isArrival = true))
|
|
|
|
|
|
|
|
|
|
assertNull(locationDao.getGeofencesByPlace(place.uid!!))
|
|
|
|
|
}
|
|
|
|
|
@ -122,11 +114,11 @@ class LocationDaoTest : InjectingTestCase() {
|
|
|
|
|
@Test
|
|
|
|
|
fun ignoreArrivalForSnoozedTask() = runBlocking {
|
|
|
|
|
freezeAt(now()).thawAfter {
|
|
|
|
|
val place = newPlace()
|
|
|
|
|
val place = Place()
|
|
|
|
|
locationDao.insert(place)
|
|
|
|
|
val task = taskDao.createNew(newTask())
|
|
|
|
|
alarmDao.insert(Alarm(task, newDateTime().plusMinutes(15).millis, TYPE_SNOOZE))
|
|
|
|
|
locationDao.insert(newGeofence(with(TASK, task), with(PLACE, place.uid), with(ARRIVAL, true)))
|
|
|
|
|
locationDao.insert(Geofence(task = task, place = place.uid, isArrival = true))
|
|
|
|
|
|
|
|
|
|
assertTrue(locationDao.getArrivalGeofences(place.uid!!, now()).isEmpty())
|
|
|
|
|
}
|
|
|
|
|
@ -135,11 +127,11 @@ class LocationDaoTest : InjectingTestCase() {
|
|
|
|
|
@Test
|
|
|
|
|
fun ignoreDepartureForSnoozedTask() = runBlocking {
|
|
|
|
|
freezeAt(now()).thawAfter {
|
|
|
|
|
val place = newPlace()
|
|
|
|
|
val place = Place()
|
|
|
|
|
locationDao.insert(place)
|
|
|
|
|
val task = taskDao.createNew(newTask())
|
|
|
|
|
alarmDao.insert(Alarm(task, newDateTime().plusMinutes(15).millis, TYPE_SNOOZE))
|
|
|
|
|
locationDao.insert(newGeofence(with(TASK, task), with(PLACE, place.uid), with(DEPARTURE, true)))
|
|
|
|
|
locationDao.insert(Geofence(task = task, place = place.uid, isDeparture = true))
|
|
|
|
|
|
|
|
|
|
assertTrue(locationDao.getDepartureGeofences(place.uid!!, now()).isEmpty())
|
|
|
|
|
}
|
|
|
|
|
@ -148,12 +140,12 @@ class LocationDaoTest : InjectingTestCase() {
|
|
|
|
|
@Test
|
|
|
|
|
fun getArrivalWithElapsedSnooze() = runBlocking {
|
|
|
|
|
freezeAt(now()).thawAfter {
|
|
|
|
|
val place = newPlace()
|
|
|
|
|
val place = Place()
|
|
|
|
|
locationDao.insert(place)
|
|
|
|
|
val task = taskDao.createNew(newTask())
|
|
|
|
|
alarmDao.insert(Alarm(task, newDateTime().minusMinutes(15).millis, TYPE_SNOOZE))
|
|
|
|
|
val geofence = newGeofence(with(TASK, task), with(PLACE, place.uid), with(ARRIVAL, true))
|
|
|
|
|
geofence.id = locationDao.insert(geofence)
|
|
|
|
|
val geofence = Geofence(task = task, place = place.uid, isArrival = true)
|
|
|
|
|
.let { it.copy(id = locationDao.insert(it)) }
|
|
|
|
|
|
|
|
|
|
assertEquals(listOf(geofence), locationDao.getArrivalGeofences(place.uid!!, now()))
|
|
|
|
|
}
|
|
|
|
|
@ -162,12 +154,12 @@ class LocationDaoTest : InjectingTestCase() {
|
|
|
|
|
@Test
|
|
|
|
|
fun getDepartureWithElapsedSnooze() = runBlocking {
|
|
|
|
|
freezeAt(now()).thawAfter {
|
|
|
|
|
val place = newPlace()
|
|
|
|
|
val place = Place()
|
|
|
|
|
locationDao.insert(place)
|
|
|
|
|
val task = taskDao.createNew(newTask())
|
|
|
|
|
alarmDao.insert(Alarm(task, newDateTime().minusMinutes(15).millis, TYPE_SNOOZE))
|
|
|
|
|
val geofence = newGeofence(with(TASK, task), with(PLACE, place.uid), with(DEPARTURE, true))
|
|
|
|
|
geofence.id = locationDao.insert(geofence)
|
|
|
|
|
val geofence = Geofence(task = task, place = place.uid, isDeparture = true)
|
|
|
|
|
.let { it.copy(id = locationDao.insert(it)) }
|
|
|
|
|
|
|
|
|
|
assertEquals(listOf(geofence), locationDao.getDepartureGeofences(place.uid!!, now()))
|
|
|
|
|
}
|
|
|
|
|
@ -176,13 +168,13 @@ class LocationDaoTest : InjectingTestCase() {
|
|
|
|
|
@Test
|
|
|
|
|
fun ignoreArrivalForHiddenTask() = runBlocking {
|
|
|
|
|
freezeAt(now()).thawAfter {
|
|
|
|
|
val place = newPlace()
|
|
|
|
|
val place = Place()
|
|
|
|
|
locationDao.insert(place)
|
|
|
|
|
taskDao.createNew(newTask(
|
|
|
|
|
with(ID, 1),
|
|
|
|
|
with(DUE_TIME, newDateTime().plusMinutes(15)),
|
|
|
|
|
with(HIDE_TYPE, Task.HIDE_UNTIL_DUE_TIME)))
|
|
|
|
|
locationDao.insert(newGeofence(with(TASK, 1), with(PLACE, place.uid), with(ARRIVAL, true)))
|
|
|
|
|
locationDao.insert(Geofence(task = 1, place = place.uid, isArrival = true))
|
|
|
|
|
|
|
|
|
|
assertTrue(locationDao.getArrivalGeofences(place.uid!!, now()).isEmpty())
|
|
|
|
|
}
|
|
|
|
|
@ -191,13 +183,13 @@ class LocationDaoTest : InjectingTestCase() {
|
|
|
|
|
@Test
|
|
|
|
|
fun ignoreDepartureForHiddenTask() = runBlocking {
|
|
|
|
|
freezeAt(now()).thawAfter {
|
|
|
|
|
val place = newPlace()
|
|
|
|
|
val place = Place()
|
|
|
|
|
locationDao.insert(place)
|
|
|
|
|
taskDao.createNew(newTask(
|
|
|
|
|
with(ID, 1),
|
|
|
|
|
with(DUE_TIME, newDateTime().plusMinutes(15)),
|
|
|
|
|
with(HIDE_TYPE, Task.HIDE_UNTIL_DUE_TIME)))
|
|
|
|
|
locationDao.insert(newGeofence(with(TASK, 1), with(PLACE, place.uid), with(DEPARTURE, true)))
|
|
|
|
|
locationDao.insert(Geofence(task = 1, place = place.uid, isDeparture = true))
|
|
|
|
|
|
|
|
|
|
assertTrue(locationDao.getDepartureGeofences(place.uid!!, now()).isEmpty())
|
|
|
|
|
}
|
|
|
|
|
@ -206,14 +198,16 @@ class LocationDaoTest : InjectingTestCase() {
|
|
|
|
|
@Test
|
|
|
|
|
fun getArrivalWithElapsedHideUntil() = runBlocking {
|
|
|
|
|
freezeAt(now()).thawAfter {
|
|
|
|
|
val place = newPlace()
|
|
|
|
|
val place = Place()
|
|
|
|
|
locationDao.insert(place)
|
|
|
|
|
taskDao.createNew(newTask(
|
|
|
|
|
with(ID, 1),
|
|
|
|
|
with(DUE_TIME, newDateTime().minusMinutes(15)),
|
|
|
|
|
with(HIDE_TYPE, Task.HIDE_UNTIL_DUE_TIME)))
|
|
|
|
|
val geofence = newGeofence(with(TASK, 1), with(PLACE, place.uid), with(ARRIVAL, true))
|
|
|
|
|
geofence.id = locationDao.insert(geofence)
|
|
|
|
|
val geofence = Geofence(task = 1, place = place.uid, isArrival = true)
|
|
|
|
|
.let {
|
|
|
|
|
it.copy(id = locationDao.insert(it))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assertEquals(listOf(geofence), locationDao.getArrivalGeofences(place.uid!!, now()))
|
|
|
|
|
}
|
|
|
|
|
@ -222,14 +216,14 @@ class LocationDaoTest : InjectingTestCase() {
|
|
|
|
|
@Test
|
|
|
|
|
fun getDepartureWithElapsedHideUntil() = runBlocking {
|
|
|
|
|
freezeAt(now()).thawAfter {
|
|
|
|
|
val place = newPlace()
|
|
|
|
|
val place = Place()
|
|
|
|
|
locationDao.insert(place)
|
|
|
|
|
taskDao.createNew(newTask(
|
|
|
|
|
with(ID, 1),
|
|
|
|
|
with(DUE_TIME, newDateTime().minusMinutes(15)),
|
|
|
|
|
with(HIDE_TYPE, Task.HIDE_UNTIL_DUE_TIME)))
|
|
|
|
|
val geofence = newGeofence(with(TASK, 1), with(PLACE, place.uid), with(DEPARTURE, true))
|
|
|
|
|
geofence.id = locationDao.insert(geofence)
|
|
|
|
|
val geofence = Geofence(task = 1, place = place.uid, isDeparture = true)
|
|
|
|
|
.let { it.copy(id = locationDao.insert(it)) }
|
|
|
|
|
|
|
|
|
|
assertEquals(listOf(geofence), locationDao.getDepartureGeofences(place.uid!!, now()))
|
|
|
|
|
}
|
|
|
|
|
|