Support setting filter expirations (#2667)
* Show filter expiration in list * Add support for setting and updating the duration of a filter * Add tests for duration conversion math * Refactor network wrapper code * Mark updated mastodon api functions as suspend * Avoid creating unnecessary Date objects * Apply suggestions to filter dialog layout
This commit is contained in:
parent
9beea540de
commit
c47d9ef6ac
7 changed files with 197 additions and 100 deletions
|
@ -7,6 +7,7 @@ import com.keylesspalace.tusky.entity.Poll
|
|||
import com.keylesspalace.tusky.entity.PollOption
|
||||
import com.keylesspalace.tusky.entity.Status
|
||||
import com.keylesspalace.tusky.network.FilterModel
|
||||
import com.keylesspalace.tusky.view.getSecondsForDurationIndex
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
|
@ -182,6 +183,23 @@ class FilterTest {
|
|||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun unchangedExpiration_shouldBeNegative_whenFilterIsExpired() {
|
||||
val expiredBySeconds = 3600
|
||||
val expiredDate = Date.from(Instant.now().minusSeconds(expiredBySeconds.toLong()))
|
||||
val updatedDuration = getSecondsForDurationIndex(-1, null, expiredDate)
|
||||
assert(updatedDuration != null && updatedDuration <= -expiredBySeconds)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun unchangedExpiration_shouldBePositive_whenFilterIsUnexpired() {
|
||||
val expiresInSeconds = 3600
|
||||
val expiredDate = Date.from(Instant.now().plusSeconds(expiresInSeconds.toLong()))
|
||||
val updatedDuration = getSecondsForDurationIndex(-1, null, expiredDate)
|
||||
assert(updatedDuration != null && updatedDuration > (expiresInSeconds - 60))
|
||||
}
|
||||
|
||||
private fun mockStatus(
|
||||
content: String = "",
|
||||
spoilerText: String = "",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue