merge: W52K —— 「后台保持连接」开关 + 前台服务(默认关;开了才有常驻通知)
This commit is contained in:
commit
579eccdfd1
10 files changed
+630
No files matched your search
@@ -0,0 +1,61 @@
|
||||
package top.yeij.cyrene.ui.settings
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
/**
|
||||
* 开关下面那行字(纯函数)。
|
||||
*
|
||||
* 这一行的价值全在「说真话」,所以钉的也是真话:
|
||||
* 1. **开的代价自己说出来**(常驻通知 + 多耗电)——不说的代价会变成用户某天「莫名多了条通知」的意外;
|
||||
* 2. **跑不了的时候不许说在跑**(通知权限被拒 / 被撤时,一个字都不提「已开」);
|
||||
* 3. 四个分支互不相同:任何一次改文案都不该把某一档悄悄吞掉。
|
||||
*/
|
||||
class KeepAliveSummaryTest {
|
||||
|
||||
@Test
|
||||
fun `the off state says what it costs to stay off`() {
|
||||
val text = keepAliveSummary(enabled = false, notificationsAllowed = true, permissionJustDenied = false)
|
||||
|
||||
assertTrue("关着要说清后果(消息不丢但连接会断):$text", text.contains("消息不会丢"))
|
||||
assertTrue(text.contains("断开"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the on state spells out the price`() {
|
||||
val text = keepAliveSummary(enabled = true, notificationsAllowed = true, permissionJustDenied = false)
|
||||
|
||||
assertTrue("必须明说会常驻一条通知:$text", text.contains("通知"))
|
||||
assertTrue("必须明说会多耗电:$text", text.contains("电"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `an enabled switch without the notification permission never claims to be working`() {
|
||||
val text = keepAliveSummary(enabled = true, notificationsAllowed = false, permissionJustDenied = false)
|
||||
|
||||
assertFalse("权限不在,绝不能写成「已开」:$text", text.contains("已开"))
|
||||
assertTrue("要说清为什么不起作用:$text", text.contains("起不来"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a just denied request reports the denial instead of pretending success`() {
|
||||
val text = keepAliveSummary(enabled = false, notificationsAllowed = false, permissionJustDenied = true)
|
||||
|
||||
assertTrue("要说清被拒了:$text", text.contains("拒绝"))
|
||||
assertFalse("被拒时不许写成「已开」:$text", text.contains("已开"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the four states are told apart`() {
|
||||
val texts = listOf(
|
||||
keepAliveSummary(enabled = false, notificationsAllowed = true, permissionJustDenied = false),
|
||||
keepAliveSummary(enabled = true, notificationsAllowed = true, permissionJustDenied = false),
|
||||
keepAliveSummary(enabled = true, notificationsAllowed = false, permissionJustDenied = false),
|
||||
keepAliveSummary(enabled = false, notificationsAllowed = false, permissionJustDenied = true),
|
||||
)
|
||||
|
||||
assertEquals("四个分支必须四句不同的话", 4, texts.toSet().size)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user