package com.cottondb.story import android.app.Application import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.test.assertCountEquals import androidx.compose.ui.test.getBoundsInRoot import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onAllNodesWithText import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.performClick import com.cottondb.shell.HelpSection import com.cottondb.shell.LocalCardLook import com.cottondb.shell.core.CottonCore import com.cottondb.story.ink.InkCardLook import com.cottondb.story.ink.WriteToUs import com.cottondb.story.ink.inkFonts import kotlinx.serialization.json.jsonObject import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import org.robolectric.annotation.Config /** * Story's Settings says Help and feedback once: Write to us stands under its Share a report. On the emulator (21 Nov * 2026) the page had a "Help and feedback ยท Write to us" row of its own at the top and the shell's Help and feedback * (Share a report) further down. */ @RunWith(RobolectricTestRunner::class) @Config(sdk = [35], qualifiers = "w400dp-h800dp-mdpi", application = Application::class) class StoryHelpOnceTest { @get:Rule val compose = createComposeRule() @Test fun write_to_us_stands_under_the_one_help_and_feedback() { val help = CottonCore.json.parseToJsonElement( """{"title":"Help and feedback","share":{"label":"Share a report","line":"A small text file for support."}}""", ).jsonObject var wrote = 0 compose.setContent { CompositionLocalProvider(LocalCardLook provides InkCardLook(inkFonts(LocalContext.current))) { HelpSection(help, more = { WriteToUs("Write to us") { wrote++ } }) {} } } compose.onAllNodesWithText("Help and feedback").assertCountEquals(1) val section = compose.onNodeWithTag("settings-help").getBoundsInRoot() val share = compose.onNodeWithTag("settings-share-report").getBoundsInRoot() val write = compose.onNodeWithTag("story-settings-help").getBoundsInRoot() assertTrue("Write to us ($write) stands in Help and feedback ($section), under Share a report ($share)", write.top >= share.bottom && write.bottom <= section.bottom) compose.onNodeWithTag("story-settings-help").performClick() compose.runOnIdle { assertEquals(1, wrote) } } }