-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Paywalls V2] Adds CornerRadiuses, Shape and MaskShape properties (#1924
- Loading branch information
1 parent
a93881d
commit 76c523e
Showing
6 changed files
with
369 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
...src/main/kotlin/com/revenuecat/purchases/paywalls/components/properties/CornerRadiuses.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.revenuecat.purchases.paywalls.components.properties | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
/** | ||
* Contains radius values for 4 corners, in dp. | ||
*/ | ||
@Serializable | ||
internal data class CornerRadiuses( | ||
/** | ||
* The top-leading, or top-start, corner radius, in dp. | ||
*/ | ||
@SerialName("top_leading") | ||
val topLeading: Double, | ||
/** | ||
* The top-trailing, or top-end, corner radius, in dp. | ||
*/ | ||
@SerialName("top_trailing") | ||
val topTrailing: Double, | ||
/** | ||
* The bottom-leading, or bottom-start, corner radius, in dp. | ||
*/ | ||
@SerialName("bottom_leading") | ||
val bottomLeading: Double, | ||
/** | ||
* The bottom-trailing, or bottom-end, corner radius, in dp. | ||
*/ | ||
@SerialName("bottom_trailing") | ||
val bottomTrailing: Double, | ||
) { | ||
companion object { | ||
val zero = CornerRadiuses(0.0, 0.0, 0.0, 0.0) | ||
val default = zero | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...ases/src/main/kotlin/com/revenuecat/purchases/paywalls/components/properties/MaskShape.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.revenuecat.purchases.paywalls.components.properties | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
internal sealed interface MaskShape { | ||
|
||
@Serializable | ||
@SerialName("rectangle") | ||
data class Rectangle( | ||
val corners: CornerRadiuses? = null, | ||
) : MaskShape | ||
|
||
@Serializable | ||
@SerialName("pill") | ||
object Pill : MaskShape | ||
|
||
@Serializable | ||
@SerialName("concave") | ||
object Concave : MaskShape | ||
|
||
@Serializable | ||
@SerialName("convex") | ||
object Convex : MaskShape | ||
} |
18 changes: 18 additions & 0 deletions
18
purchases/src/main/kotlin/com/revenuecat/purchases/paywalls/components/properties/Shape.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.revenuecat.purchases.paywalls.components.properties | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
internal sealed interface Shape { | ||
|
||
@Serializable | ||
@SerialName("rectangle") | ||
data class Rectangle( | ||
val corners: CornerRadiuses? = null, | ||
) : Shape | ||
|
||
@Serializable | ||
@SerialName("pill") | ||
object Pill : Shape | ||
} |
73 changes: 73 additions & 0 deletions
73
.../test/java/com/revenuecat/purchases/paywalls/components/properties/CornerRadiusesTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.revenuecat.purchases.paywalls.components.properties | ||
|
||
import com.revenuecat.purchases.common.OfferingParser | ||
import org.intellij.lang.annotations.Language | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.junit.runners.Parameterized | ||
|
||
@RunWith(Parameterized::class) | ||
internal class CornerRadiusesTests(@Suppress("UNUSED_PARAMETER") name: String, private val args: Args) { | ||
|
||
class Args( | ||
@Language("json") | ||
val json: String, | ||
val expected: CornerRadiuses, | ||
) | ||
|
||
companion object { | ||
|
||
@Suppress("LongMethod") | ||
@JvmStatic | ||
@Parameterized.Parameters(name = "{0}") | ||
fun parameters(): Collection<*> = listOf( | ||
arrayOf( | ||
"ints", | ||
Args( | ||
json = """ | ||
{ | ||
"top_leading": 1, | ||
"top_trailing": 2, | ||
"bottom_leading": 3, | ||
"bottom_trailing": 4 | ||
} | ||
""".trimIndent(), | ||
expected = CornerRadiuses( | ||
topLeading = 1.0, | ||
topTrailing = 2.0, | ||
bottomLeading = 3.0, | ||
bottomTrailing = 4.0, | ||
) | ||
) | ||
), | ||
arrayOf( | ||
"floats", | ||
Args( | ||
json = """ | ||
{ | ||
"top_leading": 1.2, | ||
"top_trailing": 2.3, | ||
"bottom_leading": 3.4, | ||
"bottom_trailing": 4.5 | ||
} | ||
""".trimIndent(), | ||
expected = CornerRadiuses( | ||
topLeading = 1.2, | ||
topTrailing = 2.3, | ||
bottomLeading = 3.4, | ||
bottomTrailing = 4.5, | ||
) | ||
) | ||
), | ||
) | ||
} | ||
|
||
@Test | ||
fun `Should properly deserialize CornerRadiuses`() { | ||
// Arrange, Act | ||
val actual = OfferingParser.json.decodeFromString<CornerRadiuses>(args.json) | ||
|
||
// Assert | ||
assert(actual == args.expected) | ||
} | ||
} |
119 changes: 119 additions & 0 deletions
119
...s/src/test/java/com/revenuecat/purchases/paywalls/components/properties/MaskShapeTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package com.revenuecat.purchases.paywalls.components.properties | ||
|
||
import com.revenuecat.purchases.common.OfferingParser | ||
import org.intellij.lang.annotations.Language | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.junit.runners.Parameterized | ||
|
||
@RunWith(Parameterized::class) | ||
internal class MaskShapeTests(@Suppress("UNUSED_PARAMETER") name: String, private val args: Args) { | ||
|
||
class Args( | ||
@Language("json") | ||
val json: String, | ||
val expected: MaskShape, | ||
) | ||
|
||
companion object { | ||
|
||
@Suppress("LongMethod") | ||
@JvmStatic | ||
@Parameterized.Parameters(name = "{0}") | ||
fun parameters(): Collection<*> = listOf( | ||
arrayOf( | ||
"rectangle - corners present", | ||
Args( | ||
json = """ | ||
{ | ||
"corners": { | ||
"top_leading": 1, | ||
"top_trailing": 2, | ||
"bottom_leading": 3, | ||
"bottom_trailing": 4 | ||
}, | ||
"type": "rectangle" | ||
} | ||
""".trimIndent(), | ||
expected = MaskShape.Rectangle( | ||
corners = CornerRadiuses( | ||
topLeading = 1.0, | ||
topTrailing = 2.0, | ||
bottomLeading = 3.0, | ||
bottomTrailing = 4.0 | ||
) | ||
) | ||
) | ||
), | ||
arrayOf( | ||
"rectangle - corners absent", | ||
Args( | ||
json = """ | ||
{ | ||
"type": "rectangle" | ||
} | ||
""".trimIndent(), | ||
expected = MaskShape.Rectangle( | ||
corners = null | ||
) | ||
) | ||
), | ||
arrayOf( | ||
"rectangle - corners null", | ||
Args( | ||
json = """ | ||
{ | ||
"corners": null, | ||
"type": "rectangle" | ||
} | ||
""".trimIndent(), | ||
expected = MaskShape.Rectangle( | ||
corners = null | ||
) | ||
) | ||
), | ||
arrayOf( | ||
"pill", | ||
Args( | ||
json = """ | ||
{ | ||
"type": "pill" | ||
} | ||
""".trimIndent(), | ||
expected = MaskShape.Pill | ||
) | ||
), | ||
arrayOf( | ||
"concave", | ||
Args( | ||
json = """ | ||
{ | ||
"type": "concave" | ||
} | ||
""".trimIndent(), | ||
expected = MaskShape.Concave | ||
) | ||
), | ||
arrayOf( | ||
"convex", | ||
Args( | ||
json = """ | ||
{ | ||
"type": "convex" | ||
} | ||
""".trimIndent(), | ||
expected = MaskShape.Convex | ||
) | ||
), | ||
) | ||
} | ||
|
||
@Test | ||
fun `Should properly deserialize MaskShape`() { | ||
// Arrange, Act | ||
val actual = OfferingParser.json.decodeFromString<MaskShape>(args.json) | ||
|
||
// Assert | ||
assert(actual == args.expected) | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
...hases/src/test/java/com/revenuecat/purchases/paywalls/components/properties/ShapeTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.revenuecat.purchases.paywalls.components.properties | ||
|
||
import com.revenuecat.purchases.common.OfferingParser | ||
import org.intellij.lang.annotations.Language | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.junit.runners.Parameterized | ||
|
||
@RunWith(Parameterized::class) | ||
internal class ShapeTests(@Suppress("UNUSED_PARAMETER") name: String, private val args: Args) { | ||
|
||
class Args( | ||
@Language("json") | ||
val json: String, | ||
val expected: Shape, | ||
) | ||
|
||
companion object { | ||
|
||
@Suppress("LongMethod") | ||
@JvmStatic | ||
@Parameterized.Parameters(name = "{0}") | ||
fun parameters(): Collection<*> = listOf( | ||
arrayOf( | ||
"rectangle - corners present", | ||
Args( | ||
json = """ | ||
{ | ||
"corners": { | ||
"top_leading": 1, | ||
"top_trailing": 2, | ||
"bottom_leading": 3, | ||
"bottom_trailing": 4 | ||
}, | ||
"type": "rectangle" | ||
} | ||
""".trimIndent(), | ||
expected = Shape.Rectangle( | ||
corners = CornerRadiuses( | ||
topLeading = 1.0, | ||
topTrailing = 2.0, | ||
bottomLeading = 3.0, | ||
bottomTrailing = 4.0 | ||
) | ||
) | ||
) | ||
), | ||
arrayOf( | ||
"rectangle - corners absent", | ||
Args( | ||
json = """ | ||
{ | ||
"type": "rectangle" | ||
} | ||
""".trimIndent(), | ||
expected = Shape.Rectangle( | ||
corners = null | ||
) | ||
) | ||
), | ||
arrayOf( | ||
"rectangle - corners null", | ||
Args( | ||
json = """ | ||
{ | ||
"corners": null, | ||
"type": "rectangle" | ||
} | ||
""".trimIndent(), | ||
expected = Shape.Rectangle( | ||
corners = null | ||
) | ||
) | ||
), | ||
arrayOf( | ||
"pill", | ||
Args( | ||
json = """ | ||
{ | ||
"type": "pill" | ||
} | ||
""".trimIndent(), | ||
expected = Shape.Pill | ||
) | ||
), | ||
) | ||
} | ||
|
||
@Test | ||
fun `Should properly deserialize Shape`() { | ||
// Arrange, Act | ||
val actual = OfferingParser.json.decodeFromString<Shape>(args.json) | ||
|
||
// Assert | ||
assert(actual == args.expected) | ||
} | ||
} |