Skip to content
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 V2] Adds CornerRadiuses, Shape and MaskShape properties #1924

Merged
merged 15 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
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
}
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
}
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)
}
}
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)
}
}
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)
}
}