Skip to content

Instantly share code, notes, and snippets.

View tilltue's full-sized avatar
🙊
I may be slow to respond.

junhyi park tilltue

🙊
I may be slow to respond.
View GitHub Profile
@tilltue
tilltue / CustomMatcher.swift
Last active June 17, 2018 15:14
EarlGrey Example
enum CustomMatcher {
case allOfsufficiently(id: String)
case displayLabel(text: String)
case displayButton(text: String)
var matcher: GREYMatcher {
switch self {
case let .allOfsufficiently(id):
return grey_allOf([grey_accessibilityID(id),grey_sufficientlyVisible()])
case let .displayLabel(text):
return GREYElementMatcherBlock(matchesBlock: matchesBlock(text: text), descriptionBlock: describeBlock(text: text))
@tilltue
tilltue / TestSample.swift
Last active June 17, 2018 15:19
Example Delete Purchase Item
//테이블 cell 을 delete 하면 물품이 삭제 된다.
//expect : cell swipe -> (delete) row
func test_DeletePurchaseItem() {
let addButtonMatcher = grey_allOf([grey_accessibilityID("addButton"),grey_sufficientlyVisible()])
EarlGrey.select(elementWithMatcher: addButtonMatcher).perform(grey_tap())
EarlGrey.select(elementWithMatcher: CustomMatcher.allOfsufficiently(id: "PriceTextField").matcher).perform(grey_replaceText("300"))
EarlGrey.select(elementWithMatcher: CustomMatcher.allOfsufficiently(id: "PurchaseInputConfirm").matcher).perform(grey_tap())
EarlGrey.select(elementWithMatcher: grey_accessibilityID("ListOfPurchasesViewController")).assert(grey_sufficientlyVisible())
EarlGrey.select(elementWithMatcher: grey_text("$ 300")).perform(grey_swipeFastInDirectionWithStartPoint(.left, 0.3, 0.3))
EarlGrey.select(elementWithMatcher: CustomMatcher.displayButton(text: "삭제").matcher).perform(grey_tap())
@tilltue
tilltue / Podfile
Created June 17, 2018 16:14
Podfile 설정
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '4.0'
config.build_settings['CLANG_ENABLE_CODE_COVERAGE'] = 'NO'
end
end
end
@tilltue
tilltue / CoverageTest.swift
Created June 20, 2018 14:27
code coverage test
struct CoverageTest {
func test1() {
func test2() {
print("test2")
}
test2()
}
}
@tilltue
tilltue / Api.swift
Created June 20, 2018 15:39
currency api model
enum Api {
static func getCurrencyExchangeRate(baseCurrency: String = "EUR", firebaseSaveBlock: ((Data) -> Void)? = nil) -> Single<[CurrencyExchangeRate]> {
return Service.shared.container
.resolve(MoyaProvider<CurrencyExchangeRateRemoteApi>.self)!.singleRequest(.exchangeRate(baseCurrency: baseCurrency))
.observeOn(Service.shared.container.resolve(SerialDispatchQueueScheduler.self, name: Service.RegisterationName.cacheSave.rawValue)!)
.do(onSuccess: { firebaseSaveBlock?($0) })
.map({ data -> [CurrencyExchangeRate] in
let exchangeRate = try JSONDecoder().decode(ExchangeRate.self, from: data)
return exchangeRate.convertCurrencyExchangeRate()
}).do(onSuccess: { rates in
@tilltue
tilltue / CurrencyFirebaseDB.swift
Created June 20, 2018 15:49
currency firebase database model
protocol CurrencyFirebaseDB {
var ref: DatabaseReference { get }
func getExchangeRate() -> Observable<[CurrencyExchangeRate]>
}
extension CurrencyFirebaseDB {
var ref: DatabaseReference {
return Service.shared.container.resolve(DatabaseReference.self, name: Service.RegisterationName.firebaseCurrencyExchageRate.rawValue)!
}
@tilltue
tilltue / EstimatedTaxProtocol.swift
Created June 20, 2018 16:06
Estimated Tax model
protocol EstimatedTaxProtocol {
associatedtype ItemType: PurchaseItem
var items: BehaviorSubject<[ItemType]> { get set }
var sumData: Observable<Int> { get }
var estimatedTax: Observable<Int> { get }
var estimatedTaxItems: Observable<[ItemType]> { get }
}
extension EstimatedTaxProtocol {
var sumData: Observable<Int> {
@tilltue
tilltue / CurrencySelectedViewModel.swift
Last active June 3, 2019 11:18
Currency Selected ViewModel
struct CurrencySelectedViewModel {
let currencyCellViewModels = BehaviorRelay<[CurrencyCellViewModel]>(value: [])
func selected(cellViewModel: CurrencyCellViewModel) {
}
func cancel() {
}
}
@tilltue
tilltue / CurrencySelectedViewController.swift
Created June 20, 2018 16:21
Currency Selected ViewController
extension CurrencySelectedViewController {
func bindViewModel() {
self.viewModel.listOfCurrencyDatasource.bind(to: self.bindProperty.bindViewModels).disposed(by: disposeBag)
self.viewModel.databaseModelObservable.bind(to: self.viewModel.currencyCellViewModels).disposed(by: disposeBag)
self.bindDataSource(tableView: self.tableView)
//UI action
self.bindProperty.selectedCell.asObservable().map{ $0.1 }.subscribe(onNext: { [weak self] cellViewModel in
self?.viewModel.selected(cellViewModel: cellViewModel)
self?.view.generateFeedBack()
DispatchQueue.main.async {
@tilltue
tilltue / CurrencySelectedViewModel_Tests.swift
Last active June 3, 2019 11:18
currency selected view model test
class CurrencySelectedViewModel_Tests: QuickSpec {
var viewModel: CurrencySelectedViewModel!
var disposeBag = DisposeBag()
override func spec() {
context("selected currecy"){
beforeEach {
//DB 리셋등 초기화
Realm.deleteAll(CurrencyExchangeRate.self)