Skip to content

Commit 8f04bf8

Browse files
[PM-21125] Add navigation setup for view send item (#1578)
1 parent 60dc427 commit 8f04bf8

19 files changed

+352
-211
lines changed

BitwardenShareExtension/ShareViewController.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ShareViewController: UIViewController {
1414
/// The app's theme.
1515
var appTheme: AppTheme = .default
1616

17-
var authCompletionRoute: AppRoute? = .sendItem(.add(content: nil, hasPremium: false))
17+
var authCompletionRoute: AppRoute? = .sendItem(.add(content: nil))
1818

1919
/// The processor that manages application level logic.
2020
private var appProcessor: AppProcessor?
@@ -58,9 +58,7 @@ class ShareViewController: UIViewController {
5858
let appProcessor = AppProcessor(appModule: appModule, services: services)
5959
self.appProcessor = appProcessor
6060

61-
let hasPremium = try? await services.sendRepository.doesActiveAccountHavePremium()
62-
63-
authCompletionRoute = .sendItem(.add(content: content, hasPremium: hasPremium ?? false))
61+
authCompletionRoute = .sendItem(.add(content: content))
6462

6563
Task {
6664
await appProcessor.start(

BitwardenShared/UI/Platform/Application/AppCoordinatorTests.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -383,32 +383,32 @@ class AppCoordinatorTests: BitwardenTestCase { // swiftlint:disable:this type_bo
383383
XCTAssertEqual(module.loginRequestCoordinator.routes.last, .loginRequest(.fixture()))
384384
}
385385

386-
/// `navigate(to:)` with `.sendItem(.add(content:hasPremium:))` starts the send item coordinator
386+
/// `navigate(to:)` with `.sendItem(.add(content:))` starts the send item coordinator
387387
/// and navigates to the proper route.
388388
@MainActor
389389
func test_navigateTo_sendItem() {
390-
subject.navigate(to: .sendItem(.add(content: nil, hasPremium: false)))
390+
subject.navigate(to: .sendItem(.add(content: nil)))
391391

392392
XCTAssertTrue(module.sendItemCoordinator.isStarted)
393393
XCTAssertEqual(
394394
module.sendItemCoordinator.routes,
395-
[.add(content: nil, hasPremium: false)]
395+
[.add(content: nil)]
396396
)
397397
}
398398

399399
/// `navigate(to:)` with `.sendItem()` twice uses the existing coordinator, rather than
400400
/// creating a new one.
401401
@MainActor
402402
func test_navigateTo_sendItem_twice() {
403-
subject.navigate(to: .sendItem(.add(content: nil, hasPremium: false)))
404-
subject.navigate(to: .sendItem(.add(content: .text("test"), hasPremium: true)))
403+
subject.navigate(to: .sendItem(.add(content: nil)))
404+
subject.navigate(to: .sendItem(.add(content: .text("test"))))
405405

406406
XCTAssertTrue(module.sendItemCoordinator.isStarted)
407407
XCTAssertEqual(
408408
module.sendItemCoordinator.routes,
409409
[
410-
.add(content: nil, hasPremium: false),
411-
.add(content: .text("test"), hasPremium: true),
410+
.add(content: nil),
411+
.add(content: .text("test")),
412412
]
413413
)
414414
}

BitwardenShared/UI/Platform/Application/Support/Localizations/en.lproj/Localizable.strings

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,3 +1182,5 @@
11821182
"DoYouReallyWantToDeleteAllRecordedLogs" = "Do you really want to delete all recorded logs?";
11831183
"ThisAccountWillSoonBeDeletedLogInAtXToContinueUsingBitwarden" = "This account will soon be deleted. Log in at %1$@ to continue using Bitwarden.";
11841184
"AppSettings" = "App settings";
1185+
"ViewFileSend" = "View file Send";
1186+
"ViewTextSend" = "View text Send";

BitwardenShared/UI/Tools/Send/Send/SendCoordinator.swift

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,30 +64,26 @@ final class SendCoordinator: Coordinator, HasStackNavigator {
6464
switch route {
6565
case let .addItem(type):
6666
guard let delegate = context as? SendItemDelegate else { return }
67-
Task {
68-
let hasPremium = try? await services.sendRepository.doesActiveAccountHavePremium()
69-
let route: SendItemRoute
70-
if let type {
71-
route = .add(content: .type(type), hasPremium: hasPremium ?? false)
72-
} else {
73-
route = .add(content: nil, hasPremium: hasPremium ?? false)
74-
}
75-
showItem(route: route, delegate: delegate)
67+
let route: SendItemRoute = if let type {
68+
.add(content: .type(type))
69+
} else {
70+
.add(content: nil)
7671
}
72+
showItem(route: route, delegate: delegate)
7773
case let .dismiss(dismissAction):
7874
stackNavigator?.dismiss(completion: dismissAction?.action)
7975
case let .editItem(sendView):
8076
guard let delegate = context as? SendItemDelegate else { return }
81-
Task {
82-
let hasPremium = try? await services.sendRepository.doesActiveAccountHavePremium()
83-
showItem(route: .edit(sendView, hasPremium: hasPremium ?? false), delegate: delegate)
84-
}
77+
showItem(route: .edit(sendView), delegate: delegate)
8578
case let .group(type):
8679
showGroup(type)
8780
case .list:
8881
showList()
8982
case let .share(url):
9083
showShareSheet(for: [url])
84+
case let .viewItem(sendView):
85+
guard let delegate = context as? SendItemDelegate else { return }
86+
showItem(route: .view(sendView), delegate: delegate)
9187
}
9288
}
9389

BitwardenShared/UI/Tools/Send/Send/SendCoordinatorTests.swift

Lines changed: 23 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ class SendCoordinatorTests: BitwardenTestCase {
4949

5050
/// `navigate(to:)` with `.addItem` presents the add send item screen.
5151
@MainActor
52-
func test_navigateTo_addItem_hasPremium_withDelegate() throws {
53-
sendRepository.doesActivateAccountHavePremiumResult = .success(true)
52+
func test_navigateTo_addItem_withDelegate() throws {
5453
subject.navigate(to: .addItem(), context: sendItemDelegate)
5554

5655
waitFor(!stackNavigator.actions.isEmpty)
@@ -59,14 +58,13 @@ class SendCoordinatorTests: BitwardenTestCase {
5958
XCTAssertTrue(action.view is UINavigationController)
6059

6160
XCTAssertTrue(module.sendItemCoordinator.isStarted)
62-
XCTAssertEqual(module.sendItemCoordinator.routes.last, .add(content: nil, hasPremium: true))
61+
XCTAssertEqual(module.sendItemCoordinator.routes.last, .add(content: nil))
6362
}
6463

6564
/// `navigate(to:)` with `.addItem` and without a delegate does not present the add send item
6665
/// screen.
6766
@MainActor
68-
func test_navigateTo_addItem_hasPremium_withoutDelegate() throws {
69-
sendRepository.doesActivateAccountHavePremiumResult = .success(true)
67+
func test_navigateTo_addItem_withoutDelegate() throws {
7068
subject.navigate(to: .addItem(), context: nil)
7169

7270
XCTAssertFalse(module.sendItemCoordinator.isStarted)
@@ -75,38 +73,7 @@ class SendCoordinatorTests: BitwardenTestCase {
7573

7674
/// `navigate(to:)` with `.addItem` presents the add send item screen.
7775
@MainActor
78-
func test_navigateTo_addItem_notHasPremium() throws {
79-
sendRepository.doesActivateAccountHavePremiumResult = .success(false)
80-
subject.navigate(to: .addItem(), context: sendItemDelegate)
81-
82-
waitFor(!stackNavigator.actions.isEmpty)
83-
let action = try XCTUnwrap(stackNavigator.actions.last)
84-
XCTAssertEqual(action.type, .presented)
85-
XCTAssertTrue(action.view is UINavigationController)
86-
87-
XCTAssertTrue(module.sendItemCoordinator.isStarted)
88-
XCTAssertEqual(module.sendItemCoordinator.routes.last, .add(content: nil, hasPremium: false))
89-
}
90-
91-
/// `navigate(to:)` with `.addItem` presents the add send item screen.
92-
@MainActor
93-
func test_navigateTo_addItem_hasPremiumError() throws {
94-
sendRepository.doesActivateAccountHavePremiumResult = .failure(BitwardenTestError.example)
95-
subject.navigate(to: .addItem(), context: sendItemDelegate)
96-
97-
waitFor(!stackNavigator.actions.isEmpty)
98-
let action = try XCTUnwrap(stackNavigator.actions.last)
99-
XCTAssertEqual(action.type, .presented)
100-
XCTAssertTrue(action.view is UINavigationController)
101-
102-
XCTAssertTrue(module.sendItemCoordinator.isStarted)
103-
XCTAssertEqual(module.sendItemCoordinator.routes.last, .add(content: nil, hasPremium: false))
104-
}
105-
106-
/// `navigate(to:)` with `.addItem` presents the add send item screen.
107-
@MainActor
108-
func test_navigateTo_addItem_fileType_hasPremium_withDelegate() throws {
109-
sendRepository.doesActivateAccountHavePremiumResult = .success(true)
76+
func test_navigateTo_addItem_fileType_withDelegate() throws {
11077
subject.navigate(to: .addItem(type: .file), context: sendItemDelegate)
11178

11279
waitFor(!stackNavigator.actions.isEmpty)
@@ -115,50 +82,19 @@ class SendCoordinatorTests: BitwardenTestCase {
11582
XCTAssertTrue(action.view is UINavigationController)
11683

11784
XCTAssertTrue(module.sendItemCoordinator.isStarted)
118-
XCTAssertEqual(module.sendItemCoordinator.routes.last, .add(content: .type(.file), hasPremium: true))
85+
XCTAssertEqual(module.sendItemCoordinator.routes.last, .add(content: .type(.file)))
11986
}
12087

12188
/// `navigate(to:)` with `.addItem` and without a delegate does not present the add send item
12289
/// screen.
12390
@MainActor
124-
func test_navigateTo_addItem_fileType_hasPremium_withoutDelegate() throws {
125-
sendRepository.doesActivateAccountHavePremiumResult = .success(true)
91+
func test_navigateTo_addItem_fileType_withoutDelegate() throws {
12692
subject.navigate(to: .addItem(type: .file), context: nil)
12793

12894
XCTAssertFalse(module.sendItemCoordinator.isStarted)
12995
XCTAssertTrue(module.sendItemCoordinator.routes.isEmpty)
13096
}
13197

132-
/// `navigate(to:)` with `.addItem` presents the add send item screen.
133-
@MainActor
134-
func test_navigateTo_addItem_fileType_notHasPremium() throws {
135-
sendRepository.doesActivateAccountHavePremiumResult = .success(false)
136-
subject.navigate(to: .addItem(type: .file), context: sendItemDelegate)
137-
138-
waitFor(!stackNavigator.actions.isEmpty)
139-
let action = try XCTUnwrap(stackNavigator.actions.last)
140-
XCTAssertEqual(action.type, .presented)
141-
XCTAssertTrue(action.view is UINavigationController)
142-
143-
XCTAssertTrue(module.sendItemCoordinator.isStarted)
144-
XCTAssertEqual(module.sendItemCoordinator.routes.last, .add(content: .type(.file), hasPremium: false))
145-
}
146-
147-
/// `navigate(to:)` with `.addItem` presents the add send item screen.
148-
@MainActor
149-
func test_navigateTo_addItem_fileType_hasPremiumError() throws {
150-
sendRepository.doesActivateAccountHavePremiumResult = .failure(BitwardenTestError.example)
151-
subject.navigate(to: .addItem(type: .file), context: sendItemDelegate)
152-
153-
waitFor(!stackNavigator.actions.isEmpty)
154-
let action = try XCTUnwrap(stackNavigator.actions.last)
155-
XCTAssertEqual(action.type, .presented)
156-
XCTAssertTrue(action.view is UINavigationController)
157-
158-
XCTAssertTrue(module.sendItemCoordinator.isStarted)
159-
XCTAssertEqual(module.sendItemCoordinator.routes.last, .add(content: .type(.file), hasPremium: false))
160-
}
161-
16298
/// `navigate(to:)` with `.dismiss` dismisses the current modally presented screen.
16399
@MainActor
164100
func test_navigateTo_dismiss() throws {
@@ -170,8 +106,7 @@ class SendCoordinatorTests: BitwardenTestCase {
170106

171107
/// `navigate(to:)` with `.editItem` presents the add send item screen.
172108
@MainActor
173-
func test_navigateTo_editItem_hasPremium_withDelegate() throws {
174-
sendRepository.doesActivateAccountHavePremiumResult = .success(true)
109+
func test_navigateTo_editItem_withDelegate() throws {
175110
let sendView = SendView.fixture()
176111
subject.navigate(to: .editItem(sendView), context: sendItemDelegate)
177112

@@ -181,53 +116,20 @@ class SendCoordinatorTests: BitwardenTestCase {
181116
XCTAssertTrue(action.view is UINavigationController)
182117

183118
XCTAssertTrue(module.sendItemCoordinator.isStarted)
184-
XCTAssertEqual(module.sendItemCoordinator.routes.last, .edit(sendView, hasPremium: true))
119+
XCTAssertEqual(module.sendItemCoordinator.routes.last, .edit(sendView))
185120
}
186121

187122
/// `navigate(to:)` with `.editItem` and without a delegate does not present the add send item
188123
/// screen.
189124
@MainActor
190-
func test_navigateTo_editItem_hasPremium_withoutDelegate() throws {
191-
sendRepository.doesActivateAccountHavePremiumResult = .success(true)
125+
func test_navigateTo_editItem_withoutDelegate() throws {
192126
let sendView = SendView.fixture()
193127
subject.navigate(to: .editItem(sendView), context: nil)
194128

195129
XCTAssertFalse(module.sendItemCoordinator.isStarted)
196130
XCTAssertTrue(module.sendItemCoordinator.routes.isEmpty)
197131
}
198132

199-
/// `navigate(to:)` with `.editItem` presents the add send item screen.
200-
@MainActor
201-
func test_navigateTo_editItem_notHasPremium() throws {
202-
sendRepository.doesActivateAccountHavePremiumResult = .success(false)
203-
let sendView = SendView.fixture()
204-
subject.navigate(to: .editItem(sendView), context: sendItemDelegate)
205-
206-
waitFor(!stackNavigator.actions.isEmpty)
207-
let action = try XCTUnwrap(stackNavigator.actions.last)
208-
XCTAssertEqual(action.type, .presented)
209-
XCTAssertTrue(action.view is UINavigationController)
210-
211-
XCTAssertTrue(module.sendItemCoordinator.isStarted)
212-
XCTAssertEqual(module.sendItemCoordinator.routes.last, .edit(sendView, hasPremium: false))
213-
}
214-
215-
/// `navigate(to:)` with `.editItem` presents the add send item screen.
216-
@MainActor
217-
func test_navigateTo_editItem_hasPremiumError() throws {
218-
sendRepository.doesActivateAccountHavePremiumResult = .failure(BitwardenTestError.example)
219-
let sendView = SendView.fixture()
220-
subject.navigate(to: .editItem(sendView), context: sendItemDelegate)
221-
222-
waitFor(!stackNavigator.actions.isEmpty)
223-
let action = try XCTUnwrap(stackNavigator.actions.last)
224-
XCTAssertEqual(action.type, .presented)
225-
XCTAssertTrue(action.view is UINavigationController)
226-
227-
XCTAssertTrue(module.sendItemCoordinator.isStarted)
228-
XCTAssertEqual(module.sendItemCoordinator.routes.last, .edit(sendView, hasPremium: false))
229-
}
230-
231133
/// `navigate(to:)` with `.group` pushes the send list screen for the type onto the stack.
232134
@MainActor
233135
func test_navigateTo_group() throws {
@@ -263,6 +165,20 @@ class SendCoordinatorTests: BitwardenTestCase {
263165
XCTAssertTrue(action.view is UIActivityViewController)
264166
}
265167

168+
/// `navigate(to:)` with `.viewItem` presents the view send item screen
169+
@MainActor
170+
func test_navigateTo_viewItem() throws {
171+
let sendView = SendView.fixture()
172+
subject.navigate(to: .viewItem(sendView), context: sendItemDelegate)
173+
174+
let action = try XCTUnwrap(stackNavigator.actions.last)
175+
XCTAssertEqual(action.type, .presented)
176+
XCTAssertTrue(action.view is UINavigationController)
177+
178+
XCTAssertTrue(module.sendItemCoordinator.isStarted)
179+
XCTAssertEqual(module.sendItemCoordinator.routes.last, .view(sendView))
180+
}
181+
266182
/// `start()` initializes the coordinator's state correctly.
267183
@MainActor
268184
func test_start() throws {

BitwardenShared/UI/Tools/Send/Send/SendRoute.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,10 @@ public enum SendRoute: Equatable {
3333
/// - Parameter url: The `URL` to share.
3434
///
3535
case share(url: URL)
36+
37+
/// A route to view send item screen.
38+
///
39+
/// - Parameter sendView: The `SendView` to view the details of.
40+
///
41+
case viewItem(_ sendView: SendView)
3642
}

BitwardenShared/UI/Tools/Send/SendItem/AddEditSendItem/AddEditSendItemProcessor.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ class AddEditSendItemProcessor:
165165
if state.maximumAccessCount != 0 {
166166
state.maximumAccessCountText = "\(state.maximumAccessCount)"
167167
}
168+
169+
do {
170+
state.hasPremium = try await services.sendRepository.doesActiveAccountHavePremium()
171+
} catch {
172+
services.errorReporter.log(error: error)
173+
}
168174
}
169175

170176
/// A method to respond to a `ProfileSwitcherAction`

0 commit comments

Comments
 (0)