package com.cottondb.money import android.app.Application import android.graphics.Bitmap import android.graphics.Canvas import android.graphics.LinearGradient import android.graphics.Paint import android.graphics.Shader import androidx.compose.ui.graphics.ImageBitmap import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.test.junit4.createComposeRule import com.cottondb.money.faces.DocumentFace import com.cottondb.money.faces.GroupFace import com.cottondb.money.faces.SubscriptionFace import com.cottondb.shell.core.Lines import com.cottondb.specimen.SPECIMEN_SCREEN import com.cottondb.specimen.card import com.cottondb.specimen.specimen import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import org.robolectric.annotation.Config import org.robolectric.annotation.GraphicsMode /** The kit's lines these faces read, as the core answers them (kits/shell/lines/cards.json). Synthetic. */ val cardLines = Lines( mapOf( "cards.join" to " · ", "cards.field.received" to "Received {said}", "cards.field.issuer" to "From {said}", "cards.label.slot.next_charge" to "Next charge", "cards.label.face.subscription.next_charge" to "Next charge", "cards.date.add" to "Add date", ), "Cotton Money", ) /** A synthetic picture: a warm wash with a few dark bars, [w] × [h] pixels. */ fun picture(w: Int, h: Int, page: Boolean = false): ImageBitmap { val bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888) val canvas = Canvas(bitmap) if (page) { canvas.drawColor(android.graphics.Color.WHITE) val ink = Paint().apply { color = android.graphics.Color.rgb(60, 60, 70) } canvas.drawRect(w * 0.08f, h * 0.1f, w * 0.5f, h * 0.18f, ink) ink.color = android.graphics.Color.rgb(150, 150, 160) for (i in 0 until 6) canvas.drawRect(w * 0.08f, h * (0.3f + i * 0.1f), w * (0.6f + (i % 3) * 0.1f), h * (0.33f + i * 0.1f), ink) } else { canvas.drawPaint(Paint().apply { shader = LinearGradient(0f, 0f, w.toFloat(), h.toFloat(), 0xFF7A5C3E.toInt(), 0xFFD9B98C.toInt(), Shader.TileMode.CLAMP) }) canvas.drawCircle(w * 0.5f, h * 0.45f, h * 0.22f, Paint().apply { color = 0xFF3B2A1E.toInt() }) } return bitmap.asImageBitmap() } /** Money's document, group and subscription faces (DocumentFace, GroupFace, SubscriptionFace.swift), as its APK carries them. */ @RunWith(RobolectricTestRunner::class) @GraphicsMode(GraphicsMode.Mode.NATIVE) @Config(sdk = [35], qualifiers = SPECIMEN_SCREEN, application = Application::class) class MoneyCardFacesSpecimenTest { @get:Rule val compose = createComposeRule() /** RULE: a bill with no page here stands a blank page at the left, the tag and title beside it, facts on dashed rules, the house at the foot. */ @Test fun aBillStandingBlank() = compose.specimen("money", "document-bill") { DocumentFace(card("""{"face":"document","slots":{"title":"Electricity bill","subtitle":"PDF · 1 page","date":"Received 18 Oct 2026","source":"From Example Power Company","group":"Home"}}"""), cardLines, null, false) {} } /** RULE: a title the column cannot hold takes the card's width under the page; the state is stamped at the foot. */ @Test fun aLongTitleUnderThePage() = compose.specimen("money", "document-wide-title") { DocumentFace(card("""{"face":"document","slots":{"title":"Example Bank statement INV-20260914-0042","subtitle":"PDF · 6 pages","date":"Received 2 Oct","group":"Statements","state":"Not read yet"}}"""), cardLines, picture(600, 820, page = true), false) {} } /** RULE: a page wider than tall lies across the top, the words under it. */ @Test fun aCardLyingAcross() = compose.specimen("money", "document-lying") { DocumentFace(card("""{"face":"document","corner":"Boards in 4 hours","slots":{"title":"Boarding pass BLR to DEL","subtitle":"PDF · 1 page","date":"Received 2 days ago","group":"Travel","state":"Not read yet"}}"""), cardLines, picture(900, 500, page = true), false) {} } /** RULE: a person with no photograph shows their initial ringed; the net heavy, the lines with amounts right and days in pencil, then more. */ @Test fun aGroupWithItsInitial() = compose.specimen("money", "group-initial") { GroupFace(card("""{"face":"group","slots":{"title":"Invented Asha","net":["Owes you ₹1,200"],"lines":[{"title":"Dinner","amount":"₹800","date":"Thu 22 Oct"},{"title":"Cab","amount":"₹400"},{"title":"Movie tickets","amount":"₹600","date":"Sat 17 Oct"}],"more":"+4"}}"""), null, false) {} } /** RULE: a person's photograph is mounted across the top. */ @Test fun aGroupWithAPhotograph() = compose.specimen("money", "group-photo") { GroupFace(card("""{"face":"group","slots":{"title":"Invented Ravi","net":["₹1,800 between you"],"lines":[{"title":"Groceries","amount":"₹1,800","date":"Mon 12 Oct"}]}}"""), picture(400, 300), false) {} } /** RULE: the price tag sets the provider, the name heavy, price and period, the next charge by hand and the television. */ @Test fun aStreamingSubscription() = compose.specimen("money", "subscription-streaming") { SubscriptionFace(card("""{"face":"subscription","slots":{"subtitle":"Example Media","title":"Streamflix","price":"₹649","period":"Monthly","next_charge":"Mon 2 Nov","body":"Example Bank credit card"}}"""), cardLines, false) {} } /** RULE: a cancelled one is stamped in red over the set. */ @Test fun aCancelledSubscription() = compose.specimen("money", "subscription-cancelled") { SubscriptionFace(card("""{"face":"subscription","slots":{"title":"Example Plus","price":"₹299","period":"Monthly","state":"Cancelled","body":"Example Bank credit card"}}"""), cardLines, false) {} } /** RULE: with no state, the corner's why-now is ringed there, red while it presses. */ @Test fun aSubscriptionDueSoon() = compose.specimen("money", "subscription-corner") { SubscriptionFace(card("""{"face":"subscription","corner":"Renews in 2 days","pressing":true,"slots":{"subtitle":"Example Cloud","title":"Example Cloud 2 TB","price":"₹749","period":"Monthly","next_charge":"Wed 28 Oct"}}"""), cardLines, false) {} } }