-
Notifications
You must be signed in to change notification settings - Fork 329
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Paywalls V2] Decode rectangle corners as optional (#4640)
* Decode rectangle corners as optional * And fix for shape * Added tests
- Loading branch information
1 parent
fc21382
commit 069df52
Showing
6 changed files
with
207 additions
and
3 deletions.
There are no files selected for viewing
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
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
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
82 changes: 82 additions & 0 deletions
82
Tests/UnitTests/Paywalls/Components/Properties/MaskShapeComponentTests.swift
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,82 @@ | ||
import Nimble | ||
@testable import RevenueCat | ||
import XCTest | ||
|
||
#if PAYWALL_COMPONENTS | ||
|
||
class MaskShapeComponentTests: TestCase { | ||
|
||
func testRectangleNoCorners() throws { | ||
let json = """ | ||
{ | ||
"type": "rectangle", | ||
} | ||
""" | ||
|
||
_ = try JSONDecoder.default.decode( | ||
PaywallComponent.MaskShape.self, | ||
from: json.data(using: .utf8)! | ||
) | ||
} | ||
|
||
func testRectangleWithCorners() throws { | ||
let json = """ | ||
{ | ||
"type": "rectangle", | ||
"corners": { | ||
"top_leading": 5, | ||
"top_trailing": 5, | ||
"bottom_leading": 5, | ||
"bottom_trailing": 5 | ||
} | ||
} | ||
""" | ||
|
||
_ = try JSONDecoder.default.decode( | ||
PaywallComponent.MaskShape.self, | ||
from: json.data(using: .utf8)! | ||
) | ||
} | ||
|
||
func testPill() throws { | ||
let json = """ | ||
{ | ||
"type": "pill", | ||
} | ||
""" | ||
|
||
_ = try JSONDecoder.default.decode( | ||
PaywallComponent.MaskShape.self, | ||
from: json.data(using: .utf8)! | ||
) | ||
} | ||
|
||
func testConvex() throws { | ||
let json = """ | ||
{ | ||
"type": "convex", | ||
} | ||
""" | ||
|
||
_ = try JSONDecoder.default.decode( | ||
PaywallComponent.MaskShape.self, | ||
from: json.data(using: .utf8)! | ||
) | ||
} | ||
|
||
func testConcave() throws { | ||
let json = """ | ||
{ | ||
"type": "concave", | ||
} | ||
""" | ||
|
||
_ = try JSONDecoder.default.decode( | ||
PaywallComponent.MaskShape.self, | ||
from: json.data(using: .utf8)! | ||
) | ||
} | ||
|
||
} | ||
|
||
#endif |
56 changes: 56 additions & 0 deletions
56
Tests/UnitTests/Paywalls/Components/Properties/ShapeComponentTests.swift
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,56 @@ | ||
import Nimble | ||
@testable import RevenueCat | ||
import XCTest | ||
|
||
#if PAYWALL_COMPONENTS | ||
|
||
class ShapeComponentTests: TestCase { | ||
|
||
func testRectangleNoCorners() throws { | ||
let json = """ | ||
{ | ||
"type": "rectangle", | ||
} | ||
""" | ||
|
||
_ = try JSONDecoder.default.decode( | ||
PaywallComponent.Shape.self, | ||
from: json.data(using: .utf8)! | ||
) | ||
} | ||
|
||
func testRectangleWithCorners() throws { | ||
let json = """ | ||
{ | ||
"type": "rectangle", | ||
"corners": { | ||
"top_leading": 5, | ||
"top_trailing": 5, | ||
"bottom_leading": 5, | ||
"bottom_trailing": 5 | ||
} | ||
} | ||
""" | ||
|
||
_ = try JSONDecoder.default.decode( | ||
PaywallComponent.Shape.self, | ||
from: json.data(using: .utf8)! | ||
) | ||
} | ||
|
||
func testPill() throws { | ||
let json = """ | ||
{ | ||
"type": "pill", | ||
} | ||
""" | ||
|
||
_ = try JSONDecoder.default.decode( | ||
PaywallComponent.Shape.self, | ||
from: json.data(using: .utf8)! | ||
) | ||
} | ||
|
||
} | ||
|
||
#endif |
46 changes: 46 additions & 0 deletions
46
Tests/UnitTests/Paywalls/Components/StackComponentTests.swift
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,46 @@ | ||
import Nimble | ||
@testable import RevenueCat | ||
import XCTest | ||
|
||
#if PAYWALL_COMPONENTS | ||
|
||
class StackComponentTests: TestCase { | ||
|
||
func testUnknownTypeWithSuccessfulFallbackDecodingAndEncodesAndRedecodes() throws { | ||
let jsonStack = """ | ||
{ | ||
"type": "stack", | ||
"dimension": { | ||
"type": "vertical", | ||
"alignment": "center", | ||
"distribution": "start" | ||
}, | ||
"size": { | ||
"width": { "type": "fill" }, | ||
"height": { "type": "fill" } | ||
}, | ||
"padding": { | ||
"top": 0, | ||
"bottom": 0, | ||
"leading": 0, | ||
"trailing": 0 | ||
}, | ||
"margin": { | ||
"top": 0, | ||
"bottom": 0, | ||
"leading": 0, | ||
"trailing": 0 | ||
}, | ||
"components": [] | ||
} | ||
""" | ||
|
||
_ = try JSONDecoder.default.decode( | ||
PaywallComponent.StackComponent.self, | ||
from: jsonStack.data(using: .utf8)! | ||
) | ||
} | ||
|
||
} | ||
|
||
#endif |