Skip to content

Commit

Permalink
Arabic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NachoSoto committed Sep 1, 2023
1 parent 0a696e0 commit 22de90f
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions Tests/RevenueCatUITests/Data/PackageVariablesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@ class PackageVariablesTests: TestCase {
expect(TestData.lifetimePackage.localizedPricePerPeriod(Self.spanish)) == "$119.49"
}

func testArabicLocalizedPricePerPeriod() {
let arabicPrice = "٣.٩٩ درهم"

expect(TestData.weeklyPackage.with(arabicPrice, Self.arabic).localizedPricePerPeriod(Self.arabic))
== "٣.٩٩ درهم/أسبوع"
expect(TestData.monthlyPackage.with(arabicPrice, Self.arabic).localizedPricePerPeriod(Self.arabic))
== "٣.٩٩ درهم/شهر"
expect(TestData.threeMonthPackage.with(arabicPrice, Self.arabic).localizedPricePerPeriod(Self.arabic))
== "٣.٩٩ درهم/3شهر"
expect(TestData.sixMonthPackage.with(arabicPrice, Self.arabic).localizedPricePerPeriod(Self.arabic))
== "٣.٩٩ درهم/6شهر"
expect(TestData.annualPackage.with(arabicPrice, Self.arabic).localizedPricePerPeriod(Self.arabic))
== "٣.٩٩ درهم/سنة"
expect(TestData.lifetimePackage.with(arabicPrice, Self.arabic).localizedPricePerPeriod(Self.arabic))
== "٣.٩٩ درهم"
}

func testEnglishLocalizedPriceAndPerMonth() {
expect(TestData.weeklyPackage.localizedPriceAndPerMonth(Self.english)) == "$1.99 ($7.96/mo)"
expect(TestData.monthlyPackage.localizedPriceAndPerMonth(Self.english)) == "$6.99/mo"
Expand All @@ -75,6 +92,23 @@ class PackageVariablesTests: TestCase {
expect(TestData.lifetimePackage.localizedPriceAndPerMonth(Self.spanish)) == "$119.49"
}

func testArabicLocalizedPriceAndPerMonth() {
let arabicPrice = "٣.٩٩ درهم"

expect(TestData.weeklyPackage.with(arabicPrice, Self.arabic).localizedPriceAndPerMonth(Self.arabic))
== "٣.٩٩ درهم (‏7.96 ‏د.إ.‏/شهر)"
expect(TestData.monthlyPackage.with(arabicPrice, Self.arabic).localizedPriceAndPerMonth(Self.arabic))
== "٣.٩٩ درهم/شهر"
expect(TestData.threeMonthPackage.with(arabicPrice, Self.arabic).localizedPriceAndPerMonth(Self.arabic))
== "٣.٩٩ درهم (‏1.66 ‏د.إ.‏/شهر)"
expect(TestData.sixMonthPackage.with(arabicPrice, Self.arabic).localizedPriceAndPerMonth(Self.arabic))
== "٣.٩٩ درهم (‏1.33 ‏د.إ.‏/شهر)"
expect(TestData.annualPackage.with(arabicPrice, Self.arabic).localizedPriceAndPerMonth(Self.arabic))
== "٣.٩٩ درهم (‏4.49 ‏د.إ.‏/شهر)"
expect(TestData.lifetimePackage.with(arabicPrice, Self.arabic).localizedPriceAndPerMonth(Self.arabic))
== arabicPrice
}

func testProductName() {
expect(TestData.weeklyPackage.productName) == "Weekly"
expect(TestData.monthlyPackage.productName) == "Monthly"
Expand Down Expand Up @@ -130,5 +164,57 @@ private extension PackageVariablesTests {

static let english: Locale = .init(identifier: "en_US")
static let spanish: Locale = .init(identifier: "es_ES")
static let arabic: Locale = .init(identifier: "ar_AE")

}

// MARK: -

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
private extension Package {

func with(_ newLocalizedPrice: String, _ locale: Locale) -> Package {
return .init(
identifier: self.identifier,
packageType: self.packageType,
storeProduct: self.storeProduct
.toTestProduct()
.with(newLocalizedPrice, locale)
.toStoreProduct(),
offeringIdentifier: self.offeringIdentifier
)
}

}

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
private extension TestStoreProduct {

func with(_ newLocalizedPrice: String, _ locale: Locale) -> Self {
var copy = self
copy.localizedPriceString = newLocalizedPrice
copy.locale = locale

return copy
}

}

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
private extension StoreProduct {

func toTestProduct() -> TestStoreProduct {
return .init(
localizedTitle: self.localizedTitle,
price: self.price,
localizedPriceString: self.localizedPriceString,
productIdentifier: self.productIdentifier,
productType: self.productType,
localizedDescription: self.localizedDescription,
subscriptionGroupIdentifier: self.subscriptionGroupIdentifier,
subscriptionPeriod: self.subscriptionPeriod,
isFamilyShareable: self.isFamilyShareable
)
}

}

0 comments on commit 22de90f

Please sign in to comment.