package com.cottondb.story import com.cottondb.story.ink.Current import com.cottondb.story.ink.InkState import com.cottondb.story.ink.Page import com.cottondb.story.ink.Sheet import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue import org.junit.Test import java.io.File /** * Signing in leaves the person where they were. On the emulator (first-run walk, 25 Nov 2026) about 15 seconds after a * hand-off sign-in from Settings, the copy answered no script for a moment while what was made before went up: * Settings closed by itself over a full-screen "Loading your data…" in the phone's sans face, then the script home. */ class StorySignInStaysTest { @Test fun settings_stands_while_the_core_answers_no_script_and_then_the_same_one() { val state = InkState() state.home("invented-lighthouse") state.open(Page.Settings) state.come(Current(story = null, arriving = "Loading your data…")) assertEquals(listOf(Page.Settings), state.pages) state.come(Current(story = "invented-lighthouse", arriving = null)) assertEquals("invented-lighthouse", state.story) assertEquals(listOf(Page.Settings), state.pages) } @Test fun the_same_script_answered_again_moves_nothing() { val state = InkState() state.home("invented-lighthouse") state.open(Page.Scene("invented-scene")) state.sheet = Sheet.More state.come(Current(story = "invented-lighthouse", arriving = null)) assertEquals(listOf(Page.Scene("invented-scene")), state.pages) assertEquals(Sheet.More, state.sheet) } @Test fun another_script_answered_closes_what_stood_on_the_old_one_but_not_settings() { val state = InkState() state.home("invented-lighthouse") state.open(Page.About) state.open(Page.Settings) state.come(Current(story = "invented-harbour", arriving = null)) assertEquals("invented-harbour", state.story) assertEquals(listOf(Page.Settings), state.pages) } @Test fun the_persons_own_choice_still_closes_everything() { val state = InkState() state.home("invented-lighthouse") state.open(Page.Settings) state.home(null) assertTrue(state.pages.isEmpty()) } @Test fun the_loading_line_is_drawn_in_storys_face() { val roots = listOf("src/story/kotlin", "app/src/story/kotlin").map(::File).filter { it.isDirectory } val sources = roots.flatMap { root -> root.walkTopDown().filter { it.isFile && it.extension == "kt" }.toList() } assertTrue(sources.isNotEmpty()) val calls = sources.flatMap { file -> Regex("""LoadingLine\(([^\n]*)""").findAll(file.readText()).map { file.name + ": " + it.value }.toList() } val sans = calls.filter { Regex(""",\s*null\b""").containsMatchIn(it) } assertEquals("a loading line in the phone's sans face", emptyList(), sans) assertTrue(calls.any { it.contains("inkType().mono") }) } }