-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Paywalls
: improved support for dynamic type with snapshots (#2827)
This improves the layout of the template, and adds a scroll view that optionally scrolls if the content is too large. This can serve as a the basis for future templates. ![iOS16-testAccessibility3 1](https://github.com/RevenueCat/purchases-ios/assets/685609/40cb6929-d7f0-49d4-a9c5-7fdea9747db9)
- Loading branch information
Showing
6 changed files
with
219 additions
and
82 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// BaseSnapshotTest.swift | ||
// | ||
// | ||
// Created by Nacho Soto on 7/17/23. | ||
// | ||
import Nimble | ||
import RevenueCat | ||
@testable import RevenueCatUI | ||
import SnapshotTesting | ||
import XCTest | ||
|
||
@available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *) | ||
class BaseSnapshotTest: TestCase { | ||
|
||
override class func setUp() { | ||
super.setUp() | ||
|
||
// isRecording = true | ||
} | ||
|
||
} | ||
|
||
@available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *) | ||
extension BaseSnapshotTest { | ||
|
||
static let eligibleChecker: TrialOrIntroEligibilityChecker = .producing(eligibility: .eligible) | ||
static let ineligibleChecker: TrialOrIntroEligibilityChecker = .producing(eligibility: .ineligible) | ||
static let purchaseHandler: PurchaseHandler = .mock() | ||
|
||
static let fullScreenSize: CGSize = .init(width: 460, height: 950) | ||
|
||
} |
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,32 @@ | ||
// | ||
// DataExtensions.swift | ||
// | ||
// | ||
// Created by Nacho Soto on 7/17/23. | ||
// | ||
|
||
import Foundation | ||
import RevenueCat | ||
import RevenueCatUI | ||
|
||
// MARK: - Extensions | ||
|
||
extension Offering { | ||
|
||
var paywallWithLocalImage: PaywallData { | ||
return self.paywall!.withLocalImage | ||
} | ||
|
||
} | ||
|
||
extension PaywallData { | ||
|
||
var withLocalImage: Self { | ||
var copy = self | ||
copy.assetBaseURL = URL(fileURLWithPath: Bundle.module.bundlePath) | ||
copy.config.headerImageName = "image.png" | ||
|
||
return copy | ||
} | ||
|
||
} |
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,77 @@ | ||
// | ||
// PaywallViewDynamicTypeTests.swift | ||
// | ||
// | ||
// Created by Nacho Soto on 7/17/23. | ||
// | ||
|
||
import Nimble | ||
import RevenueCat | ||
@testable import RevenueCatUI | ||
import SnapshotTesting | ||
import SwiftUI | ||
|
||
@available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *) | ||
class PaywallViewDynamicTypeTests: BaseSnapshotTest { | ||
|
||
func testXSmall() { | ||
Self.test(.xSmall) | ||
} | ||
|
||
func testSmall() { | ||
Self.test(.small) | ||
} | ||
|
||
func testMedium() { | ||
Self.test(.medium) | ||
} | ||
|
||
func testLarge() { | ||
Self.test(.xLarge) | ||
} | ||
|
||
func testXLarge() { | ||
Self.test(.xLarge) | ||
} | ||
|
||
func testXXLarge() { | ||
Self.test(.xxLarge) | ||
} | ||
|
||
func testXXXLarge() { | ||
Self.test(.xxxLarge) | ||
} | ||
|
||
func testAccessibility1() { | ||
Self.test(.accessibility1) | ||
} | ||
|
||
func testAccessibility3() { | ||
Self.test(.accessibility3) | ||
} | ||
|
||
func testAccessibility5() { | ||
Self.test(.accessibility5) | ||
} | ||
|
||
} | ||
|
||
@available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *) | ||
private extension PaywallViewDynamicTypeTests { | ||
|
||
static func test(_ type: DynamicTypeSize) { | ||
Self.createView(type) | ||
.snapshot(size: Self.fullScreenSize) | ||
} | ||
|
||
private static func createView(_ type: DynamicTypeSize) -> some View { | ||
let offering = TestData.offeringWithIntroOffer | ||
|
||
return PaywallView(offering: offering, | ||
paywall: offering.paywallWithLocalImage, | ||
introEligibility: Self.eligibleChecker, | ||
purchaseHandler: Self.purchaseHandler) | ||
.dynamicTypeSize(type) | ||
} | ||
|
||
} |
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