Cotton code
66 lines · 3.0 KB · KotlinRaw
package com.cottondb.storyimport com.cottondb.story.ink.Currentimport com.cottondb.story.ink.InkStateimport com.cottondb.story.ink.Pageimport com.cottondb.story.ink.Sheetimport org.junit.Assert.assertEqualsimport org.junit.Assert.assertTrueimport org.junit.Testimport 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>(Page.Settings), state.pages)        state.come(Current(story = "invented-lighthouse", arriving = null))        assertEquals("invented-lighthouse", state.story)        assertEquals(listOf<Page>(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>(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>(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<String>(), sans)        assertTrue(calls.any { it.contains("inkType().mono") })    }}