Skip to content

Commit 5875e0a

Browse files
committed
Fix failing ULErrorViewControllerTests
1 parent 188838f commit 5875e0a

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

WooCommerce/WooCommerceTests/Authentication/ULErrorViewControllerTests.swift

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
import XCTest
2+
import WordPressAuthenticator
23
@testable import WooCommerce
34

45
final class ULErrorViewControllerTests: XCTestCase {
56

7+
override func setUp() {
8+
super.setUp()
9+
10+
initializeAuthenticator()
11+
}
12+
13+
override func tearDown() {
14+
super.tearDown()
15+
}
16+
617
func test_viewcontroller_presents_image_provided_by_viewmodel() throws {
718
// Given
819
let viewModel = ErrorViewModel()
@@ -155,4 +166,104 @@ private final class ErrorViewModel: ULErrorViewModel {
155166
func didTapAuxiliaryButton(in viewController: UIViewController?) {
156167
auxiliaryButtonTapped = true
157168
}
169+
// MARK: - WordPressAuthenticator Initialization
170+
171+
private extension ULErrorViewControllerTests {
172+
/// Initialize `WordPressAuthenticator` with dummy configuration.
173+
///
174+
/// For some reason, the tests in this class fail when the `.view` is loaded because
175+
/// `NUXButton` instances used within `ULErrorViewController` seem to _phone home_ and access
176+
/// the `WordPressAuthenticator` instance. And since the `WordPressAuthenticator` instance
177+
/// was not initialized, I get a unit test fatal error:
178+
///
179+
/// ```
180+
/// WordPressAuthenticator wasn't initialized
181+
/// ```
182+
///
183+
/// Initializing with dummy data seems to work.
184+
///
185+
/// There is no known way to tear down this instance. Once initialized, it's initialized. And
186+
/// I don't believe we use `WordPressAuthenticator` anywhere else. So hopefully this will not
187+
/// bleed into the other unit tests. ¯\(°_o)/¯
188+
func initializeAuthenticator() {
189+
let configuration = WordPressAuthenticatorConfiguration(wpcomClientId: "",
190+
wpcomSecret: "",
191+
wpcomScheme: "",
192+
wpcomTermsOfServiceURL: "",
193+
wpcomAPIBaseURL: "",
194+
googleLoginClientId: "",
195+
googleLoginServerClientId: "",
196+
googleLoginScheme: "",
197+
userAgent: "",
198+
showLoginOptions: true,
199+
enableSignUp: false,
200+
enableSignInWithApple: false,
201+
enableSignupWithGoogle: false,
202+
enableUnifiedAuth: true,
203+
continueWithSiteAddressFirst: true)
204+
205+
let style = WordPressAuthenticatorStyle(primaryNormalBackgroundColor: .red,
206+
primaryNormalBorderColor: .red,
207+
primaryHighlightBackgroundColor: .red,
208+
primaryHighlightBorderColor: .red,
209+
secondaryNormalBackgroundColor: .red,
210+
secondaryNormalBorderColor: .red,
211+
secondaryHighlightBackgroundColor: .red,
212+
secondaryHighlightBorderColor: .red,
213+
disabledBackgroundColor: .red,
214+
disabledBorderColor: .red,
215+
primaryTitleColor: .primaryButtonTitle,
216+
secondaryTitleColor: .red,
217+
disabledTitleColor: .red,
218+
disabledButtonActivityIndicatorColor: .red,
219+
textButtonColor: .red,
220+
textButtonHighlightColor: .red,
221+
instructionColor: .red,
222+
subheadlineColor: .red,
223+
placeholderColor: .red,
224+
viewControllerBackgroundColor: .red,
225+
textFieldBackgroundColor: .red,
226+
buttonViewBackgroundColor: .red,
227+
buttonViewTopShadowImage: nil,
228+
navBarImage: UIImage(),
229+
navBarBadgeColor: .red,
230+
navBarBackgroundColor: .red,
231+
prologueTopContainerChildViewController: nil,
232+
statusBarStyle: .default)
233+
234+
let displayStrings = WordPressAuthenticatorDisplayStrings(emailLoginInstructions: "",
235+
getStartedInstructions: "",
236+
jetpackLoginInstructions: "",
237+
siteLoginInstructions: "",
238+
usernamePasswordInstructions: "",
239+
continueWithWPButtonTitle: "",
240+
enterYourSiteAddressButtonTitle: "",
241+
findSiteButtonTitle: "",
242+
signupTermsOfService: "",
243+
getStartedTitle: "")
244+
245+
let unifiedStyle = WordPressAuthenticatorUnifiedStyle(borderColor: .red,
246+
errorColor: .red,
247+
textColor: .red,
248+
textSubtleColor: .red,
249+
textButtonColor: .red,
250+
textButtonHighlightColor: .red,
251+
viewControllerBackgroundColor: .red,
252+
prologueButtonsBackgroundColor: .red,
253+
prologueViewBackgroundColor: .red,
254+
navBarBackgroundColor: .red,
255+
navButtonTextColor: .red,
256+
navTitleTextColor: .red)
257+
258+
let displayImages = WordPressAuthenticatorDisplayImages(
259+
magicLink: UIImage(),
260+
siteAddressModalPlaceholder: UIImage()
261+
)
262+
263+
WordPressAuthenticator.initialize(configuration: configuration,
264+
style: style,
265+
unifiedStyle: unifiedStyle,
266+
displayImages: displayImages,
267+
displayStrings: displayStrings)
268+
}
158269
}

0 commit comments

Comments
 (0)