package com.cottondb.android.ui.legal import androidx.compose.ui.graphics.asAndroidBitmap import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithContentDescription import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.onRoot import androidx.compose.ui.test.performScrollTo import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.performClick import androidx.compose.ui.test.captureToImage import androidx.test.ext.junit.runners.AndroidJUnit4 import com.cottondb.android.ScreenEvidence import com.cottondb.android.legal.LegalDocuments import com.cottondb.android.design.CottonTheme import org.junit.Assert.assertEquals import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) class LegalScreenTest { @get:Rule val compose = createComposeRule() @Test fun privacyPresentsTheStaticSheetAndDelegatesBack() { var backs = 0 compose.setContent { CottonTheme { LegalScreen(LegalDocuments.privacy, onBack = { backs += 1 }) } } ScreenEvidence.capture("legal-privacy") { compose.onRoot().captureToImage().asAndroidBitmap() } compose.onNodeWithText("Privacy").assertExists() compose.onNodeWithText("Last updated 11 August 2026").assertExists() compose.onNodeWithText("Deleting your data").performScrollTo().assertIsDisplayed() compose.onNodeWithText( "You can delete any record from inside the app. To delete your account and everything in it, use the \"Report a problem\" option in Settings and ask — it is removed, not archived.", ).assertExists() compose.onNodeWithContentDescription("Back").performClick() assertEquals(1, backs) } @Test fun termsPreservesSectionOrderAndLastParagraph() { compose.setContent { CottonTheme { LegalScreen(LegalDocuments.terms, onBack = {}) } } ScreenEvidence.capture("legal-terms") { compose.onRoot().captureToImage().asAndroidBitmap() } compose.onNodeWithText("Terms").assertExists() compose.onNodeWithText("Your account").assertExists() compose.onNodeWithText("Changes").assertExists() compose.onNodeWithText( "These terms can change as the app does. The date at the top says when they last did.", ).assertExists() } }