package dev.privacyllc.period.lock

import dev.privacyllc.period.core.notifications.NotificationCopy
import dev.privacyllc.period.feature.lock.LockCopy
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test

/**
 * The lock screen is semi-public, so it may not disclose what the app is for.
 *
 * This is the same rule the notification copy already lives under, checked
 * against the same list, and it matters here for the same reason: the text is
 * visible to somebody who has not authenticated. A future edit that made the
 * empty screen friendlier — "Unlock to see your cycle" — would defeat the lock
 * for anybody reading over a shoulder, and would look like an improvement in
 * review.
 *
 * Values rather than source text, deliberately. Grepping `LockScreen.kt` cannot
 * work: its KDoc explains this rule and therefore contains every word it
 * forbids. `GUARDS.md` §2.
 */
class LockCopyTest {

    @Test fun `no lock screen string discloses what this app records`() {
        val offenders = LockCopy.all.flatMap { line ->
            NotificationCopy.SENSITIVE_WORDS
                .filter { word -> line.contains(word, ignoreCase = true) }
                .map { word -> "\"$word\" in: $line" }
        }
        assertEquals("the lock screen must not name what this app is for", emptyList<String>(), offenders)
    }

    /** A guard over an empty list is not a guard. */
    @Test fun `the checked surface is not accidentally empty`() {
        assertTrue("LockCopy.all must cover the visible strings", LockCopy.all.size >= 8)
        assertTrue(NotificationCopy.SENSITIVE_WORDS.isNotEmpty())
    }

    /**
     * The countdown is the one string built at runtime, so it is checked in the
     * shape it actually renders rather than as a template.
     */
    @Test fun `the countdown string is also clean`() {
        listOf("30s", "1:00", "15:00").forEach { formatted ->
            val line = LockCopy.tryAgainIn(formatted)
            NotificationCopy.SENSITIVE_WORDS.forEach { word ->
                assertTrue(
                    "\"$word\" appeared in: $line",
                    !line.contains(word, ignoreCase = true),
                )
            }
        }
    }
}
