From 59486c824a6f23add3bbd99d2c183854fdd9ec8a Mon Sep 17 00:00:00 2001 From: Doug Date: Wed, 8 Dec 2021 12:00:23 +0000 Subject: [PATCH] Add accessibility labels/hints. Fix tests. Show analytics prompt to everyone. --- Riot/Assets/en.lproj/Vector.strings | 1 + Riot/Generated/Strings.swift | 4 ++++ Riot/Managers/Analytics/Analytics.swift | 6 +++--- .../MockAnalyticsPromptStrings.swift | 2 +- .../AnalyticsPrompt/View/AnalyticsPrompt.swift | 8 ++++++++ RiotTests/AnalyticsTests.swift | 16 +++++++++------- 6 files changed, 26 insertions(+), 11 deletions(-) diff --git a/Riot/Assets/en.lproj/Vector.strings b/Riot/Assets/en.lproj/Vector.strings index 17ecfa6a2..f513009c6 100644 --- a/Riot/Assets/en.lproj/Vector.strings +++ b/Riot/Assets/en.lproj/Vector.strings @@ -78,6 +78,7 @@ // Accessibility "accessibility_checkbox_label" = "checkbox"; +"accessibility_button_label" = "button"; // Authentication "auth_login" = "Log in"; diff --git a/Riot/Generated/Strings.swift b/Riot/Generated/Strings.swift index b8546ccda..d47bdfb99 100644 --- a/Riot/Generated/Strings.swift +++ b/Riot/Generated/Strings.swift @@ -15,6 +15,10 @@ public class VectorL10n: NSObject { public static var accept: String { return VectorL10n.tr("Vector", "accept") } + /// button + public static var accessibilityButtonLabel: String { + return VectorL10n.tr("Vector", "accessibility_button_label") + } /// checkbox public static var accessibilityCheckboxLabel: String { return VectorL10n.tr("Vector", "accessibility_checkbox_label") diff --git a/Riot/Managers/Analytics/Analytics.swift b/Riot/Managers/Analytics/Analytics.swift index 837869254..617f7fec4 100644 --- a/Riot/Managers/Analytics/Analytics.swift +++ b/Riot/Managers/Analytics/Analytics.swift @@ -32,10 +32,10 @@ import AnalyticsEvents /// Whether or not the object is enabled and sending events to the server. var isRunning: Bool { client.isRunning } - /// Whether the user has yet to opt in or out of analytics collection. + /// Whether to show the user the analytics opt in prompt. var shouldShowAnalyticsPrompt: Bool { - // Show an analytics prompt when the user hasn't seen the PostHog prompt before. - !RiotSettings.shared.hasSeenAnalyticsPrompt + // Only show the prompt once, and when analytics are configured in BuildSettings. + !RiotSettings.shared.hasSeenAnalyticsPrompt && PHGPostHogConfiguration.standard != nil } /// Indicates whether the user previously accepted Matomo analytics and should be shown the upgrade prompt. diff --git a/RiotSwiftUI/Modules/AnalyticsPrompt/MockAnalyticsPromptStrings.swift b/RiotSwiftUI/Modules/AnalyticsPrompt/MockAnalyticsPromptStrings.swift index 0e2dba938..ee0e59ed0 100644 --- a/RiotSwiftUI/Modules/AnalyticsPrompt/MockAnalyticsPromptStrings.swift +++ b/RiotSwiftUI/Modules/AnalyticsPrompt/MockAnalyticsPromptStrings.swift @@ -14,7 +14,7 @@ // limitations under the License. // -import Foundation +import UIKit struct MockAnalyticsPromptStrings: AnalyticsPromptStringsProtocol { var appDisplayName = "Element" diff --git a/RiotSwiftUI/Modules/AnalyticsPrompt/View/AnalyticsPrompt.swift b/RiotSwiftUI/Modules/AnalyticsPrompt/View/AnalyticsPrompt.swift index fecd0b284..a5a9635ac 100644 --- a/RiotSwiftUI/Modules/AnalyticsPrompt/View/AnalyticsPrompt.swift +++ b/RiotSwiftUI/Modules/AnalyticsPrompt/View/AnalyticsPrompt.swift @@ -40,6 +40,8 @@ struct AnalyticsPrompt: View { Text("\(viewModel.viewState.promptType.description)\n") AnalyticsPromptTermsText(attributedString: viewModel.viewState.promptType.termsStrings) + .accessibilityLabel(Text(viewModel.viewState.promptType.termsStrings.string)) + .accessibilityValue(Text(VectorL10n.accessibilityButtonLabel)) .onTapGesture { viewModel.send(viewAction: .openTermsURL) } @@ -50,10 +52,15 @@ struct AnalyticsPrompt: View { private var checkmarkList: some View { VStack(alignment: .leading) { AnalyticsPromptCheckmarkItem(attributedString: viewModel.viewState.strings.point1) + .accessibilityLabel(Text(viewModel.viewState.strings.point1.string)) + AnalyticsPromptCheckmarkItem(attributedString: viewModel.viewState.strings.point2) + .accessibilityLabel(Text(viewModel.viewState.strings.point2.string)) + AnalyticsPromptCheckmarkItem(string: VectorL10n.analyticsPromptPoint3) } .font(theme.fonts.body) + .frame(maxWidth: .infinity) } /// The stack of enable/disable buttons. @@ -89,6 +96,7 @@ struct AnalyticsPrompt: View { .padding(.bottom, 2) descriptionText + .font(theme.fonts.body) .foregroundColor(theme.colors.secondaryContent) .multilineTextAlignment(.center) diff --git a/RiotTests/AnalyticsTests.swift b/RiotTests/AnalyticsTests.swift index b31cbd6c5..5e15bf523 100644 --- a/RiotTests/AnalyticsTests.swift +++ b/RiotTests/AnalyticsTests.swift @@ -28,8 +28,8 @@ class AnalyticsTests: XCTestCase { let displayUpgradeMessage = Analytics.shared.promptShouldDisplayUpgradeMessage // Then the regular prompt should be shown. - XCTAssertTrue(showPrompt, "A prompt should be shown when for a new user") - XCTAssertFalse(displayUpgradeMessage, "The prompt should not ask about upgrading from Matomo") + XCTAssertTrue(showPrompt, "A prompt should be shown for a new user.") + XCTAssertFalse(displayUpgradeMessage, "The prompt should not ask about upgrading from Matomo.") } func testAnalyticsPromptUpgradeFromMatomo() { @@ -42,8 +42,8 @@ class AnalyticsTests: XCTestCase { let displayUpgradeMessage = Analytics.shared.promptShouldDisplayUpgradeMessage // Then an upgrade prompt should be shown. - XCTAssertTrue(showPrompt, "A prompt should be shown when for a new user") - XCTAssertTrue(displayUpgradeMessage, "The prompt should not ask about upgrading from Matomo") + XCTAssertTrue(showPrompt, "A prompt should be shown to the user.") + XCTAssertTrue(displayUpgradeMessage, "The prompt should ask about upgrading from Matomo.") } func testAnalyticsPromptUserDeclinedMatomo() { @@ -53,9 +53,11 @@ class AnalyticsTests: XCTestCase { // When the user is prompted for analytics let showPrompt = Analytics.shared.shouldShowAnalyticsPrompt + let displayUpgradeMessage = Analytics.shared.promptShouldDisplayUpgradeMessage - // Then no prompt should be shown. - XCTAssertFalse(showPrompt, "A prompt should be shown when for a new user") + // Then the regular prompt should be shown. + XCTAssertTrue(showPrompt, "A prompt should be shown to the user.") + XCTAssertFalse(displayUpgradeMessage, "The prompt should not ask about upgrading from Matomo.") } func testAnalyticsPromptUserAcceptedPostHog() { @@ -66,6 +68,6 @@ class AnalyticsTests: XCTestCase { let showPrompt = Analytics.shared.shouldShowAnalyticsPrompt // Then no prompt should be shown. - XCTAssertFalse(showPrompt, "A prompt should be shown when for a new user") + XCTAssertFalse(showPrompt, "A prompt should not be shown any more.") } }