Created
July 27, 2022 05:30
-
-
Save fishkingsin/4a4584bf4bcee2620ae31f185192816a to your computer and use it in GitHub Desktop.
USDFRenewalPopupViewModelTests.swift
This file contains hidden or 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
// | |
// USDFRenewalPopupViewModelTests.swift | |
// ChiefTests | |
// | |
// Created by on_luk on 26/7/2022. | |
// | |
import XCTest | |
import Combine | |
@testable import ChiefMT | |
class USDFRenewalPopupViewModelTests: XCTestCase { | |
var viewModel: USDFRenewalPopupViewModelType! | |
private var cancellable = Set<AnyCancellable>() | |
private var expectation: XCTestExpectation? | |
override func setUp() { | |
super.setUp() | |
viewModel = USDFRenewalPopupViewModel(appState: CHFAppState.shared) | |
bind() | |
} | |
override func tearDown() { | |
viewModel = nil | |
super.tearDown() | |
} | |
func testAll() { | |
test_viewDidLoadWithStaticContents() | |
test_actions() | |
} | |
private func test_viewDidLoad(with lang: CHFLanguage) { | |
CHFAppState.shared.language.value = lang | |
viewModel.inputs.viewDidLoad() | |
} | |
private func test_viewDidLoadWithStaticContents() { | |
expectation = XCTestExpectation(description: "Lang is set to English") | |
test_viewDidLoad(with: .English) | |
wait(for: [expectation!], timeout: 1) | |
expectation = XCTestExpectation(description: "Lang is set to TraditionalChinese") | |
test_viewDidLoad(with: .TraditionalChinese) | |
wait(for: [expectation!], timeout: 1) | |
expectation = XCTestExpectation(description: "Lang is set to SimplifiedChinese") | |
test_viewDidLoad(with: .SimplifiedChinese) | |
wait(for: [expectation!], timeout: 1) | |
} | |
private func test_actions() { | |
expectation = XCTestExpectation(description: "onclick close button") | |
viewModel.inputs.onCloseButtonClicked() | |
wait(for: [expectation!], timeout: 1) | |
expectation = XCTestExpectation(description: "onclick update button") | |
viewModel.inputs.onUpdateButtonClicked() | |
wait(for: [expectation!], timeout: 1) | |
} | |
private func bind() { | |
viewModel.outputs | |
.content | |
.compactMap({ $0 }) | |
.receive(on: DispatchQueue.main) | |
.sink { text in | |
switch CHFAppState.shared.language.value { | |
case .English: | |
XCTAssertTrue(text == "According to the terms and conditions of the “NASDAQ Global Subscriber Agreement”, the subscriber of US real-time streaming service is necessary to declare the use of data and the “Non-Professional” status regularly. Please choose “Update” then complete the declaration and confirmation to enjoy the US real-time streaming service.") | |
case .TraditionalChinese: | |
XCTAssertTrue(text == "根據「NASDAQ全球訂閱者協議」內之條款及細則,美股即時串流報價服務之使用者,須定期聲明其接收數據的用途及符合「非專業用戶」的資格。請選擇「更新」並完成聲明及確認,以繼續享用美股即時串流報價服務。") | |
case .SimplifiedChinese: | |
XCTAssertTrue(text == "根据「NASDAQ全球订阅者协议」内之条款及细则,美股即时串流报价服务之使用者,须定期声明其接收数据的用途及符合「非专业用户」的资格。请选择「更新」并完成声明及确认,以继续享用美股即时串流报价服务。") | |
case .Korean, .Japanese, .Khmer, .Error, .Default: | |
XCTFail("Unexpected") | |
} | |
self.expectation?.fulfill() | |
}.store(in: &cancellable) | |
viewModel.outputs | |
.didClickCloseButton | |
.compactMap({ $0 }) | |
.sink { _ in | |
XCTAssert(true) | |
self.expectation?.fulfill() | |
}.store(in: &cancellable) | |
viewModel.outputs | |
.didClickUpdateButton | |
.compactMap({ $0 }) | |
.sink { _ in | |
XCTAssert(true) | |
self.expectation?.fulfill() | |
}.store(in: &cancellable) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment