Skip to content

Commit 86ab1ba

Browse files
committed
Add tests for AddOrderCoordinator
1 parent 9abe13d commit 86ab1ba

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,7 @@
892892
AE6DBE3B2732CAAD00957E7A /* AdaptiveStack.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE6DBE3A2732CAAD00957E7A /* AdaptiveStack.swift */; };
893893
AEA622B2274669D3002A9B57 /* AddOrderCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEA622B1274669D3002A9B57 /* AddOrderCoordinator.swift */; };
894894
AEA622B427466B78002A9B57 /* BottomSheetOrderType.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEA622B327466B78002A9B57 /* BottomSheetOrderType.swift */; };
895+
AEA622B727468790002A9B57 /* AddOrderCoordinatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEA622B627468790002A9B57 /* AddOrderCoordinatorTests.swift */; };
895896
AEB73C0C25CD734200A8454A /* AttributePickerViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEB73C0B25CD734200A8454A /* AttributePickerViewModel.swift */; };
896897
AEB73C1725CD8E5800A8454A /* AttributePickerViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEB73C1625CD8E5800A8454A /* AttributePickerViewModelTests.swift */; };
897898
AECD57D226DFDF7500A3B580 /* EditOrderAddressForm.swift in Sources */ = {isa = PBXBuildFile; fileRef = AECD57D126DFDF7500A3B580 /* EditOrderAddressForm.swift */; };
@@ -2343,6 +2344,7 @@
23432344
AE6DBE3A2732CAAD00957E7A /* AdaptiveStack.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdaptiveStack.swift; sourceTree = "<group>"; };
23442345
AEA622B1274669D3002A9B57 /* AddOrderCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddOrderCoordinator.swift; sourceTree = "<group>"; };
23452346
AEA622B327466B78002A9B57 /* BottomSheetOrderType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BottomSheetOrderType.swift; sourceTree = "<group>"; };
2347+
AEA622B627468790002A9B57 /* AddOrderCoordinatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddOrderCoordinatorTests.swift; sourceTree = "<group>"; };
23462348
AEB73C0B25CD734200A8454A /* AttributePickerViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttributePickerViewModel.swift; sourceTree = "<group>"; };
23472349
AEB73C1625CD8E5800A8454A /* AttributePickerViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttributePickerViewModelTests.swift; sourceTree = "<group>"; };
23482350
AECD57D126DFDF7500A3B580 /* EditOrderAddressForm.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditOrderAddressForm.swift; sourceTree = "<group>"; };
@@ -4841,6 +4843,7 @@
48414843
2667BFD5252E5D4C008099D4 /* Issue Refund */,
48424844
57F2C6C9246DEBB10074063B /* Order Details */,
48434845
262AF3882713B65700E39AFF /* Simple Payments */,
4846+
AEA622B52746876D002A9B57 /* Order Creation */,
48444847
570AAB042472FACB00516C0C /* OrderDetailsDataSourceTests.swift */,
48454848
57C5FF7B25091DE50074EC26 /* OrderListSyncActionUseCaseTests.swift */,
48464849
5767E93F256D9A4A00CFA652 /* OrderListViewModelTests.swift */,
@@ -5106,6 +5109,14 @@
51065109
path = ../config;
51075110
sourceTree = "<group>";
51085111
};
5112+
AEA622B52746876D002A9B57 /* Order Creation */ = {
5113+
isa = PBXGroup;
5114+
children = (
5115+
AEA622B627468790002A9B57 /* AddOrderCoordinatorTests.swift */,
5116+
);
5117+
path = "Order Creation";
5118+
sourceTree = "<group>";
5119+
};
51095120
AEB73C1525CD8E3100A8454A /* Edit Product Variation */ = {
51105121
isa = PBXGroup;
51115122
children = (
@@ -8591,6 +8602,7 @@
85918602
4524CDA1242D045C00B2F20A /* ProductStatusSettingListSelectorCommandTests.swift in Sources */,
85928603
02077F72253816FF005A78EF /* ProductFormActionsFactory+ReadonlyProductTests.swift in Sources */,
85938604
D8C11A6222E24C4A00D4A88D /* LedgerTableViewCellTests.swift in Sources */,
8605+
AEA622B727468790002A9B57 /* AddOrderCoordinatorTests.swift in Sources */,
85948606
D802549126552FE1001B2CC1 /* CardPresentModalScanningForReaderTests.swift in Sources */,
85958607
A655725D258B91AE008AE7CA /* OrderListCellViewModelTests.swift in Sources */,
85968608
D83A6A7A23792B2400419D48 /* UIColor+Muriel-Tests.swift in Sources */,
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import TestKit
2+
import XCTest
3+
import Yosemite
4+
5+
@testable import WooCommerce
6+
import WordPressUI
7+
8+
final class AddOrderCoordinatorTests: XCTestCase {
9+
private var navigationController: UINavigationController!
10+
11+
override func setUp() {
12+
super.setUp()
13+
navigationController = UINavigationController()
14+
15+
let window = UIWindow(frame: UIScreen.main.bounds)
16+
window.rootViewController = UIViewController()
17+
window.makeKeyAndVisible()
18+
window.rootViewController = navigationController
19+
}
20+
21+
override func tearDown() {
22+
navigationController = nil
23+
super.tearDown()
24+
}
25+
26+
func test_it_presents_bottom_sheet_when_all_types_are_available() throws {
27+
// Given
28+
let coordinator = makeAddProductCoordinator(isOrderCreationEnabled: true,
29+
shouldShowSimplePaymentsButton: true)
30+
31+
// When
32+
coordinator.start()
33+
waitUntil {
34+
coordinator.navigationController.presentedViewController != nil
35+
}
36+
37+
// Then
38+
assertThat(coordinator.navigationController.presentedViewController, isAnInstanceOf: BottomSheetViewController.self)
39+
}
40+
41+
func test_it_does_nothing_when_all_types_are_unaviable() throws {
42+
// Given
43+
let coordinator = makeAddProductCoordinator(isOrderCreationEnabled: false,
44+
shouldShowSimplePaymentsButton: false)
45+
46+
// When
47+
coordinator.start()
48+
49+
// Then
50+
XCTAssertNil(coordinator.navigationController.presentedViewController)
51+
}
52+
53+
func test_it_opens_simple_payments_when_its_only_available_type() throws {
54+
// Given
55+
let coordinator = makeAddProductCoordinator(isOrderCreationEnabled: false,
56+
shouldShowSimplePaymentsButton: true)
57+
58+
// When
59+
coordinator.start()
60+
waitUntil {
61+
coordinator.navigationController.presentedViewController != nil
62+
}
63+
64+
// Then
65+
let presentedNC = coordinator.navigationController.presentedViewController as? UINavigationController
66+
assertThat(presentedNC, isAnInstanceOf: WooNavigationController.self)
67+
assertThat(presentedNC?.topViewController, isAnInstanceOf: SimplePaymentsAmountHostingController.self)
68+
}
69+
}
70+
71+
private extension AddOrderCoordinatorTests {
72+
func makeAddProductCoordinator(isOrderCreationEnabled: Bool, shouldShowSimplePaymentsButton: Bool) -> AddOrderCoordinator {
73+
let sourceBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: nil, action: nil)
74+
return AddOrderCoordinator(siteID: 100,
75+
isOrderCreationEnabled: isOrderCreationEnabled,
76+
shouldShowSimplePaymentsButton: shouldShowSimplePaymentsButton,
77+
sourceBarButtonItem: sourceBarButtonItem,
78+
sourceNavigationController: navigationController)
79+
}
80+
}

0 commit comments

Comments
 (0)