Last active
June 3, 2019 11:18
-
-
Save tilltue/5fdf6eb5c03924cfffb1df9bc61c999a to your computer and use it in GitHub Desktop.
currency selected view model test
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
class CurrencySelectedViewModel_Tests: QuickSpec { | |
var viewModel: CurrencySelectedViewModel! | |
var disposeBag = DisposeBag() | |
override func spec() { | |
context("selected currecy"){ | |
beforeEach { | |
//DB 리셋등 초기화 | |
Realm.deleteAll(CurrencyExchangeRate.self) | |
Defaults[.latestSelectedCurrency] = "" | |
Service.shared.mockRegister() | |
self.viewModel = Service.shared.container.resolve(CurrencySelectedViewModel.self)! | |
self.viewModel.deleteRef() | |
self.viewModel.firebaseCurrencyExchangeRate.subscribe().disposed(by: self.disposeBag) | |
self.viewModel.databaseModelObservable.bind(to: self.viewModel.currencyCellViewModels).disposed(by: self.disposeBag) | |
} | |
it("loaded") { | |
//currency 목록을 통해 tableviewcellviewmodel 이 48개 생성되어있다면 성공. 필요한 값들이 정상적으로 있는지 확인. | |
expect(self.viewModel.currencyCellViewModels.value.count).toEventually(equal(48)) | |
expect(self.viewModel.currencyCellViewModels.value.map{ UIImage(named: $0.currency.imageName) }.count).to(equal(48)) | |
expect(self.viewModel.currencyCellViewModels.value.map{ $0.currency.country }.count).to(equal(48)) | |
expect(self.viewModel.currencyCellViewModels.value.map{ $0.currency.symbol }.count).to(equal(48)) | |
let exchangeRate = CurrencyExchangeRate(currency: .usd, exchangeRate: 0) | |
let expectViewModel = CurrencyCellViewModel(currencyExchangeRate: exchangeRate) | |
expect(self.viewModel.currencyCellViewModels.value.filter{ $0 == expectViewModel }[0].exchangeRate).to(equal(1069.03)) | |
} | |
it("selected") { | |
//20번째 모델(ILS)를 선택했을때 마지막에 선택된 것으로 ils 나오면 성공. | |
expect(self.viewModel.currencyCellViewModels.value.count).toEventually(equal(48)) | |
self.viewModel.selected(cellViewModel: self.viewModel.currencyCellViewModels.value[20]) | |
expect(self.viewModel.selected.value.text).to(equal("ILS")) | |
expect(Defaults[.latestSelectedCurrency]).to(equal("ils")) | |
} | |
it("cancel") { | |
//... | |
} | |
} | |
//... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment