-
Notifications
You must be signed in to change notification settings - Fork 70
Feature/home view model test #196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
6a0f2e5
1d09c57
d8ec150
52440f1
465e596
f093343
262c589
bf34552
f90273c
3dba248
408cbb3
2abd084
28400ad
8427723
6b8147a
8724014
913b640
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -8,6 +8,55 @@ | |||||
import XCTest | ||||||
@testable import FinanceApp | ||||||
|
||||||
class HomeViewModelTests: XCTestCase { | ||||||
final class HomeViewModelTests: XCTestCase { | ||||||
|
||||||
let dispatchQueueSpy = DispatchQueueSpy() | ||||||
let financeServiceSpy = FinanceServiceSpy() | ||||||
let delegateSpy = HomeViewModelDelegateSpy() | ||||||
lazy var sut = HomeViewModel(financeService: financeServiceSpy, dispatchQueue: dispatchQueueSpy) | ||||||
|
||||||
func test_didFetchHomeData_isCalled () { | ||||||
//Given | ||||||
sut.delegate = delegateSpy | ||||||
//When | ||||||
sut.fetchData() | ||||||
//Then | ||||||
XCTAssertTrue(delegateSpy.delegateIsCalled) | ||||||
} | ||||||
|
||||||
func test_fetchHomeDataAndDispatchQueue_isCalled() { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
//when | ||||||
sut.fetchData() | ||||||
//then | ||||||
XCTAssertTrue(financeServiceSpy.fetchHomeDataIsCalled) | ||||||
XCTAssertTrue(dispatchQueueSpy.isDispatchCalled) | ||||||
} | ||||||
|
||||||
func test_fetchData_shouldNotCallDelegate_whenHomedataIsNill () { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// Given | ||||||
financeServiceSpy.homeData = nil | ||||||
//When | ||||||
sut.fetchData() | ||||||
//Then | ||||||
XCTAssertFalse(dispatchQueueSpy.isDispatchCalled) | ||||||
} | ||||||
} | ||||||
|
||||||
class HomeViewModelDelegateSpy: HomeViewModelDelegate { | ||||||
var delegateIsCalled: Bool = false | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
func didFetchHomeData(_ data: FinanceApp.HomeData) { | ||||||
delegateIsCalled = true | ||||||
} | ||||||
} | ||||||
|
||||||
class FinanceServiceSpy: FetchHomeDataProtocol { | ||||||
|
||||||
var homeData: HomeData? = HomeData(balance: 0, savings: 0, spending: 0, activity: [Activity(name: "", price: 0, time: "")]) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. O que você acha de utilizarmos uma |
||||||
var fetchHomeDataIsCalled: Bool = false | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
func fetchHomeData(_ completion: @escaping (FinanceApp.HomeData?) -> Void) { | ||||||
fetchHomeDataIsCalled = true | ||||||
completion(homeData) | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,7 +5,12 @@ import Foundation | |||||
@testable import FinanceApp | ||||||
|
||||||
public class DispatchQueueSpy: DispatchQueueProtocol { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
var isDispatchCalled: Bool = false | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
public func async(group: DispatchGroup?, qos: DispatchQoS, flags: DispatchWorkItemFlags, execute work: @escaping @convention(block) () -> Void) { | ||||||
isDispatchCalled = true | ||||||
work() | ||||||
} | ||||||
} | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.