-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Paywalls: Add support for sub_period
variable
#1264
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package com.revenuecat.purchases.ui.revenuecatui.data.processed | ||
|
||
import com.revenuecat.purchases.Package | ||
import com.revenuecat.purchases.PackageType | ||
import com.revenuecat.purchases.ui.revenuecatui.R | ||
import com.revenuecat.purchases.ui.revenuecatui.helpers.ApplicationContext | ||
import java.util.Locale | ||
|
||
|
@@ -28,7 +30,17 @@ internal class VariableDataProvider( | |
} | ||
|
||
fun periodName(rcPackage: Package): String { | ||
return "PERIOD_NAME" | ||
val stringId = when (rcPackage.packageType) { | ||
PackageType.LIFETIME -> R.string.lifetime | ||
PackageType.ANNUAL -> R.string.annual | ||
PackageType.SIX_MONTH -> R.string.semester | ||
PackageType.THREE_MONTH -> R.string.quarter | ||
PackageType.TWO_MONTH -> R.string.bimonthly | ||
PackageType.MONTHLY -> R.string.monthly | ||
PackageType.WEEKLY -> R.string.weekly | ||
PackageType.UNKNOWN, PackageType.CUSTOM -> null | ||
} | ||
return stringId?.let { applicationContext.getString(it) } ?: "" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm defaulting to an empty string, which I think is the same we do in iOS. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍🏻 |
||
} | ||
|
||
fun subscriptionDuration(rcPackage: Package): String? { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="restore_purchases">Restore purchases</string> | ||
<string name="annual">Annual</string> | ||
<string name="semester">6 month</string> | ||
<string name="quarter">3 month</string> | ||
<string name="bimonthly">2 month</string> | ||
<string name="monthly">Monthly</string> | ||
<string name="weekly">Weekly</string> | ||
<string name="lifetime">Lifetime</string> | ||
</resources> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,10 @@ package com.revenuecat.purchases.ui.revenuecatui.data.processed | |
import android.net.Uri | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.revenuecat.purchases.Package | ||
import com.revenuecat.purchases.PackageType | ||
import com.revenuecat.purchases.ui.revenuecatui.PaywallViewMode | ||
import com.revenuecat.purchases.ui.revenuecatui.data.MockApplicationContext | ||
import com.revenuecat.purchases.ui.revenuecatui.data.TestData | ||
import com.revenuecat.purchases.ui.revenuecatui.helpers.ApplicationContext | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.Before | ||
import org.junit.Test | ||
|
@@ -16,21 +17,14 @@ import java.util.Locale | |
internal class TemplateConfigurationFactoryTest { | ||
|
||
private val paywallViewMode = PaywallViewMode.FULL_SCREEN | ||
private val testAppName = "testAppName" | ||
|
||
private lateinit var variableDataProvider: VariableDataProvider | ||
|
||
private lateinit var template2Configuration: TemplateConfiguration | ||
|
||
@Before | ||
fun setUp() { | ||
variableDataProvider = VariableDataProvider( | ||
applicationContext = object : ApplicationContext { | ||
override fun getApplicationName(): String { | ||
return testAppName | ||
} | ||
} | ||
) | ||
variableDataProvider = VariableDataProvider(MockApplicationContext()) | ||
template2Configuration = TemplateConfigurationFactory.create( | ||
variableDataProvider, | ||
paywallViewMode, | ||
|
@@ -87,14 +81,20 @@ internal class TemplateConfigurationFactoryTest { | |
|
||
private fun getPackageInfo(rcPackage: Package): TemplateConfiguration.PackageInfo { | ||
val localizedConfiguration = TestData.template2.configForLocale(Locale.US)!! | ||
val periodName = when(rcPackage.packageType) { | ||
PackageType.ANNUAL -> "Annual" | ||
PackageType.MONTHLY -> "Monthly" | ||
PackageType.WEEKLY -> "Weekly" | ||
else -> error("Unknown package type ${rcPackage.packageType}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't like copying this here... But I thought it was better to kind of duplicate this logic than use the real code during the tests. |
||
} | ||
val processedLocalization = ProcessedLocalizedConfiguration( | ||
title = localizedConfiguration.title, | ||
subtitle = localizedConfiguration.subtitle, | ||
callToAction = "Subscribe for PRICE_PER_PERIOD", | ||
callToActionWithIntroOffer = null, | ||
offerDetails = "PRICE_AND_PER_MONTH", | ||
offerDetailsWithIntroOffer = "PRICE_AND_PER_MONTH after INT_OFFER_DURATION trial", | ||
offerName = "PERIOD_NAME", | ||
offerName = periodName, | ||
features = emptyList(), | ||
) | ||
return TemplateConfiguration.PackageInfo( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,10 @@ package com.revenuecat.purchases.ui.revenuecatui.data.processed | |
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.revenuecat.purchases.Package | ||
import com.revenuecat.purchases.models.Price | ||
import com.revenuecat.purchases.models.StoreProduct | ||
import com.revenuecat.purchases.PackageType | ||
import com.revenuecat.purchases.ui.revenuecatui.data.MockApplicationContext | ||
import com.revenuecat.purchases.ui.revenuecatui.data.TestData | ||
import com.revenuecat.purchases.ui.revenuecatui.helpers.ApplicationContext | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.Before | ||
import org.junit.Test | ||
|
@@ -26,11 +24,7 @@ class VariableProcessorTest { | |
|
||
@Before | ||
fun setUp() { | ||
applicationContext = object : ApplicationContext { | ||
override fun getApplicationName(): String { | ||
return "test app name" | ||
} | ||
} | ||
applicationContext = MockApplicationContext() | ||
variableDataProvider = VariableDataProvider(applicationContext) | ||
rcPackage = TestData.Packages.annual | ||
} | ||
|
@@ -50,14 +44,14 @@ class VariableProcessorTest { | |
@Test | ||
fun `process variables returns processed text with single variable`() { | ||
val originalText = "text with {{ app_name }} one variable" | ||
val expectedText = "text with test app name one variable" | ||
val expectedText = "text with Mock Paywall one variable" | ||
expectVariablesResult(originalText, expectedText) | ||
} | ||
|
||
@Test | ||
fun `process variables returns processed text with multiple variable`() { | ||
val originalText = "text with {{ app_name }} and {{ sub_price_per_month }} multiple variables" | ||
val expectedText = "text with test app name and $5.67 multiple variables" | ||
val expectedText = "text with Mock Paywall and $5.67 multiple variables" | ||
expectVariablesResult(originalText, expectedText) | ||
} | ||
|
||
|
@@ -77,7 +71,7 @@ class VariableProcessorTest { | |
|
||
@Test | ||
fun `process variables processes app_name`() { | ||
expectVariablesResult("{{ app_name }}", "test app name") | ||
expectVariablesResult("{{ app_name }}", "Mock Paywall") | ||
} | ||
|
||
@Test | ||
|
@@ -103,8 +97,20 @@ class VariableProcessorTest { | |
} | ||
|
||
@Test | ||
fun `process variables processes sub_period`() { | ||
expectVariablesResult("{{ sub_period }}", "PERIOD_NAME") | ||
fun `process variables processes sub_period annual`() { | ||
expectVariablesResult("{{ sub_period }}", "Annual") | ||
} | ||
|
||
@Test | ||
fun `process variables processes sub_period monthly`() { | ||
rcPackage = TestData.Packages.monthly | ||
expectVariablesResult("{{ sub_period }}", "Monthly") | ||
} | ||
|
||
@Test | ||
fun `process variables processes sub_period custom period`() { | ||
rcPackage = TestData.Packages.annual.copy(packageType = PackageType.CUSTOM) | ||
expectVariablesResult("{{ sub_period }}", "") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just want to confirm this is what we expect @NachoSoto There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah 👍🏻 I don't have a test for this in iOS but this is fine. |
||
} | ||
|
||
@Test | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied the strings from iOS. Though it felt a bit weird to not make this plural