|
| 1 | +/* |
| 2 | + * Copyright (c) 2026 David Allison <davidallisongithub@gmail.com> |
| 3 | + * |
| 4 | + * This program is free software; you can redistribute it and/or modify it under |
| 5 | + * the terms of the GNU General Public License as published by the Free Software |
| 6 | + * Foundation; either version 3 of the License, or (at your option) any later |
| 7 | + * version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, but WITHOUT ANY |
| 10 | + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 11 | + * PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 12 | + * |
| 13 | + * You should have received a copy of the GNU General Public License along with |
| 14 | + * this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | + */ |
| 16 | +package com.ichi2.anki |
| 17 | + |
| 18 | +import android.view.Gravity |
| 19 | +import android.view.View |
| 20 | +import android.view.ViewGroup |
| 21 | +import android.widget.FrameLayout |
| 22 | +import androidx.core.graphics.Insets |
| 23 | +import androidx.core.view.ViewCompat |
| 24 | +import androidx.core.view.WindowInsetsCompat |
| 25 | +import androidx.test.ext.junit.runners.AndroidJUnit4 |
| 26 | +import org.junit.Test |
| 27 | +import org.junit.runner.RunWith |
| 28 | + |
| 29 | +/** |
| 30 | + * Screenshot tests for [CardBrowser] |
| 31 | + * |
| 32 | + * `./gradlew :AnkiDroid:verifyRoborazziPlayDebug -Pscreenshot --tests "com.ichi2.anki.CardBrowserScreenshotTest"` |
| 33 | + */ |
| 34 | +@RunWith(AndroidJUnit4::class) |
| 35 | +class CardBrowserScreenshotTest : ScreenshotTest() { |
| 36 | + @Test |
| 37 | + fun cardBrowserWith30Notes() = |
| 38 | + withCardBrowser(noteCount = 50) { browser -> |
| 39 | + // Robolectric reports zero system-bar insets by default. Inject realistic ones |
| 40 | + // so the app's edge-to-edge layout responds as it would on a real device. |
| 41 | + val density = browser.resources.displayMetrics.density |
| 42 | + val statusBarPx = (24 * density).toInt() |
| 43 | + val navBarPx = (48 * density).toInt() |
| 44 | + val insets = |
| 45 | + WindowInsetsCompat |
| 46 | + .Builder() |
| 47 | + .setInsets(WindowInsetsCompat.Type.statusBars(), Insets.of(0, statusBarPx, 0, 0)) |
| 48 | + .setInsets(WindowInsetsCompat.Type.navigationBars(), Insets.of(0, 0, 0, navBarPx)) |
| 49 | + .build() |
| 50 | + ViewCompat.dispatchApplyWindowInsets(browser.window.decorView, insets) |
| 51 | + |
| 52 | + // overlay a translucent band where the nav bar would sit |
| 53 | + // to see if content is drawn underneath it |
| 54 | + val decor = browser.window.decorView as ViewGroup |
| 55 | + val navBarOverlay = |
| 56 | + View(browser).apply { |
| 57 | + setBackgroundColor(0x80000000.toInt()) |
| 58 | + } |
| 59 | + decor.addView( |
| 60 | + navBarOverlay, |
| 61 | + FrameLayout.LayoutParams( |
| 62 | + FrameLayout.LayoutParams.MATCH_PARENT, |
| 63 | + navBarPx, |
| 64 | + Gravity.BOTTOM, |
| 65 | + ), |
| 66 | + ) |
| 67 | + |
| 68 | + captureScreen("30_notes") |
| 69 | + } |
| 70 | +} |
0 commit comments