Files
LLeMbas-Android/app/src/test/java/eu/llembas/android/ReportNotificationTest.kt
T
HomerandClaude Fable 5.2 af290cd7d5
CI / check (push) Canceled after 0s
Review: a report's conversation, ids from outside, the form's notify, the drawer, the channels
Contract at server dev 40813d1 (84 files): a chat's `controls` and `report`,
a text step's `pages` and `text`, a report's `schedule_title`.

- B1 (must): a `user` row the server wrote (`machine`) is never the person's
  bubble -- a quiet note; in a report's conversation the first such line is
  left out. A report chat's bar takes its title from the chat's own `report`
  (so it survives the app being closed), and its menu offers only what
  `controls` allows.
- A1: ids from a push payload or an intent extra pass `safeId`
  (^[A-Za-z0-9_-]{1,64}$) before they become a route: chat, schedule, run,
  report.
- C1-C3: an empty "When..." is sent empty (the server's default) and the
  field shows the default as a placeholder; editing sends `notify` only once
  the schedule was read or the person chose, and a failed read says so and
  disables Save.
- B2: Reports is in the drawer only where the instance has the route.
- A text step with pages is drawn from the server's `text`; a report from
  its `text`. A fence with a space before `html-view` is a code block, as
  the spec has it.
- A push of a kind the app does not know shows nothing. An important report
  uses a channel of high importance. A report read or deleted in the app
  cancels its notification.
- stop() and compact() post an empty body again: a search-and-replace in
  adc1c4f had changed them to "{}" by mistake.

One commit: the model, the screens and the push share these files.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-13 11:38:14 +00:00

83 lines
4.0 KiB
Kotlin

package eu.llembas.android
import android.app.Application
import android.app.Notification
import android.app.NotificationManager
import eu.llembas.android.push.Notifications
import eu.llembas.android.push.ReportNotice
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.Shadows.shadowOf
import org.robolectric.annotation.Config
/**
* A report's notification, both of its faces: unlocked, the report's title and summary; on the
* lock screen the app's fixed words and nothing from the account (rule 5).
*/
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [35], qualifiers = "en")
class ReportNotificationTest {
private val app: Application get() = RuntimeEnvironment.getApplication()
private val notice = ReportNotice("rep1", "Two tenders opened", "Storage bids are due in May.", high = false)
private fun Notification.words() = listOf(Notification.EXTRA_TITLE, Notification.EXTRA_TEXT, Notification.EXTRA_BIG_TEXT).map {
extras.getCharSequence(it)?.toString().orEmpty()
}
@Test
fun unlockedItSaysTheReportLockedOnlyThatThereIsOne() {
val shown = Notifications.reportNotification(app, "home", notice)
assertEquals(LembasApp.CHANNEL_REPORTS, shown.channelId)
assertEquals("Two tenders opened", shown.words()[0])
assertEquals("Storage bids are due in May.", shown.words()[1])
// Private: Android shows the public version on a locked screen.
assertEquals(Notification.VISIBILITY_PRIVATE, shown.visibility)
val locked = shown.publicVersion
assertNotNull(locked)
assertEquals(listOf("LLeMbas", "New report", ""), locked.words())
// Nothing of the report anywhere in what the lock screen gets.
val all = locked.words().joinToString(" ") + locked.extras.keySet().joinToString(" ") { locked.extras.get(it)?.toString().orEmpty() }
assertFalse(all.contains("tenders"))
assertFalse(all.contains("Storage"))
}
@Test
fun itOffersOpenAndMarkReadAndTheSecondNeedsThePhoneUnlocked() {
val shown = Notifications.reportNotification(app, "home", notice)
assertEquals(listOf("Open", "Mark read"), shown.actions.map { it.title.toString() })
assertFalse(shown.actions[0].isAuthenticationRequired)
assertTrue(shown.actions[1].isAuthenticationRequired)
assertNotNull(shown.contentIntent)
assertEquals(Notification.FLAG_AUTO_CANCEL, shown.flags and Notification.FLAG_AUTO_CANCEL)
// A report without a title still says something that is the app's own.
assertEquals("New report", Notifications.reportNotification(app, "home", notice.copy(title = "")).words()[0])
}
@Test
fun anImportantReportHasAChannelThatComesUp() {
assertEquals(LembasApp.CHANNEL_REPORTS_HIGH, Notifications.reportNotification(app, "home", notice.copy(high = true)).channelId)
val manager = app.getSystemService(NotificationManager::class.java)
assertEquals(NotificationManager.IMPORTANCE_HIGH, manager.getNotificationChannel(LembasApp.CHANNEL_REPORTS_HIGH).importance)
assertEquals(NotificationManager.IMPORTANCE_DEFAULT, manager.getNotificationChannel(LembasApp.CHANNEL_REPORTS).importance)
// Both stay private on the lock screen.
assertEquals(Notification.VISIBILITY_PRIVATE, manager.getNotificationChannel(LembasApp.CHANNEL_REPORTS_HIGH).lockscreenVisibility)
}
@Test
fun readingTheReportInTheAppTakesItsNotificationAway() {
val manager = app.getSystemService(NotificationManager::class.java)
manager.notify(notice.id, Notifications.reportNotification(app, "home", notice))
assertNotNull(shadowOf(manager).getNotification(notice.id))
Notifications.reportSeen(app, "rep1")
assertNull(shadowOf(manager).getNotification(notice.id))
}
}