From 4aceea91b8aa6a2ba9ad0095deda68d2a54a3db6 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Sun, 22 Sep 2019 11:14:25 -0700 Subject: [PATCH] Tests fix! --- Clocker/Clocker/en.lproj/Localizable.strings | 5 +++++ Clocker/Clocker/hi.lproj/Localizable.strings | 5 +++++ .../ClockerUITests/FloatingWindowTests.swift | 5 +---- Clocker/ClockerUITests/OnboardingTests.swift | 18 +++++++++--------- Clocker/ClockerUITests/PreferencesTest.swift | 9 +++++++-- .../OnboardingWelcomeViewController.swift | 3 +-- 6 files changed, 28 insertions(+), 17 deletions(-) diff --git a/Clocker/Clocker/en.lproj/Localizable.strings b/Clocker/Clocker/en.lproj/Localizable.strings index a3ad658..07af75b 100644 --- a/Clocker/Clocker/en.lproj/Localizable.strings +++ b/Clocker/Clocker/en.lproj/Localizable.strings @@ -149,3 +149,8 @@ "You're offline, maybe?" = "You're offline, maybe?"; "Try again, maybe?" = "Try again, maybe?"; "The Internet connection appears to be offline." = "The Internet connection appears to be offline."; + +// UI Tests +"New Zealand" = "New Zealand"; +"Florida" = "Florida"; +"San Francisco" = "San Francisco"; diff --git a/Clocker/Clocker/hi.lproj/Localizable.strings b/Clocker/Clocker/hi.lproj/Localizable.strings index 6dd92b8..ee055ea 100644 --- a/Clocker/Clocker/hi.lproj/Localizable.strings +++ b/Clocker/Clocker/hi.lproj/Localizable.strings @@ -66,3 +66,8 @@ // Appearance Tab "Panel Theme" = "प्रकटन"; + +// UI Tests +"New Zealand" = "न्यूज़ीलैंड"; +"Florida" = "फ्लोरिडा"; +"San Francisco" = "सान फ्रांसिस्को"; diff --git a/Clocker/ClockerUITests/FloatingWindowTests.swift b/Clocker/ClockerUITests/FloatingWindowTests.swift index 1309da6..f6f7f2c 100644 --- a/Clocker/ClockerUITests/FloatingWindowTests.swift +++ b/Clocker/ClockerUITests/FloatingWindowTests.swift @@ -5,10 +5,7 @@ import XCTest extension String { func localizedString() -> String { let bundle = Bundle(for: AboutUsTests.self) - let deviceLanguage = Locale.preferredLanguages.first - let localizationBundle = Bundle(path: bundle.path(forResource: deviceLanguage, - ofType: "lproj")!) - return NSLocalizedString(self, bundle: localizationBundle!, comment: "") + return NSLocalizedString(self, bundle: bundle, comment: "") } } diff --git a/Clocker/ClockerUITests/OnboardingTests.swift b/Clocker/ClockerUITests/OnboardingTests.swift index de6b6b7..68e4917 100644 --- a/Clocker/ClockerUITests/OnboardingTests.swift +++ b/Clocker/ClockerUITests/OnboardingTests.swift @@ -98,8 +98,8 @@ class OnboardingTests: XCTestCase { let onboardingWindow = app.windows["OnboardingWindow"] // Tests static texts - XCTAssertTrue(onboardingWindow.staticTexts["Clocker"].exists, "Static text Clocker was unexpectedly missing") - XCTAssertTrue(onboardingWindow.staticTexts["It only takes 3 steps to set up Clocker."].exists, "Accessory label's static text was unexpectedly wrong.") + XCTAssertTrue(onboardingWindow.staticTexts["CFBundleDisplayName".localizedString()].exists, "Static text Clocker was unexpectedly missing") + XCTAssertTrue(onboardingWindow.staticTexts["It only takes 3 steps to set up Clocker.".localizedString()].exists, "Accessory label's static text was unexpectedly wrong.") let button = onboardingWindow.buttons["Forward"] @@ -112,10 +112,10 @@ class OnboardingTests: XCTestCase { private func permissionsControllerTests() { let onboardingWindow = app.windows["OnboardingWindow"] - XCTAssertTrue(onboardingWindow.staticTexts["Permissions"].exists, "Header label's static text was unexpectedly wrong.") - XCTAssertTrue(onboardingWindow.staticTexts["These can be configured later in System Preferences."].exists, "Onboarding Info label's static text was unexpectedly wrong.") + XCTAssertTrue(onboardingWindow.staticTexts["Permissions".localizedString()].exists, "Header label's static text was unexpectedly wrong.") + XCTAssertTrue(onboardingWindow.staticTexts["Later Config Description".localizedString()].exists, "Onboarding Info label's static text was unexpectedly wrong.") - XCTAssertTrue(onboardingWindow.buttons["Forward"].title == "Continue", "Forward button title's was unexpectedly wrong") + XCTAssertTrue(onboardingWindow.buttons["Forward"].title == "Continue".localizedString(), "Forward button title's was unexpectedly wrong") XCTAssertTrue(onboardingWindow.buttons["Backward"].exists, "Back button was unexpectedly missing") XCTAssertFalse(onboardingWindow.buttons["Alternate"].exists, "Alternate button was unexpectedly present.") } @@ -126,17 +126,17 @@ class OnboardingTests: XCTestCase { XCTAssertTrue(onboardingWindow.buttons["Forward"].title == "Open Clocker At Login", "Forward button title's was unexpectedly wrong") XCTAssertTrue(onboardingWindow.buttons["Alternate"].title == "Don't Open", "Alternate button title's was unexpectedly wrong") - XCTAssertTrue(onboardingWindow.staticTexts["Launch at Login"].exists, "Header label's static text was unexpectedly wrong.") - XCTAssertTrue(onboardingWindow.staticTexts["Should Clocker open automatically on startup?"].exists, "Accessory label's static text was unexpectedly wrong.") + XCTAssertTrue(onboardingWindow.staticTexts["Launch at Login".localizedString()].exists, "Header label's static text was unexpectedly wrong.") + XCTAssertTrue(onboardingWindow.staticTexts["Should Clocker open automatically on startup?".localizedString()].exists, "Accessory label's static text was unexpectedly wrong.") } private func searchControllerTests() { let onboardingWindow = app.windows["OnboardingWindow"] XCTAssertFalse(onboardingWindow.buttons["Alternate"].exists, "Alternate button was unexpectedly present.") - XCTAssertTrue(onboardingWindow.buttons["Forward"].title == "Continue", "Forward button title's was unexpectedly wrong") + XCTAssertTrue(onboardingWindow.buttons["Forward"].title == "Continue".localizedString(), "Forward button title's was unexpectedly wrong") - XCTAssertTrue(onboardingWindow.staticTexts["Quick Add Locations"].exists, "Header label's static text was unexpectedly wrong.") + XCTAssertTrue(onboardingWindow.staticTexts["Quick Add Locations".localizedString()].exists, "Header label's static text was unexpectedly wrong.") XCTAssertTrue(onboardingWindow.staticTexts["More search options in Clocker Preferences."].exists, "Accessory label's static text was unexpectedly wrong.") } diff --git a/Clocker/ClockerUITests/PreferencesTest.swift b/Clocker/ClockerUITests/PreferencesTest.swift index bc3e71d..4a4da59 100644 --- a/Clocker/ClockerUITests/PreferencesTest.swift +++ b/Clocker/ClockerUITests/PreferencesTest.swift @@ -76,7 +76,10 @@ class PreferencesTest: XCTestCase { } } - XCTAssertEqual(actualLabels, ["New Zealand", "Florida", "San Francisco"]) + XCTAssertEqual(actualLabels, + ["New Zealand".localizedString(), + "Florida".localizedString(), + "San Francisco".localizedString()]) app.windows["Clocker"].checkBoxes["Sort by Time Difference".localizedString()].click() @@ -89,7 +92,9 @@ class PreferencesTest: XCTestCase { } } - XCTAssertEqual(actualReversedLabels, ["San Francisco", "Florida", "New Zealand"]) + XCTAssertEqual(actualReversedLabels, ["San Francisco".localizedString(), + "Florida".localizedString(), + "New Zealand".localizedString()]) addAPlace(place: "Omaha", to: app) addAPlace(place: "Mumbai", to: app) diff --git a/Clocker/Onboarding/OnboardingWelcomeViewController.swift b/Clocker/Onboarding/OnboardingWelcomeViewController.swift index 5036042..072fd37 100644 --- a/Clocker/Onboarding/OnboardingWelcomeViewController.swift +++ b/Clocker/Onboarding/OnboardingWelcomeViewController.swift @@ -12,8 +12,7 @@ class OnboardingWelcomeViewController: NSViewController { } private func setup() { - appLabel.stringValue = NSLocalizedString("CFBundleDisplayName", - comment: "App Name") + appLabel.stringValue = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String ?? "Clocker" accessoryLabel.stringValue = NSLocalizedString("It only takes 3 steps to set up Clocker.", comment: "App Setup Description")