Skip to content

Commit

Permalink
[PM-13682] Added generate crash and error reports to Debug view (#1056)
Browse files Browse the repository at this point in the history
  • Loading branch information
fedemkr authored Oct 18, 2024
1 parent 62311c5 commit caefc7b
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1042,5 +1042,7 @@
"AutofillPasswords" = "Autofill passwords";
"SetUpAutofillOnAllYourDevicesToLoginWithASingleTapAnywhere" = "Set up autofill on all your devices to login with a single tap anywhere.";
"GotIt" = "Got it";
"GenerateCrash" = "Generate crash";
"GenerateErrorReport" = "Generate error report";
"AllowAuthenticatorSyncing" = "Allow authenticator syncing";
"AuthenticatorSync" = "Authenticator sync";
4 changes: 4 additions & 0 deletions BitwardenShared/UI/Platform/DebugMenu/DebugMenuAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ import Foundation
enum DebugMenuAction: Equatable {
/// The dismiss button was tapped.
case dismissTapped
/// The generate crash button was tapped.
case generateCrash
/// The generate error report button was tapped.
case generateErrorReport
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ final class DebugMenuCoordinator: Coordinator, HasStackNavigator {

typealias Services = HasAppSettingsStore
& HasConfigService
& HasErrorReporter

// MARK: Private Properties

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import BitwardenSdk
import Foundation

// MARK: - DebugMenuProcessor
Expand All @@ -8,6 +9,7 @@ final class DebugMenuProcessor: StateProcessor<DebugMenuState, DebugMenuAction,
// MARK: Types

typealias Services = HasConfigService
& HasErrorReporter

// MARK: Properties

Expand Down Expand Up @@ -42,6 +44,13 @@ final class DebugMenuProcessor: StateProcessor<DebugMenuState, DebugMenuAction,
switch action {
case .dismissTapped:
coordinator.navigate(to: .dismiss)
case .generateCrash:
preconditionFailure("Generated crash from debug view.")
case .generateErrorReport:
services.errorReporter.log(error: BitwardenSdk.BitwardenError.E(
message: "Generated error report from debug view.")
)
services.errorReporter.log(error: KeychainServiceError.osStatusError(1))
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import BitwardenSdk
import XCTest

@testable import BitwardenShared
Expand All @@ -7,6 +8,7 @@ class DebugMenuProcessorTests: BitwardenTestCase {

var configService: MockConfigService!
var coordinator: MockCoordinator<DebugMenuRoute, Void>!
var errorReporter: MockErrorReporter!
var subject: DebugMenuProcessor!

// MARK: Set Up & Tear Down
Expand All @@ -16,10 +18,12 @@ class DebugMenuProcessorTests: BitwardenTestCase {

configService = MockConfigService()
coordinator = MockCoordinator<DebugMenuRoute, Void>()
errorReporter = MockErrorReporter()
subject = DebugMenuProcessor(
coordinator: coordinator.asAnyCoordinator(),
services: ServiceContainer.withMocks(
configService: configService
configService: configService,
errorReporter: errorReporter
),
state: DebugMenuState(featureFlags: [])
)
Expand All @@ -30,6 +34,7 @@ class DebugMenuProcessorTests: BitwardenTestCase {

configService = nil
coordinator = nil
errorReporter = nil
subject = nil
}

Expand Down Expand Up @@ -83,4 +88,20 @@ class DebugMenuProcessorTests: BitwardenTestCase {

XCTAssertTrue(configService.toggleDebugFeatureFlagCalled)
}

/// `receive()` with `.generateErrorReport` generates error reports on the error reporter.
@MainActor
func test_receive_generateErrorReport() {
subject.receive(.generateErrorReport)
XCTAssertEqual(
errorReporter.errors[0] as? BitwardenSdk.BitwardenError,
BitwardenSdk.BitwardenError.E(
message: "Generated error report from debug view."
)
)
XCTAssertEqual(
errorReporter.errors[1] as? KeychainServiceError,
KeychainServiceError.osStatusError(1)
)
}
}
23 changes: 23 additions & 0 deletions BitwardenShared/UI/Platform/DebugMenu/DebugMenuView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ struct DebugMenuView: View {
} header: {
featureFlagSectionHeader
}
Section {
errorReportSection
} header: {
Text("Error reports")
}
}
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Expand All @@ -36,6 +41,24 @@ struct DebugMenuView: View {
}
}

/// The error reports section.
private var errorReportSection: some View {
Group {
Button {
store.send(.generateErrorReport)
} label: {
Text(Localizations.generateErrorReport)
}
.accessibilityIdentifier("GenerateErrorReportButton")
Button {
store.send(.generateCrash)
} label: {
Text(Localizations.generateCrash)
}
.accessibilityIdentifier("GenerateCrashButton")
}
}

/// The feature flags currently used in the app.
private var featureFlags: some View {
ForEach(store.state.featureFlags) { flag in
Expand Down
16 changes: 16 additions & 0 deletions BitwardenShared/UI/Platform/DebugMenu/DebugMenuViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ class DebugMenuViewTests: BitwardenTestCase {
XCTAssertEqual(processor.effects.last, .toggleFeatureFlag(featureFlagName, true))
}

/// Tapping the generate crash button dispatches the `.generateCrash` action.
@MainActor
func test_generateCrash_tap() throws {
let button = try subject.inspect().find(button: Localizations.generateCrash)
try button.tap()
XCTAssertEqual(processor.dispatchedActions.last, .generateCrash)
}

/// Tapping the generate error report button dispatches the `.generateErrorReport` action.
@MainActor
func test_generateErrorReport_tap() throws {
let button = try subject.inspect().find(button: Localizations.generateErrorReport)
try button.tap()
XCTAssertEqual(processor.dispatchedActions.last, .generateErrorReport)
}

/// Test that the refresh button sends the correct effect.
@MainActor
func test_refreshFeatureFlags_tapped() async throws {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit caefc7b

Please sign in to comment.