This adds the first screen for badge gifting. It lets you see the gift badge, pick the currency, and advance to the next screen. It also adds a skeleton for the next screen, so there's somewhere to advance to, but that screen is unfinished. All of this is behind disabled flags, so this should have no user impact.
47 lines
1.6 KiB
Swift
47 lines
1.6 KiB
Swift
//
|
|
// Copyright (c) 2022 Open Whisper Systems. All rights reserved.
|
|
//
|
|
|
|
import XCTest
|
|
@testable import Signal
|
|
|
|
class BadgeGiftingChooseBadgeViewControllerStateTest: XCTestCase {
|
|
typealias State = BadgeGiftingChooseBadgeViewController.State
|
|
|
|
private func getGiftBadge() -> ProfileBadge {
|
|
try! ProfileBadge(jsonDictionary: [
|
|
"id": "GIFT",
|
|
"category": "donor",
|
|
"name": "A Gift",
|
|
"description": "A gift badge!",
|
|
"sprites6": ["ldpi.png", "mdpi.png", "hdpi.png", "xhdpi.png", "xxhdpi.png", "xxxhdpi.png"]
|
|
])
|
|
}
|
|
|
|
func testCanContinue() throws {
|
|
let stuck: [State] = [.initializing, .loading, .loadFailed]
|
|
stuck.forEach { XCTAssertFalse($0.canContinue) }
|
|
|
|
let notStuck: State = .loaded(selectedCurrencyCode: "EUR", badge: getGiftBadge(), pricesByCurrencyCode: ["EUR": 123, "USD": 456])
|
|
XCTAssertTrue(notStuck.canContinue)
|
|
}
|
|
|
|
func testSelectCurrencyCode() throws {
|
|
let badge = getGiftBadge()
|
|
|
|
let before = State.loaded(selectedCurrencyCode: "USD", badge: badge, pricesByCurrencyCode: ["EUR": 123, "USD": 456])
|
|
let after = before.selectCurrencyCode("EUR")
|
|
|
|
func assertCurrencyCode(_ state: State, expected: Currency.Code) throws {
|
|
switch state {
|
|
case let .loaded(actual, _, _):
|
|
XCTAssertEqual(actual, expected)
|
|
default:
|
|
XCTFail("Invalid state")
|
|
}
|
|
}
|
|
try assertCurrencyCode(before, expected: "USD")
|
|
try assertCurrencyCode(after, expected: "EUR")
|
|
}
|
|
}
|