Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
Added paparazzi screen test (#2923) (#3175)
Browse files Browse the repository at this point in the history
* feat: Added Paparazzi tests for the report module (#2923)

* feat: Added Paparazzi tests for the search module (#2923)

* feat: Added Paparazzi tests for the settings module (#2923)

* feat: Added Paparazzi tests for the transaction module (#2923)

* fix: removed paparrazi tests for settings screen

* fix: Fixed paprazzi test for home module
  • Loading branch information
Vivekban authored May 1, 2024
1 parent 6d7f1b2 commit 4e25b3f
Show file tree
Hide file tree
Showing 22 changed files with 183 additions and 23 deletions.
3 changes: 2 additions & 1 deletion screen/home/src/main/java/com/ivy/home/HomeTab.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import com.ivy.legacy.data.AppBaseData
import com.ivy.legacy.data.BufferInfo
import com.ivy.legacy.data.LegacyDueSection
import com.ivy.legacy.data.model.MainTab
import com.ivy.legacy.data.model.Month
import com.ivy.legacy.data.model.TimePeriod
import com.ivy.legacy.ivyWalletCtx
import com.ivy.legacy.ui.component.transaction.TransactionsDividerLine
Expand Down Expand Up @@ -413,7 +414,7 @@ private fun BoxWithConstraintsScope.PreviewHomeTab(isDark: Boolean = false) {
stats = IncomeExpensePair.zero(),
expanded = false,
),
period = ivyWalletCtx().selectedPeriod,
period = TimePeriod(month = Month.monthsList().first(), year = 2023),
hideBalance = false,
hideIncome = false,
expanded = false
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions screen/reports/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ dependencies {
implementation(projects.shared.ui.navigation)
implementation(projects.temp.legacyCode)
implementation(projects.temp.oldDesign)

testImplementation(projects.shared.ui.testing)
}
25 changes: 21 additions & 4 deletions screen/reports/src/main/java/com/ivy/reports/ReportScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.zIndex
import androidx.lifecycle.viewmodel.compose.viewModel
import com.ivy.base.legacy.Theme
import com.ivy.base.legacy.stringRes
import com.ivy.base.model.TransactionType
import com.ivy.data.model.Category
Expand Down Expand Up @@ -402,8 +403,8 @@ private fun Toolbar(
@ExperimentalFoundationApi
@Preview
@Composable
private fun Preview() {
IvyWalletPreview {
private fun Preview(theme: Theme = Theme.LIGHT) {
IvyWalletPreview(theme) {
val acc1 = Account("Cash", color = Green.toArgb())
val acc2 = Account("DSK", color = GreenDark.toArgb())
val cat1 = Category(
Expand Down Expand Up @@ -469,8 +470,8 @@ private fun Preview() {
@ExperimentalFoundationApi
@Preview
@Composable
private fun Preview_NO_FILTER() {
IvyWalletPreview {
private fun Preview_NO_FILTER(theme: Theme = Theme.LIGHT) {
IvyWalletPreview(theme) {
val acc1 = Account("Cash", color = Green.toArgb())
val acc2 = Account("DSK", color = GreenDark.toArgb())
val cat1 = Category(
Expand Down Expand Up @@ -534,3 +535,19 @@ private fun Preview_NO_FILTER() {
UI(state = state)
}
}

/** For screenshot testing */
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun ReportUiTest(isDark: Boolean) {
val theme = if (isDark) Theme.DARK else Theme.LIGHT
Preview(theme)
}

/** For screenshot testing */
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun ReportNoFilterUiTest(isDark: Boolean) {
val theme = if (isDark) Theme.DARK else Theme.LIGHT
Preview_NO_FILTER(theme)
}
30 changes: 30 additions & 0 deletions screen/reports/src/test/java/com/ivy/report/ReportPaparazziTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.ivy.report

import com.google.testing.junit.testparameterinjector.TestParameter
import com.google.testing.junit.testparameterinjector.TestParameterInjector
import com.ivy.reports.ReportNoFilterUiTest
import com.ivy.reports.ReportUiTest
import com.ivy.ui.testing.PaparazziScreenshotTest
import com.ivy.ui.testing.PaparazziTheme
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(TestParameterInjector::class)
class ReportPaparazziTest(
@TestParameter
private val theme: PaparazziTheme,
) : PaparazziScreenshotTest() {
@Test
fun `snapshot Report Screen`() {
snapshot(theme) {
ReportUiTest(theme == PaparazziTheme.Dark)
}
}

@Test
fun `snapshot Report Screen no filter`() {
snapshot(theme) {
ReportNoFilterUiTest(theme == PaparazziTheme.Dark)
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions screen/search/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ dependencies {
implementation(projects.shared.ui.navigation)
implementation(projects.temp.legacyCode)
implementation(projects.temp.oldDesign)

testImplementation(projects.shared.ui.testing)
}
31 changes: 22 additions & 9 deletions screen/search/src/main/java/com/ivy/search/SearchScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.ivy.search

import androidx.compose.animation.core.animateDpAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
Expand All @@ -19,7 +20,8 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.ivy.base.legacy.stringRes
import com.ivy.base.legacy.Theme
import com.ivy.design.utils.IvyComponentPreview
import com.ivy.legacy.data.AppBaseData
import com.ivy.legacy.ui.SearchInput
import com.ivy.legacy.ui.component.transaction.transactions
Expand Down Expand Up @@ -78,7 +80,11 @@ private fun SearchUi(
}

Spacer(Modifier.height(16.dp))

val emptyStateTitle = stringResource(R.string.no_transactions)
val emptyStateText = stringResource(
R.string.no_transactions_for_query,
searchQueryTextFieldValue.text
)
LazyColumn(
modifier = Modifier.fillMaxSize(),
state = listState
Expand All @@ -96,11 +102,8 @@ private fun SearchUi(
setOverdueExpanded = { },
history = uiState.transactions,
onPayOrGet = { },
emptyStateTitle = stringRes(R.string.no_transactions),
emptyStateText = stringRes(
R.string.no_transactions_for_query,
searchQueryTextFieldValue.text
),
emptyStateTitle = emptyStateTitle,
emptyStateText = emptyStateText,
dateDividerMarginTop = 16.dp
)

Expand All @@ -122,8 +125,8 @@ private fun SearchUi(

@Preview
@Composable
private fun Preview() {
IvyPreview {
private fun Preview(isDark: Boolean = false) {
IvyPreview(isDark) {
SearchUi(
uiState = SearchState(
searchQuery = "Transaction",
Expand All @@ -136,3 +139,13 @@ private fun Preview() {
)
}
}

/** For screenshot testing */
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun SearchUiTest(isDark: Boolean) {
val theme = if (isDark) Theme.DARK else Theme.LIGHT
IvyComponentPreview(theme = theme) {
Preview(isDark)
}
}
21 changes: 21 additions & 0 deletions screen/search/src/test/java/com/ivy/search/SearchPaparazziTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.ivy.search

import com.google.testing.junit.testparameterinjector.TestParameter
import com.google.testing.junit.testparameterinjector.TestParameterInjector
import com.ivy.ui.testing.PaparazziScreenshotTest
import com.ivy.ui.testing.PaparazziTheme
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(TestParameterInjector::class)
class SearchPaparazziTest(
@TestParameter
private val theme: PaparazziTheme,
) : PaparazziScreenshotTest() {
@Test
fun `snapshot Search Screen`() {
snapshot(theme) {
SearchUiTest(theme == PaparazziTheme.Dark)
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions screen/settings/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ dependencies {
implementation(projects.temp.legacyCode)
implementation(projects.temp.oldDesign)
implementation(projects.widget.balance)

testImplementation(projects.shared.ui.testing)
}
15 changes: 13 additions & 2 deletions screen/settings/src/main/java/com/ivy/settings/SettingsScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1115,8 +1115,8 @@ private fun SettingsDefaultButton(
@ExperimentalFoundationApi
@Preview
@Composable
private fun Preview() {
IvyWalletPreview {
private fun Preview(theme: Theme = Theme.LIGHT) {
IvyWalletPreview(theme) {
UI(
nameLocalAccount = null,
theme = Theme.AUTO,
Expand All @@ -1127,3 +1127,14 @@ private fun Preview() {
)
}
}

/** For screenshot testing */
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun SettingsUiTest(isDark: Boolean) {
val theme = when (isDark) {
true -> Theme.DARK
false -> Theme.LIGHT
}
Preview(theme)
}
2 changes: 2 additions & 0 deletions screen/transactions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ dependencies {
implementation(projects.shared.ui.navigation)
implementation(projects.temp.legacyCode)
implementation(projects.temp.oldDesign)

testImplementation(projects.shared.ui.testing)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ivy.transactions

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraintsScope
Expand Down Expand Up @@ -43,8 +44,10 @@ import com.ivy.design.l0_system.UI
import com.ivy.design.l0_system.style
import com.ivy.design.utils.thenIf
import com.ivy.legacy.Constants
import com.ivy.legacy.IvyWalletPreview
import com.ivy.legacy.data.AppBaseData
import com.ivy.legacy.data.LegacyDueSection
import com.ivy.legacy.data.model.Month
import com.ivy.legacy.data.model.TimePeriod
import com.ivy.legacy.datamodel.Account
import com.ivy.legacy.ivyWalletCtx
Expand Down Expand Up @@ -897,9 +900,7 @@ private fun BoxWithConstraintsScope.Preview_crypto() {
private fun BoxWithConstraintsScope.Preview_empty_upcoming() {
IvyPreview {
UI(
period = TimePeriod.currentMonth(
startDayOfMonth = 1
), // preview
period = TimePeriod(month = Month.monthsList().first(), year = 2023),
baseCurrency = "BGN",
currency = "BGN",

Expand Down Expand Up @@ -939,3 +940,16 @@ private fun BoxWithConstraintsScope.Preview_empty_upcoming() {
)
}
}

/** For screenshot testing */
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun TransactionsUiTest(isDark: Boolean) {
val theme = when (isDark) {
true -> Theme.DARK
false -> Theme.LIGHT
}
IvyWalletPreview(theme) {
Preview_empty_upcoming()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.ivy.transactions

import com.google.testing.junit.testparameterinjector.TestParameter
import com.google.testing.junit.testparameterinjector.TestParameterInjector
import com.ivy.ui.testing.PaparazziScreenshotTest
import com.ivy.ui.testing.PaparazziTheme
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(TestParameterInjector::class)
class TransactionsPaparazziTest(
@TestParameter
private val theme: PaparazziTheme,
) : PaparazziScreenshotTest() {
@Test
fun `snapshot Transactions Screen`() {
snapshot(theme) {
TransactionsUiTest(theme == PaparazziTheme.Dark)
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4e25b3f

Please sign in to comment.