From ac4c3e2f3d4061489910d396b6b4057ac0f0bec7 Mon Sep 17 00:00:00 2001 From: ezimet-livefront Date: Fri, 22 Nov 2024 11:29:27 -0500 Subject: [PATCH] fix accessibility --- .../UI/Auth/ProfileSwitcher/ProfileSwitcherRow.swift | 6 +++--- .../UI/Auth/ProfileSwitcher/ProfileSwitcherRowState.swift | 7 +++++-- .../UI/Auth/ProfileSwitcher/ProfileSwitcherView.swift | 3 ++- .../UI/Auth/ProfileSwitcher/ProfileSwitcherViewTests.swift | 2 ++ 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/BitwardenShared/UI/Auth/ProfileSwitcher/ProfileSwitcherRow.swift b/BitwardenShared/UI/Auth/ProfileSwitcher/ProfileSwitcherRow.swift index 20500a665..70a181a54 100644 --- a/BitwardenShared/UI/Auth/ProfileSwitcher/ProfileSwitcherRow.swift +++ b/BitwardenShared/UI/Auth/ProfileSwitcher/ProfileSwitcherRow.swift @@ -213,7 +213,7 @@ struct ProfileSwitcherRow: View { ) ) } - .onLongPressGesture(if: store.state.allowLockAndLogout) { + .onLongPressGesture(if: store.state.allowLock || store.state.allowLogout) { await store.perform( .longPressed( isSelected @@ -227,13 +227,13 @@ struct ProfileSwitcherRow: View { await store.perform(.accessibility(.select(profileSwitcherItem))) } .conditionalAccessibilityAsyncAction( - if: store.state.allowLockAndLogout, + if: store.state.allowLock, named: Localizations.lock ) { await store.perform(.accessibility(.lock(profileSwitcherItem))) } .conditionalAccessibilityAction( - if: store.state.allowLockAndLogout, + if: store.state.allowLogout, named: Localizations.logOut ) { store.send(.accessibility(.logout(profileSwitcherItem))) diff --git a/BitwardenShared/UI/Auth/ProfileSwitcher/ProfileSwitcherRowState.swift b/BitwardenShared/UI/Auth/ProfileSwitcher/ProfileSwitcherRowState.swift index b39b3d7ae..1c9353836 100644 --- a/BitwardenShared/UI/Auth/ProfileSwitcher/ProfileSwitcherRowState.swift +++ b/BitwardenShared/UI/Auth/ProfileSwitcher/ProfileSwitcherRowState.swift @@ -23,8 +23,11 @@ struct ProfileSwitcherRowState: Equatable { case alternate(ProfileSwitcherItem) } - /// Should the row allow lock and logout? - var allowLockAndLogout: Bool = true + /// Should the row allow lock. + var allowLock: Bool = true + + /// Should the row allow logout. + var allowLogout: Bool = true /// A flag for tracking accessibility focus var shouldTakeAccessibilityFocus: Bool diff --git a/BitwardenShared/UI/Auth/ProfileSwitcher/ProfileSwitcherView.swift b/BitwardenShared/UI/Auth/ProfileSwitcher/ProfileSwitcherView.swift index f2ae5a0af..0cef882c9 100644 --- a/BitwardenShared/UI/Auth/ProfileSwitcher/ProfileSwitcherView.swift +++ b/BitwardenShared/UI/Auth/ProfileSwitcher/ProfileSwitcherView.swift @@ -115,7 +115,8 @@ struct ProfileSwitcherView: View { store: store.child( state: { _ in ProfileSwitcherRowState( - allowLockAndLogout: store.state.allowLockAndLogout, + allowLock: accountProfile.canBeLocked, + allowLogout: store.state.allowLockAndLogout, shouldTakeAccessibilityFocus: store.state.isVisible && isActive, showDivider: showDivider, diff --git a/BitwardenShared/UI/Auth/ProfileSwitcher/ProfileSwitcherViewTests.swift b/BitwardenShared/UI/Auth/ProfileSwitcher/ProfileSwitcherViewTests.swift index fa78a63a7..7942fd0b7 100644 --- a/BitwardenShared/UI/Auth/ProfileSwitcher/ProfileSwitcherViewTests.swift +++ b/BitwardenShared/UI/Auth/ProfileSwitcher/ProfileSwitcherViewTests.swift @@ -53,6 +53,7 @@ class ProfileSwitcherViewTests: BitwardenTestCase { // swiftlint:disable:this ty @MainActor func test_accountRow_longPress_currentAccount_noLockOrLogout() throws { processor.state.allowLockAndLogout = false + processor.state.accounts[0].canBeLocked = false let accountRow = try subject.inspect().find(button: "anne.account@bitwarden.com") XCTAssertThrowsError(try accountRow.labelView().recursiveCallOnLongPressGesture()) } @@ -106,6 +107,7 @@ class ProfileSwitcherViewTests: BitwardenTestCase { // swiftlint:disable:this ty @MainActor func test_alternateAccountRow_longPress_currentAccount_noLockOrLogout() throws { let alternate = ProfileSwitcherItem.fixture( + canBeLocked: false, email: "alternate@bitwarden.com", userInitials: "NA" )