package com.cottondb.sites import kotlinx.serialization.json.Json import kotlinx.serialization.json.jsonObject import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Test import java.io.File /** sites-design 51b0c496ce (CONTRACT "The list"): no screen lock, Arrange's moves, Fill a login, an old web view. */ class SitesNoLockTest { private val repo = generateSequence(File("").absoluteFile) { it.parentFile }.first { File(it, "apps/registry.json").isFile } private fun src(name: String) = File(repo, "apps/android/app/src/sites/kotlin/com/cottondb/sites/$name").readText() private val words by lazy { Json.parseToJsonElement(File(repo, "crates/cotton-core/kits/shell/lines/sites.json").readText()).jsonObject } @Test fun the_words_are_the_cores() { listOf("hidden" to "no_lock", "hidden" to "set_lock", "arrange" to "up", "arrange" to "down", "failed" to "old_title", "failed" to "old_line", "failed" to "old_update", "login" to "other").forEach { (set, key) -> assertTrue("$set.$key", words[set]!!.jsonObject.containsKey(key)) } } /** A phone with no screen lock says so: sites.home gets no_lock, the list shows why and how to set one, no Hide. */ @Test fun a_phone_with_no_lock_shows_hidden_sites_and_says_why() { val state = src("SitesState.kt") assertTrue(state.contains("isDeviceSecure")) assertTrue(state.contains("if (noLock) put(\"no_lock\", true)")) val list = src("ListScreen.kt") assertTrue(list.contains("hidden.str(\"no_lock\")") && list.contains("hidden.str(\"set_lock\")")) assertTrue(list.contains("if (noLock == null) HideButton(")) } /** Arrange's TalkBack moves, the Fill line's key mark, and the old web view in the core's words. */ @Test fun arrange_fill_and_the_old_web_view_say_the_cores_words() { val edit = src("Edit.kt") assertTrue(edit.contains("state.w(\"arrange.up\"") && edit.contains("state.w(\"arrange.down\"")) assertFalse(edit.contains("table.move_up")) assertTrue(src("Fill.kt").contains("control(state.w(\"login.other\"))")) val state = src("SitesState.kt") assertFalse(state.contains("web view without profiles\"); return@go")) assertTrue(state.split("sheet = Sheet.OldWebView").size == 3) val sheets = src("Sheets.kt") assertTrue(sheets.contains("failed.old_title") && sheets.contains("failed.old_update") && sheets.contains("com.google.android.webview")) } }