A chat app's shape: new chat first, chats in a drawer, Scheduled
CI / check (push) Canceled after 0s
CI / check (push) Canceled after 0s
The app opens on a new chat (greeting, suggestions, composer) instead of a list. The model is the top bar's title (picture, name, caret) and opens a bottom-sheet picker with pictures, what each model can do and its levels. Chats live in a navigation drawer: search, New chat, New agent chat, Files, Scheduled, then Today / Earlier / Agent chats, Settings with the account at the foot. The transcript: the person's words in a bubble on the right, the model's full width without one; thinking and each round of tools fold into chips that open; fenced code becomes its own block with the language and Copy; attached pictures are thumbnails; a breathing dot while a reply is written; Copy and Regenerate under a reply, and a long-press menu (Copy, Select text, Edit, Regenerate). The composer is one rounded field: attach (+), an Options button that opens the tune sheet (Thinking switch or effort levels, team size, Plan first or the agent's mode, and a new agent chat's device and folder: only what the model offers), the microphone, and Send that becomes Stop. Settings are Material 3 grouped lists. Scheduled (phone first): the list (next run, last status, pause switch), a schedule's page (rule, Run now, Pause, next runs, history with model and Open), and create/edit in words with a preview before saving. Notification channels Scheduled results and Scheduled failures, private on the lock screen with a public version, actions Open and Pause. The /api/v2 routes are provisional (api/Schedules.kt) until the server's contract lands. Screens take their state as data (ChatContent, DrawerContent, SettingsContent, Scheduled*Content), so the screenshot tests draw every one with fake data. 60 strings, in all eight languages. Unit tests for the fence splitter, the drawer's grouping, the chat state the controls read, and schedule times. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
38 files changed
+5282
-1182
No files matched your search
@@ -0,0 +1,44 @@
|
||||
package eu.llembas.android
|
||||
|
||||
import eu.llembas.android.api.Chat
|
||||
import eu.llembas.android.ui.home.groupChats
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import java.time.LocalDate
|
||||
import java.time.ZoneId
|
||||
|
||||
class ChatGroupsTest {
|
||||
private val zone = ZoneId.of("Europe/Bratislava")
|
||||
private val today = LocalDate.of(2026, 3, 10)
|
||||
|
||||
private fun chat(id: String, title: String, updated: String?, kind: String = "chat") = Chat(id = id, title = title, kind = kind, updatedAt = updated)
|
||||
|
||||
@Test
|
||||
fun todayEarlierAndAgentsKeepTheirOrder() {
|
||||
val chats = listOf(
|
||||
chat("a", "Bread", "2026-03-10T08:00:00+00:00"),
|
||||
chat("b", "Repo", "2026-03-10T07:00:00+00:00", kind = "agent"),
|
||||
chat("c", "Honey", "2026-03-09T12:00:00+00:00"),
|
||||
chat("d", "Old", null),
|
||||
)
|
||||
val groups = groupChats(chats, "", today, zone)
|
||||
assertEquals(listOf("a"), groups.today.map { it.id })
|
||||
assertEquals(listOf("c", "d"), groups.earlier.map { it.id })
|
||||
assertEquals(listOf("b"), groups.agents.map { it.id })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun theDayIsThePhones() {
|
||||
// 23:30 UTC on the 9th is already the 10th in Central Europe.
|
||||
val groups = groupChats(listOf(chat("a", "Late", "2026-03-09T23:30:00+00:00")), "", today, zone)
|
||||
assertEquals(listOf("a"), groups.today.map { it.id })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun searchMatchesTheTitleInAnyCase() {
|
||||
val chats = listOf(chat("a", "Lembas bread", null), chat("b", "Ropes", null))
|
||||
assertEquals(listOf("a"), groupChats(chats, " BREAD ", today, zone).earlier.map { it.id })
|
||||
assertTrue(groupChats(chats, "nothing", today, zone).isEmpty)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package eu.llembas.android
|
||||
|
||||
import eu.llembas.android.api.AgentsSetting
|
||||
import eu.llembas.android.api.Chat
|
||||
import eu.llembas.android.api.LembasJson
|
||||
import eu.llembas.android.api.LinkedDevice
|
||||
import eu.llembas.android.api.ModelList
|
||||
import eu.llembas.android.ui.chat.ChatState
|
||||
import eu.llembas.android.ui.chat.Draft
|
||||
import eu.llembas.android.ui.chat.agents
|
||||
import eu.llembas.android.ui.chat.compactContext
|
||||
import eu.llembas.android.ui.chat.device
|
||||
import eu.llembas.android.ui.chat.level
|
||||
import eu.llembas.android.ui.chat.modelId
|
||||
import eu.llembas.android.ui.chat.offersTeam
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
/** What the top bar, the composer and the tune sheet read from a chat's state. */
|
||||
class ChatStateTest {
|
||||
private val models = LembasJson.decodeFromString(
|
||||
ModelList.serializer(),
|
||||
requireNotNull(javaClass.classLoader!!.getResource("models.json")).readText(),
|
||||
).models
|
||||
|
||||
@Test
|
||||
fun theModelIsTheChatsThenTheDraftsThenTheDefault() {
|
||||
assertEquals("qwen", ChatState(models = models).modelId)
|
||||
assertEquals("gpt-oss", ChatState(models = models, draft = Draft(model = "gpt-oss")).modelId)
|
||||
assertEquals("vision-small", ChatState(models = models, chat = Chat(id = "c", model = "vision-small"), draft = Draft(model = "gpt-oss")).modelId)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun theLevelFollowsTheModelsControl() {
|
||||
// A switch model starts at its effort; one level is no choice at all.
|
||||
assertEquals("medium", ChatState(models = models).level)
|
||||
assertEquals("off", ChatState(models = models, draft = Draft(effort = "off")).level)
|
||||
assertNull(ChatState(models = models, draft = Draft(model = "vision-small")).level)
|
||||
// A level the model does not offer falls back to its own.
|
||||
assertEquals("high", ChatState(models = models, chat = Chat(id = "c", model = "gpt-oss", effort = "extreme")).level)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aTeamIsOfferedByTheServerOrGuessedForANewChat() {
|
||||
assertTrue(ChatState(models = models).offersTeam(agent = false))
|
||||
assertFalse(ChatState(models = models).offersTeam(agent = true))
|
||||
assertFalse(ChatState(models = models, draft = Draft(model = "gpt-oss")).offersTeam(agent = false))
|
||||
assertTrue(ChatState(models = models, chat = Chat(id = "c", model = "gpt-oss"), teamOffered = true).offersTeam(agent = false))
|
||||
assertEquals(AgentsSetting(2, 6), ChatState(draft = Draft(agents = AgentsSetting(2, 6))).agents)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aNewAgentChatRunsOnTheChosenDeviceOrTheFirst() {
|
||||
val devices = listOf(LinkedDevice("d1"), LinkedDevice("d2"))
|
||||
assertEquals("d1", ChatState(devices = devices).device?.id)
|
||||
assertEquals("d2", ChatState(devices = devices, draft = Draft(device = "d2")).device?.id)
|
||||
assertNull(ChatState().device)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun contextWindowsAreSaidShort() {
|
||||
assertEquals("128K", compactContext(131072))
|
||||
assertEquals("8K", compactContext(8192))
|
||||
assertEquals("1M", compactContext(1_000_000))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package eu.llembas.android
|
||||
|
||||
import eu.llembas.android.ui.Segment
|
||||
import eu.llembas.android.ui.splitFences
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class MarkdownSplitTest {
|
||||
@Test
|
||||
fun proseOnlyIsOnePiece() {
|
||||
assertEquals(listOf(Segment.Prose("Hello *there*.")), splitFences("Hello *there*.\n"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aFenceBetweenProse() {
|
||||
val split = splitFences("Here is how:\n\n```sh\nbake --slow\n```\n\nDone.")
|
||||
assertEquals(
|
||||
listOf(Segment.Prose("Here is how:"), Segment.Code("sh", "bake --slow"), Segment.Prose("Done.")),
|
||||
split,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun anUnclosedFenceRunsToTheEndWhileWritten() {
|
||||
val split = splitFences("Code:\n```kotlin\nval a = 1\nval b")
|
||||
assertEquals(listOf(Segment.Prose("Code:"), Segment.Code("kotlin", "val a = 1\nval b", closed = false)), split)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aLongerFenceHoldsAShorterOne() {
|
||||
val split = splitFences("````md\n```\ninner\n```\n````")
|
||||
assertEquals(listOf(Segment.Code("md", "```\ninner\n```")), split)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun tildesAndNoLanguage() {
|
||||
assertEquals(listOf(Segment.Code("", "x")), splitFences("~~~\nx\n~~~"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aFenceInsideAListStaysProse() {
|
||||
val text = "1. Run it:\n\n ```sh\n make\n ```"
|
||||
assertEquals(listOf(Segment.Prose(text)), splitFences(text))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun inlineBackticksAreNotAFence() {
|
||||
assertEquals(listOf(Segment.Prose("Use ``` to fence code.")), splitFences("Use ``` to fence code."))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package eu.llembas.android
|
||||
|
||||
import eu.llembas.android.api.LembasJson
|
||||
import eu.llembas.android.api.ScheduleList
|
||||
import eu.llembas.android.ui.scheduled.ScheduleLogic
|
||||
import eu.llembas.android.ui.scheduled.Tone
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Test
|
||||
import java.time.ZoneId
|
||||
import java.util.Locale
|
||||
|
||||
class ScheduleLogicTest {
|
||||
private val zone = ZoneId.of("Europe/Bratislava")
|
||||
|
||||
@Test
|
||||
fun statusesHaveTones() {
|
||||
assertEquals(Tone.Good, ScheduleLogic.tone("ok"))
|
||||
assertEquals(Tone.Quiet, ScheduleLogic.tone("silent"))
|
||||
assertEquals(Tone.Bad, ScheduleLogic.tone("failed"))
|
||||
assertEquals(Tone.Bad, ScheduleLogic.tone("missed"))
|
||||
assertEquals(Tone.Waiting, ScheduleLogic.tone("waiting"))
|
||||
assertEquals(Tone.Neutral, ScheduleLogic.tone("something new"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aMomentIsShownWhereThePhoneIs() {
|
||||
assertEquals("Tue 10 Mar, 08:00", ScheduleLogic.moment("2026-03-10T07:00:00+00:00", zone, Locale.ENGLISH))
|
||||
assertNull(ScheduleLogic.moment("tomorrow", zone, Locale.ENGLISH))
|
||||
assertNull(ScheduleLogic.moment(null, zone, Locale.ENGLISH))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun upcomingKeepsFiveReadableRuns() {
|
||||
val runs = (1..7).map { "2026-03-1${it}T07:00:00+00:00" } + "nonsense"
|
||||
assertEquals(5, ScheduleLogic.upcoming(runs, zone = zone, locale = Locale.ENGLISH).size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aScheduleListThatSaysLittleStillParses() {
|
||||
val list = LembasJson.decodeFromString(ScheduleList.serializer(), """{"schedules":[{"id":"s1","paused":true,"later":1}]}""")
|
||||
assertEquals("s1", list.schedules.single().id)
|
||||
assertNull(list.schedules.single().nextRun)
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,220 @@
|
||||
package eu.llembas.android.shots
|
||||
|
||||
import eu.llembas.android.api.ActivitySummary
|
||||
import eu.llembas.android.api.AgentsSetting
|
||||
import eu.llembas.android.api.Attachment
|
||||
import eu.llembas.android.api.Chat
|
||||
import eu.llembas.android.api.LembasJson
|
||||
import eu.llembas.android.api.LinkedDevice
|
||||
import eu.llembas.android.api.LiveReply
|
||||
import eu.llembas.android.api.Message
|
||||
import eu.llembas.android.api.Metrics
|
||||
import eu.llembas.android.api.ModelList
|
||||
import eu.llembas.android.api.Schedule
|
||||
import eu.llembas.android.api.SchedulePreview
|
||||
import eu.llembas.android.api.ScheduleRun
|
||||
import eu.llembas.android.api.Step
|
||||
import eu.llembas.android.api.Tail
|
||||
import eu.llembas.android.api.ToolBlock
|
||||
import eu.llembas.android.api.ToolCall
|
||||
import eu.llembas.android.auth.Instance
|
||||
import eu.llembas.android.auth.Prefs
|
||||
import eu.llembas.android.ui.chat.ChatState
|
||||
import eu.llembas.android.ui.chat.Draft
|
||||
import eu.llembas.android.ui.home.ChatsState
|
||||
import eu.llembas.android.ui.scheduled.EditState
|
||||
import eu.llembas.android.ui.scheduled.ScheduleState
|
||||
import eu.llembas.android.ui.scheduled.ScheduledState
|
||||
import eu.llembas.android.ui.settings.SettingsState
|
||||
import java.time.LocalDate
|
||||
|
||||
/** Made-up data for the screenshots: the server's own contract files where they fit. */
|
||||
object Fakes {
|
||||
private fun text(name: String): String = requireNotNull(javaClass.classLoader!!.getResource("$name.json")).readText()
|
||||
|
||||
/** The day the drawer is drawn on: chats updated on it are "Today". */
|
||||
val today: LocalDate = LocalDate.of(2026, 3, 10)
|
||||
|
||||
val models = LembasJson.decodeFromString(ModelList.serializer(), text("models")).models
|
||||
val question = LembasJson.decodeFromString(Message.serializer(), text("message_user"))
|
||||
val answer = LembasJson.decodeFromString(Message.serializer(), text("message_assistant"))
|
||||
|
||||
private val packing = Message(
|
||||
id = "m3",
|
||||
role = "user",
|
||||
text = "Plan a three-day walk to the hills. What should I pack?",
|
||||
attachments = listOf(Attachment(id = "a1", name = "map.jpg", image = true), Attachment(id = "a2", name = "route.gpx", mime = "application/gpx+xml")),
|
||||
)
|
||||
|
||||
private val packingSteps = listOf(
|
||||
Step(
|
||||
index = 0,
|
||||
kind = "thinking",
|
||||
text = "Three days, hills, early spring: warm layers, water, food that keeps.",
|
||||
label = "for 4 seconds · 120 tokens",
|
||||
),
|
||||
Step(
|
||||
index = 0,
|
||||
kind = "tools",
|
||||
calls = listOf(
|
||||
ToolCall(id = "c1", name = "web_search", status = "ok", block = ToolBlock(kind = "web", title = "weather in the hills next week")),
|
||||
ToolCall(
|
||||
id = "c2",
|
||||
name = "read",
|
||||
status = "ok",
|
||||
text = "Day 1: 18 km\nDay 2: 22 km\nDay 3: 15 km",
|
||||
block = ToolBlock(kind = "read", title = "notes/route.md"),
|
||||
),
|
||||
),
|
||||
),
|
||||
Step(
|
||||
index = 1,
|
||||
kind = "text",
|
||||
markdown = "Here is a list for **three days**, light enough to carry:\n\n" +
|
||||
"- Lembas, wrapped in leaves (one bite fills a grown man)\n" +
|
||||
"- A warm cloak and a spare pair of socks\n" +
|
||||
"- Two litres of water, and a way to refill it\n\n" +
|
||||
"```python\ndef pack(days):\n return [\"lembas\"] * days + [\"cloak\", \"rope\"]\n```\n\n" +
|
||||
"The second day is the longest: start early.",
|
||||
),
|
||||
)
|
||||
|
||||
private val packingAnswer = Message(
|
||||
id = "m4",
|
||||
role = "assistant",
|
||||
model = "qwen",
|
||||
steps = packingSteps,
|
||||
metrics = Metrics(completionTokens = 412, elapsedMs = 9000, tokPerSecond = 45.8),
|
||||
)
|
||||
|
||||
val chat = Chat(id = "c1", title = "Packing for the road", model = "qwen", updatedAt = "2026-03-10T09:00:00+00:00")
|
||||
|
||||
val newChat = ChatState(models = models)
|
||||
|
||||
val newAgentChat = ChatState(
|
||||
models = models,
|
||||
devices = listOf(LinkedDevice(id = "d1", name = "Workstation", host = "workstation"), LinkedDevice(id = "d2", name = "Laptop", host = "laptop")),
|
||||
draft = Draft(directory = "~/src/garden"),
|
||||
)
|
||||
|
||||
val transcript = ChatState(
|
||||
chat = chat,
|
||||
messages = listOf(question, answer, packing, packingAnswer),
|
||||
models = models,
|
||||
teamOffered = true,
|
||||
summary = ActivitySummary(working = 2, active = 2, total = 2),
|
||||
)
|
||||
|
||||
/** The last reply while it is being written: its tools done, its words coming in. */
|
||||
val writing = transcript.copy(
|
||||
messages = listOf(question, answer, packing, packingAnswer.copy(steps = emptyList(), complete = false)),
|
||||
live = LiveReply(messageId = "m4", steps = packingSteps.take(2), tail = Tail(text = "Here is a list for **three days**, light enough")),
|
||||
summary = null,
|
||||
)
|
||||
|
||||
/** A chat on a model with effort levels, a team and a plan: the tune sheet with everything. */
|
||||
val tuned = transcript.copy(
|
||||
chat = chat.copy(model = "gpt-oss", effort = "high", mode = "plan", agents = AgentsSetting(1, 4)),
|
||||
)
|
||||
|
||||
val chats = ChatsState(
|
||||
chats = listOf(
|
||||
chat,
|
||||
Chat(id = "c2", title = "Repairing the garden gate", kind = "agent", updatedAt = "2026-03-10T08:00:00+00:00", running = true),
|
||||
Chat(id = "c3", title = "A letter to the mayor about the bridge", updatedAt = "2026-03-10T07:00:00+00:00", unread = true),
|
||||
Chat(id = "c4", title = "Sourdough timings", updatedAt = "2026-03-09T18:00:00+00:00"),
|
||||
Chat(id = "c5", title = "Translate the recipe into Slovak", updatedAt = "2026-03-08T10:00:00+00:00"),
|
||||
Chat(id = "c6", title = "Why do leaves keep bread fresh, and does it work with any leaf or only some?", updatedAt = "2026-03-01T10:00:00+00:00"),
|
||||
Chat(id = "c7", title = "Clean up the build scripts", kind = "agent", updatedAt = "2026-03-02T10:00:00+00:00"),
|
||||
),
|
||||
)
|
||||
|
||||
private val home = Instance(id = "i1", base = "https://llm.example.org", name = "Home", email = "frodo@example.org", sealedToken = "")
|
||||
private val work = Instance(id = "i2", base = "https://ai.example.com", name = "Work", email = "f.baggins@example.com", sealedToken = "")
|
||||
|
||||
val settings = SettingsState(
|
||||
instances = listOf(home, work),
|
||||
active = home,
|
||||
prefs = Prefs(theme = "", assistantTemporary = true),
|
||||
hasDistributor = true,
|
||||
version = "1.0.0-beta.3",
|
||||
selfUpdate = true,
|
||||
)
|
||||
|
||||
private val ok =
|
||||
ScheduleRun(id = "r1", dueAt = "2026-03-10T06:30:00+00:00", startedAt = "2026-03-10T06:30:02+00:00", status = "ok", model = "qwen", chatId = "c9")
|
||||
private val nextRuns = (11..17).map { "2026-03-${it}T06:30:00+00:00" }
|
||||
|
||||
val schedules = listOf(
|
||||
Schedule(
|
||||
id = "s1",
|
||||
title = "Morning news on renewables",
|
||||
instruction = "Sum up the news about renewable energy from the last day, in five points.",
|
||||
rule = "Every weekday at 07:30",
|
||||
nextRuns = nextRuns,
|
||||
lastRun = ok,
|
||||
model = "qwen",
|
||||
notify = "matters",
|
||||
),
|
||||
Schedule(
|
||||
id = "s2",
|
||||
title = "Check the garden sensors",
|
||||
instruction = "Read the sensors and tell me if the soil is too dry.",
|
||||
rule = "Every 3 hours",
|
||||
nextRuns = listOf("2026-03-10T12:00:00+00:00"),
|
||||
lastRun = ScheduleRun(id = "r2", status = "silent"),
|
||||
),
|
||||
Schedule(
|
||||
id = "s3",
|
||||
title = "Weekly backup report",
|
||||
instruction = "Summarise last week's backups and anything that failed.",
|
||||
rule = "Every Monday at 09:00",
|
||||
paused = true,
|
||||
lastRun = ScheduleRun(id = "r3", status = "failed", error = "The model could not be reached."),
|
||||
),
|
||||
Schedule(
|
||||
id = "s4",
|
||||
title = "Dentist",
|
||||
instruction = "Remind me to call the dentist.",
|
||||
rule = "Once, on Thursday at 10:00",
|
||||
nextRuns = listOf("2026-03-12T09:00:00+00:00"),
|
||||
lastRun = ScheduleRun(id = "r4", status = "waiting"),
|
||||
),
|
||||
)
|
||||
|
||||
val scheduled = ScheduledState(schedules = schedules)
|
||||
|
||||
val schedule = ScheduleState(
|
||||
schedule = schedules[0],
|
||||
runs = listOf(
|
||||
ok,
|
||||
ScheduleRun(
|
||||
id = "r0",
|
||||
startedAt = "2026-03-09T06:41:00+00:00",
|
||||
status = "ok",
|
||||
model = "gpt-oss",
|
||||
modelReason = "switched: qwen busy",
|
||||
chatId = "c8",
|
||||
),
|
||||
ScheduleRun(id = "r-1", dueAt = "2026-03-06T06:30:00+00:00", status = "silent", model = "qwen"),
|
||||
ScheduleRun(id = "r-2", dueAt = "2026-03-05T06:30:00+00:00", status = "missed", missed = 2),
|
||||
ScheduleRun(
|
||||
id = "r-3",
|
||||
startedAt = "2026-03-04T06:30:00+00:00",
|
||||
status = "failed",
|
||||
model = "qwen",
|
||||
error = "The model stopped answering after 10 minutes.",
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
val editing = EditState(
|
||||
words = "Every weekday at 7:30, sum up the news about renewable energy in five points",
|
||||
preview = SchedulePreview(
|
||||
title = "Morning news on renewables",
|
||||
ruleText = "Every weekday at 07:30",
|
||||
instruction = "Sum up the news about renewable energy from the last day, in five points.",
|
||||
nextRuns = nextRuns,
|
||||
),
|
||||
)
|
||||
}
|
||||
@@ -1,28 +1,143 @@
|
||||
package eu.llembas.android.shots
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.DrawerValue
|
||||
import androidx.compose.material3.ModalNavigationDrawer
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.rememberDrawerState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import eu.llembas.android.ui.chat.Steps
|
||||
import eu.llembas.android.ui.chat.UserBubble
|
||||
import eu.llembas.android.ui.chat.ChatActions
|
||||
import eu.llembas.android.ui.chat.ChatContent
|
||||
import eu.llembas.android.ui.chat.ModelPickerContent
|
||||
import eu.llembas.android.ui.chat.TuneContent
|
||||
import eu.llembas.android.ui.chat.modelId
|
||||
import eu.llembas.android.ui.home.DrawerActions
|
||||
import eu.llembas.android.ui.home.DrawerContent
|
||||
import eu.llembas.android.ui.scheduled.ScheduleContent
|
||||
import eu.llembas.android.ui.scheduled.ScheduleEditContent
|
||||
import eu.llembas.android.ui.scheduled.ScheduledContent
|
||||
import eu.llembas.android.ui.settings.SettingsActions
|
||||
import eu.llembas.android.ui.settings.SettingsContent
|
||||
import eu.llembas.android.ui.theme.LocalPalette
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.GraphicsMode
|
||||
import java.time.ZoneOffset
|
||||
|
||||
/** The app's screens with made-up data ([Fakes]), as a phone shows them. See [shoot]. */
|
||||
private object NoChatActions : ChatActions
|
||||
|
||||
private object NoDrawerActions : DrawerActions
|
||||
|
||||
private object NoSettingsActions : SettingsActions
|
||||
|
||||
/**
|
||||
* The app's screens with made-up data ([Fakes]), as a phone shows them: each in Shire and
|
||||
* Moria, at a large phone's size and, where things crowd, a small one's and with large type.
|
||||
* See [shoot]. These are looked at after every design change; they assert nothing.
|
||||
*/
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@GraphicsMode(GraphicsMode.Mode.NATIVE)
|
||||
@Config(sdk = [35], qualifiers = "xhdpi")
|
||||
class ScreenShots {
|
||||
@Test
|
||||
fun transcript() = shoot("transcript") {
|
||||
Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(16.dp)) {
|
||||
UserBubble(Fakes.question)
|
||||
Steps(Fakes.answer.steps)
|
||||
fun newChat() {
|
||||
shoot("01-new-chat") { ChatContent(Fakes.newChat, NoChatActions, agent = false) }
|
||||
shoot("01-new-chat", Phone.Small) { ChatContent(Fakes.newChat, NoChatActions, agent = false) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun newAgentChat() = shoot("02-new-agent-chat") { ChatContent(Fakes.newAgentChat, NoChatActions, agent = true) }
|
||||
|
||||
@Test
|
||||
fun transcript() {
|
||||
shoot("03-transcript") { ChatContent(Fakes.transcript, NoChatActions, agent = false) }
|
||||
shoot("03-transcript", Phone.Small) { ChatContent(Fakes.transcript, NoChatActions, agent = false) }
|
||||
shoot("03-transcript", Phone.Small, fontScale = 1.5f) { ChatContent(Fakes.transcript, NoChatActions, agent = false) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun writing() = shoot("04-writing") { ChatContent(Fakes.writing, NoChatActions, agent = false) }
|
||||
|
||||
@Test
|
||||
fun drawer() {
|
||||
val drawn: @Composable () -> Unit = {
|
||||
ModalNavigationDrawer(
|
||||
drawerState = rememberDrawerState(DrawerValue.Open),
|
||||
drawerContent = {
|
||||
DrawerContent(
|
||||
Fakes.chats,
|
||||
current = "c1",
|
||||
account = "Home · frodo@example.org",
|
||||
actions = NoDrawerActions,
|
||||
today = Fakes.today,
|
||||
zone = ZoneOffset.UTC,
|
||||
)
|
||||
},
|
||||
) { ChatContent(Fakes.transcript, NoChatActions, agent = false) }
|
||||
}
|
||||
shoot("05-drawer", content = drawn)
|
||||
shoot("05-drawer", Phone.Small, content = drawn)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun modelPicker() = shoot("06-model-picker") {
|
||||
SheetOver { ModelPickerContent(Fakes.models, Fakes.transcript.modelId, onPick = {}) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun tune() = shoot("07-tune") {
|
||||
SheetOver { TuneContent(Fakes.tuned, NoChatActions, agent = false) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun settings() {
|
||||
shoot("08-settings") { SettingsContent(Fakes.settings, NoSettingsActions) }
|
||||
shoot("08-settings", Phone.Small) { SettingsContent(Fakes.settings, NoSettingsActions) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun scheduled() {
|
||||
shoot("09-scheduled") { ScheduledContent(Fakes.scheduled) }
|
||||
shoot("09-scheduled", Phone.Small) { ScheduledContent(Fakes.scheduled) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun schedule() = shoot("10-schedule") { ScheduleContent(Fakes.schedule) }
|
||||
|
||||
@Test
|
||||
fun scheduleEdit() = shoot("11-schedule-edit") { ScheduleEditContent(Fakes.editing, editing = false) }
|
||||
}
|
||||
|
||||
/**
|
||||
* A bottom sheet's content as the sheet shows it, over a dimmed page: the sheet itself is a
|
||||
* window of its own, which a screenshot of the page does not hold.
|
||||
*/
|
||||
@Composable
|
||||
private fun SheetOver(content: @Composable () -> Unit) {
|
||||
val palette = LocalPalette.current
|
||||
Box(Modifier.fillMaxSize().background(palette.bg)) {
|
||||
Box(Modifier.fillMaxSize().background(palette.inkInverse.copy(alpha = 0.5f)))
|
||||
Surface(
|
||||
color = palette.surface,
|
||||
shape = RoundedCornerShape(topStart = 28.dp, topEnd = 28.dp),
|
||||
modifier = Modifier.align(Alignment.BottomCenter).fillMaxWidth(),
|
||||
) {
|
||||
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
Box(Modifier.padding(vertical = 16.dp).size(width = 32.dp, height = 4.dp).background(palette.inkFaint, RoundedCornerShape(2.dp)))
|
||||
content()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user