Skip to content
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

Add localizations to UI tests target #118

Merged
merged 3 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 56 additions & 36 deletions ElementX.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion ElementX/Sources/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5406,7 +5406,7 @@ extension ElementL10n {
}

private static func trIn(_ language: String, _ table: String, _ key: String, _ args: CVarArg...) -> String {
guard let bundle = Bundle.lprojBundle(for: language) else {
guard let bundle = Bundle(for: BundleToken.self).lprojBundle(for: language) else {
// no translations for the desired language
return key
}
Expand All @@ -5415,3 +5415,5 @@ extension ElementL10n {
}
}

private final class BundleToken {}

20 changes: 3 additions & 17 deletions ElementX/Sources/Other/Extensions/Bundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,11 @@ import Foundation

public extension Bundle {

/// Returns the real app bundle.
/// Can also be used in app extensions.
static let app: Bundle = {
let bundle = main
if bundle.bundleURL.pathExtension == "appex" {
// Peel off two directory levels - MY_APP.app/PlugIns/MY_APP_EXTENSION.appex
let url = bundle.bundleURL.deletingLastPathComponent().deletingLastPathComponent()
if let otherBundle = Bundle(url: url) {
return otherBundle
}
}
return bundle
}()

/// Get an lproj language bundle from the main app bundle.
/// Get an lproj language bundle from the receiver bundle.
/// - Parameter language: The language to try to load.
/// - Returns: The lproj bundle if found otherwise nil.
@objc static func lprojBundle(for language: String) -> Bundle? {
guard let lprojURL = Bundle.app.url(forResource: language, withExtension: "lproj") else { return nil }
func lprojBundle(for language: String) -> Bundle? {
guard let lprojURL = url(forResource: language, withExtension: "lproj") else { return nil }
return Bundle(url: lprojURL)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ struct SplashScreen: View {
Text(ElementL10n.loginSplashSubmit)
}
.buttonStyle(.elementAction(.xLarge))
.accessibilityIdentifier("getStartedButton")
}
.padding(.horizontal, 16)
.readableFrame()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ extension {{enumName}} {
}

private static func trIn(_ language: String, _ table: String, _ key: String, _ args: CVarArg...) -> String {
guard let bundle = Bundle.lprojBundle(for: language) else {
guard let bundle = Bundle(for: BundleToken.self).lprojBundle(for: language) else {
// no translations for the desired language
return key
}
Expand All @@ -96,6 +96,8 @@ extension {{enumName}} {
}
}

private final class BundleToken {}

{% else %}
// No string found
{% endif %}
42 changes: 22 additions & 20 deletions UITests/Sources/BugReportUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,8 @@ class BugReportUITests: XCTestCase {
let app = Application.launch()
app.goToScreenWithIdentifier(.bugReport)

XCTAssert(app.navigationBars["Bug report"].exists)
XCTAssert(app.staticTexts["reportBugDescription"].exists)
XCTAssert(app.staticTexts["sendLogsDescription"].exists)
XCTAssert(app.textViews["reportTextView"].exists)
let sendingLogsToggle = app.switches["sendLogsToggle"]
XCTAssert(sendingLogsToggle.exists)
XCTAssert(sendingLogsToggle.isOn)
XCTAssert(app.staticTexts["sendLogsText"].exists)
let sendButton = app.buttons["sendButton"]
XCTAssert(sendButton.exists)
XCTAssertFalse(sendButton.isEnabled)
verifyInitialStateComponents(in: app)

XCTAssertFalse(app.images["screenshotImage"].exists)
XCTAssertFalse(app.buttons["removeScreenshotButton"].exists)
}
Expand Down Expand Up @@ -68,20 +59,31 @@ class BugReportUITests: XCTestCase {
let app = Application.launch()
app.goToScreenWithIdentifier(.bugReportWithScreenshot)

XCTAssert(app.navigationBars["Bug report"].exists)
XCTAssert(app.staticTexts["reportBugDescription"].exists)
XCTAssert(app.staticTexts["sendLogsDescription"].exists)
verifyInitialStateComponents(in: app)

XCTAssert(app.images["screenshotImage"].exists)
XCTAssert(app.buttons["removeScreenshotButton"].exists)
}

func verifyInitialStateComponents(in app: XCUIApplication) {
XCTAssert(app.navigationBars[ElementL10n.titleActivityBugReport].exists)
let descLabel = app.staticTexts["reportBugDescription"]
XCTAssert(descLabel.exists)
XCTAssertEqual(descLabel.label, ElementL10n.sendBugReportDescription)
let sendLogsDescLabel = app.staticTexts["sendLogsDescription"]
XCTAssert(sendLogsDescLabel.exists)
XCTAssertEqual(sendLogsDescLabel.label, ElementL10n.sendBugReportLogsDescription)
XCTAssert(app.textViews["reportTextView"].exists)
let sendingLogsToggle = app.switches["sendLogsToggle"]
XCTAssert(sendingLogsToggle.exists)
XCTAssert(sendingLogsToggle.isOn)
XCTAssert(app.staticTexts["sendLogsText"].exists)
let sendLogsToggle = app.switches["sendLogsToggle"]
XCTAssert(sendLogsToggle.exists)
XCTAssert(sendLogsToggle.isOn)
let sendLogsLabel = app.staticTexts["sendLogsText"]
XCTAssert(sendLogsLabel.exists)
XCTAssertEqual(sendLogsLabel.label, ElementL10n.sendBugReportIncludeLogs)
let sendButton = app.buttons["sendButton"]
XCTAssert(sendButton.exists)
XCTAssertEqual(sendButton.label, ElementL10n.actionSend)
XCTAssertFalse(sendButton.isEnabled)
XCTAssert(app.images["screenshotImage"].exists)
XCTAssert(app.buttons["removeScreenshotButton"].exists)
}

}
Expand Down
6 changes: 6 additions & 0 deletions UITests/Sources/LoginScreenUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class LoginScreenUITests: XCTestCase {
func validateServerDescriptionIsVisible(for state: String) {
let descriptionLabel = app.staticTexts["serverDescriptionText"]
XCTAssertTrue(descriptionLabel.exists, "The server description should be shown for \(state).")
XCTAssertEqual(descriptionLabel.label, ElementL10n.authenticationServerInfoMatrixDescription)
}

/// Checks that the server description label is hidden.
Expand All @@ -89,6 +90,7 @@ class LoginScreenUITests: XCTestCase {
XCTAssertTrue(usernameTextField.exists, "Username input should be shown for \(state).")
XCTAssertTrue(passwordTextField.exists, "Password input should be shown for \(state).")
XCTAssertTrue(nextButton.exists, "The next button should be shown for \(state).")
XCTAssertEqual(nextButton.label, ElementL10n.loginSignupSubmit)
}

/// Checks that the username and password text fields are hidden along with the next button.
Expand All @@ -107,19 +109,22 @@ class LoginScreenUITests: XCTestCase {
let nextButton = app.buttons["nextButton"]
XCTAssertTrue(nextButton.exists, "The next button should be shown.")
XCTAssertFalse(nextButton.isEnabled, "The next button should be disabled for \(state).")
XCTAssertEqual(nextButton.label, ElementL10n.loginSignupSubmit)
}

/// Checks that the next button is shown and is enabled.
func validateNextButtonIsEnabled(for state: String) {
let nextButton = app.buttons["nextButton"]
XCTAssertTrue(nextButton.exists, "The next button should be shown.")
XCTAssertTrue(nextButton.isEnabled, "The next button should be enabled for \(state).")
XCTAssertEqual(nextButton.label, ElementL10n.loginSignupSubmit)
}

/// Checks that the OIDC button is shown on the screen.
func validateOIDCButtonIsShown(for state: String) {
let oidcButton = app.buttons["oidcButton"]
XCTAssertTrue(oidcButton.exists, "The OIDC button should be shown for \(state).")
XCTAssertEqual(oidcButton.label, ElementL10n.loginContinue)
}

/// Checks that the OIDC button is not shown on the screen.
Expand All @@ -132,6 +137,7 @@ class LoginScreenUITests: XCTestCase {
func validateUnsupportedServerTextIsShown(for state: String) {
let unsupportedText = app.staticTexts["unsupportedServerText"]
XCTAssertTrue(unsupportedText.exists, "The unsupported homeserver text should be shown for \(state).")
XCTAssertEqual(unsupportedText.label, ElementL10n.autodiscoverWellKnownError)
}

/// Checks that the unsupported homeserver text is not shown on the screen.
Expand Down
16 changes: 12 additions & 4 deletions UITests/Sources/SettingsUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,19 @@ class SettingsUITests: XCTestCase {
let app = Application.launch()
app.goToScreenWithIdentifier(.settings)

XCTAssert(app.navigationBars["Settings"].exists)
XCTAssert(app.buttons["reportBugButton"].exists)
XCTAssert(app.navigationBars[ElementL10n.settings].exists)
let reportBugButton = app.buttons["reportBugButton"]
XCTAssert(reportBugButton.exists)
XCTAssertEqual(reportBugButton.label, ElementL10n.sendBugReport)
XCTAssertEqual(app.buttons["crashButton"].exists, BuildSettings.settingsCrashButtonVisible)
XCTAssertEqual(app.buttons["timelineStylePicker"].exists, BuildSettings.settingsShowTimelineStyle)
XCTAssert(app.buttons["logoutButton"].exists)
let timelineStylePicker = app.buttons["timelineStylePicker"]
XCTAssertEqual(timelineStylePicker.exists, BuildSettings.settingsShowTimelineStyle)
if BuildSettings.settingsShowTimelineStyle {
XCTAssertEqual(timelineStylePicker.staticTexts.firstMatch.label, ElementL10n.settingsTimelineStyle)
}
let logoutButton = app.buttons["logoutButton"]
XCTAssert(logoutButton.exists)
XCTAssertEqual(logoutButton.label, ElementL10n.logout)
}

}
3 changes: 2 additions & 1 deletion UITests/Sources/SplashScreenUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ class SplashScreenUITests: XCTestCase {
let app = Application.launch()
app.goToScreenWithIdentifier(.splash)

let getStartedButton = app.buttons["Get started"]
let getStartedButton = app.buttons["getStartedButton"]
XCTAssertTrue(getStartedButton.exists, "The primary action button should be shown.")
XCTAssertEqual(getStartedButton.label, ElementL10n.loginSplashSubmit)
}

func testSwipingBetweenPages() async throws {
Expand Down
4 changes: 4 additions & 0 deletions UITests/SupportingFiles/target.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@ targets:
- path: ../../ElementX/Sources/BuildSettings.swift
- path: ../../ElementX/Sources/Screens/RoomScreen/View/Style/TimelineStyle.swift
- path: ../../ElementX/Sources/UITestScreenIdentifier.swift
- path: ../../ElementX/Sources/Generated/Strings.swift
- path: ../../ElementX/Sources/Generated/Strings+Untranslated.swift
- path: ../../ElementX/Resources
- path: ../../ElementX/Sources/Other/Extensions/Bundle.swift
1 change: 1 addition & 0 deletions changelog.d/101.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add localizations to UI tests target and add some checks.