Export retained notification images in HTML

This commit is contained in:
ajp_anton
2026-07-23 10:51:07 +00:00
parent 6eb9058595
commit dd1c9e5a01
8 changed files with 123 additions and 7 deletions
@@ -0,0 +1,33 @@
package se.ajpanton.notificationlog.export
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import se.ajpanton.notificationlog.model.NotificationAction
import se.ajpanton.notificationlog.model.NotificationLogEntry
import se.ajpanton.notificationlog.settings.LogViewSettings
class LogExporterTest {
private val imageEntry = NotificationLogEntry(
recordedAtEpochMillis = 0,
packageName = "example.app",
appName = "Example",
action = NotificationAction.APPEARED,
contents = "A notification [image]",
imageId = "123e4567-e89b-12d3-a456-426614174000",
)
@Test fun `text exports retain an image placeholder`() {
assertTrue(LogExporter.csv(listOf(imageEntry), LogViewSettings()).contains("[image]"))
assertTrue(LogExporter.formatted(listOf(imageEntry), LogViewSettings()).contains("[image]"))
}
@Test fun `html replaces an image placeholder only when a support path exists`() {
val withImage = LogExporter.html(listOf(imageEntry), LogViewSettings()) { "images/${it.imageId}.png" }
val withoutImage = LogExporter.html(listOf(imageEntry), LogViewSettings())
assertTrue(withImage.contains("<img src=\"images/123e4567-e89b-12d3-a456-426614174000.png\""))
assertFalse(withoutImage.contains("<img"))
assertTrue(withoutImage.contains("[image]"))
}
}