Skip to content

Debugview: Add snapshot tests for debug view using Paparazzi#1187

Merged
tonidero merged 18 commits into
mainfrom
debug-view-ui-tests
Aug 8, 2023
Merged

Debugview: Add snapshot tests for debug view using Paparazzi#1187
tonidero merged 18 commits into
mainfrom
debug-view-ui-tests

Conversation

@tonidero

@tonidero tonidero commented Aug 2, 2023

Copy link
Copy Markdown
Contributor

Description

This PR adds some simple snapshot tests for the debug view using Paparazzi. This allows us to not need an emulator, since it uses the android studio engine to generate the snapshots.

@tonidero tonidero added the test label Aug 2, 2023
@codecov

codecov Bot commented Aug 2, 2023

Copy link
Copy Markdown

Codecov Report

Merging #1187 (9ccb8e6) into main (b1f7ece) will not change coverage.
The diff coverage is n/a.

❗ Current head 9ccb8e6 differs from pull request most recent head 3d8b580. Consider uploading reports for the commit 3d8b580 to get more accurate results

@@           Coverage Diff           @@
##             main    #1187   +/-   ##
=======================================
  Coverage   85.92%   85.92%           
=======================================
  Files         181      181           
  Lines        6217     6217           
  Branches      900      900           
=======================================
  Hits         5342     5342           
  Misses        533      533           
  Partials      342      342           

@tonidero tonidero force-pushed the debug-view-2 branch 2 times, most recently from 245a982 to da87a22 Compare August 3, 2023 09:59
Base automatically changed from debug-view-2 to main August 3, 2023 10:15
@tonidero tonidero force-pushed the debug-view-ui-tests branch from 7f8712d to 9813a81 Compare August 4, 2023 11:10
@tonidero tonidero changed the title Add UI tests for debug view Add snapshot tests for debug view using Paparazzi Aug 4, 2023
@tonidero tonidero force-pushed the debug-view-ui-tests branch from 49814ff to 5926a5c Compare August 7, 2023 08:23
toastMessage,
Toast.LENGTH_LONG,
).show()
viewModel.toastDisplayed()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was wrong, we should only call this after displaying the toast

Comment thread gradle.properties
android.useAndroidX=true
android.enableJetifier=true
# This is needed for paparazzi to work through jetifier.
android.jetifier.ignorelist=android-base-common,common

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should see if we still need to enable jetifier... For now, this was part of the documentation and didn't find any issues after this.

factory = InternalDebugRevenueCatScreenViewModelFactory(onPurchaseCompleted, onPurchaseErrored),
),
screenViewModel: DebugRevenueCatViewModel? = null,
activity: Activity? = null,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to be able to pass a mock activity now since this is no longer instrumentation tests (doesn't require a device).

@Test
fun notConfiguredStateDisplaysCorrectly() {
snapshotTest {
InternalDebugRevenueCatScreen(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to use the bottom sheet instead of the Screen composable directly, but couldn't get it to work. I changed to this and it worked like a charm, and I think it covers most of what we want.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is fine 👍🏻

@tonidero tonidero marked this pull request as ready for review August 7, 2023 09:19
@tonidero tonidero requested a review from a team August 7, 2023 09:20
@tonidero tonidero changed the title Add snapshot tests for debug view using Paparazzi Debugview: Add snapshot tests for debug view using Paparazzi Aug 7, 2023

@NachoSoto NachoSoto left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏🏻

onPurchaseErrored: (PurchasesTransactionException) -> Unit,
isVisible: Boolean = false,
onDismissCallback: (() -> Unit)? = null,
viewModel: DebugRevenueCatViewModel? = null,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It think this could clarify that passing nil will create a default view model.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add a comment 👍

@Preview(showBackground = true)
@Composable
private fun SettingGroupPreview() {
val viewModel = object : DebugRevenueCatViewModel {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

import com.revenuecat.purchases.models.SubscriptionOptions

@Suppress("MagicNumber")
internal val testOffering: Offering

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@Test
fun notConfiguredStateDisplaysCorrectly() {
snapshotTest {
InternalDebugRevenueCatScreen(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is fine 👍🏻


private fun snapshotTest(composable: @Composable () -> Unit) {
paparazzi.snapshot {
Column(modifier = Modifier.heightIn(max = maxHeight)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@tonidero tonidero enabled auto-merge (squash) August 8, 2023 09:20
@tonidero tonidero merged commit fa0aa89 into main Aug 8, 2023
@tonidero tonidero deleted the debug-view-ui-tests branch August 8, 2023 09:34
tonidero pushed a commit that referenced this pull request Aug 10, 2023
**This is an automatic release.**

### Bugfixes
* Fix NoSuchElementException by using poll when accessing
serviceRequests (#1190) via Cesar de la Vega (@vegaro)
### Other Changes
* Debug view: rename package (#1191) via Toni Rico (@tonidero)
* Debugview: Add snapshot tests for debug view using Paparazzi (#1187)
via Toni Rico (@tonidero)
* Debug view: Add offerings section and purchasing capabilities (#1186)
via Toni Rico (@tonidero)
* Debug view: Initial UI + Usage in MagicWeatherCompose (#1075) via Toni
Rico (@tonidero)
* Remove customEntitlementComputation flavor for non-purchases modules
(#1180) via Toni Rico (@tonidero)

Co-authored-by: revenuecat-ops <ops@revenuecat.com>
tonidero added a commit that referenced this pull request Aug 16, 2023
…ew` package (#1192)

### Description
This sets up the project to be able to deploy the `defaultsRelease`
variant as `purchases-debug-view-noop` package and `defaultsDebug`
variant as `purchases-debug-view`

Hold until #1187 and #1191 are merged.
@vegaro vegaro added pr:other and removed pr:test labels Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants