Skip to content

Commit cb3ee6a

Browse files
committed
ULErrorVC: Add test that the viewModel viewDidLoad is triggered
1 parent 5875e0a commit cb3ee6a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

WooCommerce/WooCommerceTests/Authentication/ULErrorViewControllerTests.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ final class ULErrorViewControllerTests: XCTestCase {
1111
}
1212

1313
override func tearDown() {
14+
// There is no known tear down for the Authenticator. So this method intentionally does
15+
// nothing.
1416
super.tearDown()
1517
}
1618

@@ -135,6 +137,20 @@ final class ULErrorViewControllerTests: XCTestCase {
135137
// Then
136138
XCTAssertTrue(viewModel.secondaryButtonTapped)
137139
}
140+
141+
func test_viewController_informs_viewModel_when_the_view_is_loaded() throws {
142+
// Given
143+
let viewModel = ErrorViewModel()
144+
let viewController = ULErrorViewController(viewModel: viewModel)
145+
146+
XCTAssertFalse(viewModel.viewDidLoadTriggered)
147+
148+
// When
149+
_ = try XCTUnwrap(viewController.view)
150+
151+
// Then
152+
XCTAssertTrue(viewModel.viewDidLoadTriggered)
153+
}
138154
}
139155

140156

@@ -154,6 +170,7 @@ private final class ErrorViewModel: ULErrorViewModel {
154170
var primaryButtonTapped: Bool = false
155171
var secondaryButtonTapped: Bool = false
156172
var auxiliaryButtonTapped: Bool = false
173+
var viewDidLoadTriggered = false
157174

158175
func didTapPrimaryButton(in viewController: UIViewController?) {
159176
primaryButtonTapped = true
@@ -166,6 +183,12 @@ private final class ErrorViewModel: ULErrorViewModel {
166183
func didTapAuxiliaryButton(in viewController: UIViewController?) {
167184
auxiliaryButtonTapped = true
168185
}
186+
187+
func viewDidLoad(in viewController: UIViewController?) {
188+
viewDidLoadTriggered = true
189+
}
190+
}
191+
169192
// MARK: - WordPressAuthenticator Initialization
170193

171194
private extension ULErrorViewControllerTests {

0 commit comments

Comments
 (0)