Skip to content

Commit d484f29

Browse files
authored
Merge pull request #7124 from woocommerce/issue/6524-orders-test-with-shipping
[Order Creation] Expand new order UI test to include adding shipping
2 parents e1e5d34 + 9a5692c commit d484f29

File tree

10 files changed

+236
-57
lines changed

10 files changed

+236
-57
lines changed

WooCommerce/Classes/ViewRelated/Orders/Order Creation/PaymentSection/OrderPaymentSection.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ struct OrderPaymentSection: View {
6767
}
6868
.buttonStyle(PlusButtonStyle())
6969
.padding()
70+
.accessibilityIdentifier("add-shipping-button")
7071
}
7172
}
7273

WooCommerce/Classes/ViewRelated/Orders/Order Creation/PaymentSection/ShippingLineDetails.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ struct ShippingLineDetails: View {
3737
.onTapGesture {
3838
focusAmountInput = true
3939
}
40+
.accessibilityIdentifier("add-shipping-amount-field")
4041
}
4142
}
4243
.frame(minHeight: Layout.amountRowHeight)
@@ -50,6 +51,7 @@ struct ShippingLineDetails: View {
5051
text: $viewModel.methodTitle,
5152
symbol: nil,
5253
keyboardType: .default)
54+
.accessibilityIdentifier("add-shipping-name-field")
5355
}
5456
.padding(.horizontal, insets: safeAreaInsets)
5557
.addingTopAndBottomDividers()
@@ -90,6 +92,7 @@ struct ShippingLineDetails: View {
9092
presentation.wrappedValue.dismiss()
9193
}
9294
.disabled(viewModel.shouldDisableDoneButton)
95+
.accessibilityIdentifier("add-shipping-done-button")
9396
}
9497
}
9598
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import ScreenObject
2+
import XCTest
3+
4+
public final class AddShippingScreen: ScreenObject {
5+
6+
private let shippingAmountGetter: (XCUIApplication) -> XCUIElement = {
7+
$0.textFields["add-shipping-amount-field"]
8+
}
9+
10+
private let shippingNameGetter: (XCUIApplication) -> XCUIElement = {
11+
$0.textFields["add-shipping-name-field"]
12+
}
13+
14+
private let doneButtonGetter: (XCUIApplication) -> XCUIElement = {
15+
$0.buttons["add-shipping-done-button"]
16+
}
17+
18+
private var shippingAmountField: XCUIElement { shippingAmountGetter(app) }
19+
20+
private var shippingNameField: XCUIElement { shippingNameGetter(app) }
21+
22+
private var doneButton: XCUIElement { doneButtonGetter(app) }
23+
24+
init(app: XCUIApplication = XCUIApplication()) throws {
25+
try super.init(
26+
expectedElementGetters: [ shippingAmountGetter ],
27+
app: app
28+
)
29+
}
30+
31+
/// Enters a shipping amount.
32+
/// - Returns: Add Shipping screen object.
33+
@discardableResult
34+
public func enterShippingAmount(_ amount: String) throws -> Self {
35+
shippingAmountField.tap()
36+
shippingAmountField.typeText(amount)
37+
return self
38+
}
39+
40+
/// Enters a shipping name.
41+
/// - Returns: Add Shipping screen object.
42+
@discardableResult
43+
public func enterShippingName(_ name: String) throws -> Self {
44+
shippingNameField.tap()
45+
shippingNameField.typeText(name)
46+
return self
47+
}
48+
49+
/// Confirms entered shipping details and closes Add Shipping screen.
50+
/// - Returns: New Order screen object.
51+
@discardableResult
52+
public func confirmShippingDetails() throws -> NewOrderScreen {
53+
doneButton.tap()
54+
return try NewOrderScreen()
55+
}
56+
}

WooCommerce/UITestsFoundation/Screens/Orders/NewOrderScreen.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ public final class NewOrderScreen: ScreenObject {
2323
$0.staticTexts["Add Customer Details"]
2424
}
2525

26+
private let addShippingButtonGetter: (XCUIApplication) -> XCUIElement = {
27+
$0.buttons["add-shipping-button"]
28+
}
29+
2630
private var createButton: XCUIElement { createButtonGetter(app) }
2731

2832
/// Cancel button in the Navigation bar.
@@ -41,6 +45,10 @@ public final class NewOrderScreen: ScreenObject {
4145
///
4246
private var addCustomerDetailsButton: XCUIElement { addCustomerDetailsButtonGetter(app) }
4347

48+
/// Add Shipping button in the Payment section.
49+
///
50+
private var addShippingButton: XCUIElement { addShippingButtonGetter(app) }
51+
4452
public init(app: XCUIApplication = XCUIApplication()) throws {
4553
try super.init(
4654
expectedElementGetters: [ createButtonGetter ],
@@ -74,6 +82,14 @@ public final class NewOrderScreen: ScreenObject {
7482
return try CustomerDetailsScreen()
7583
}
7684

85+
/// Opens the Add Shipping screen.
86+
/// - Returns: Add Shipping screen object.
87+
@discardableResult
88+
public func openAddShippingScreen() throws -> AddShippingScreen {
89+
addShippingButton.tap()
90+
return try AddShippingScreen()
91+
}
92+
7793
// MARK: - High-level Order Creation actions
7894

7995
/// Creates a remote order with all of the entered order data.
@@ -107,6 +123,18 @@ public final class NewOrderScreen: ScreenObject {
107123
.enterCustomerDetails(name: name)
108124
}
109125

126+
/// Adds shipping on the Add Shipping screen.
127+
/// - Parameters:
128+
/// - amount: Amount (in the store currency) to add for shipping.
129+
/// - name: Name of the shipping method (e.g. "Free Shipping" or "Flat Rate").
130+
/// - Returns: New Order screen object.
131+
public func addShipping(amount: String, name: String) throws -> NewOrderScreen {
132+
return try openAddShippingScreen()
133+
.enterShippingAmount(amount)
134+
.enterShippingName(name)
135+
.confirmShippingDetails()
136+
}
137+
110138
/// Cancels Order Creation process
111139
/// - Returns: Orders Screen object.
112140
@discardableResult

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,7 @@
12601260
CC254F3426C4113B005F3C82 /* ShippingLabelPackageSelection.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC254F3326C4113B005F3C82 /* ShippingLabelPackageSelection.swift */; };
12611261
CC254F3626C437AB005F3C82 /* ShippingLabelCustomPackageForm.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC254F3526C437AB005F3C82 /* ShippingLabelCustomPackageForm.swift */; };
12621262
CC254F3826C43B52005F3C82 /* ShippingLabelCustomPackageFormViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC254F3726C43B52005F3C82 /* ShippingLabelCustomPackageFormViewModel.swift */; };
1263+
CC2A08022862400100510C4B /* orders_3337_add_shipping.json in Resources */ = {isa = PBXBuildFile; fileRef = CC2A08012862400100510C4B /* orders_3337_add_shipping.json */; };
12631264
CC2E72F727B6BFB800A62872 /* ProductVariationFormatterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC2E72F627B6BFB800A62872 /* ProductVariationFormatterTests.swift */; };
12641265
CC440E1E2770C6AF0074C264 /* ProductInOrderViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC440E1D2770C6AF0074C264 /* ProductInOrderViewModel.swift */; };
12651266
CC4A4E962655273D00B75DCD /* ShippingLabelPaymentMethods.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC4A4E952655273D00B75DCD /* ShippingLabelPaymentMethods.swift */; };
@@ -1283,6 +1284,7 @@
12831284
CC666F2627F359590045AF1E /* OrdersTopBannerFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC666F2527F359590045AF1E /* OrdersTopBannerFactory.swift */; };
12841285
CC69236226010946002FB669 /* LoginProloguePages.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC69236126010946002FB669 /* LoginProloguePages.swift */; };
12851286
CC6923AC26010D8D002FB669 /* LoginProloguePageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC6923AB26010D8D002FB669 /* LoginProloguePageViewController.swift */; };
1287+
CC71353B2862285300A28B42 /* AddShippingScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC71353A2862285300A28B42 /* AddShippingScreen.swift */; };
12861288
CC72BB6427BD842500837876 /* DisclosureIndicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC72BB6327BD842500837876 /* DisclosureIndicator.swift */; };
12871289
CC770C8A27B1497700CE6ABC /* SearchHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC770C8927B1497700CE6ABC /* SearchHeader.swift */; };
12881290
CC77488E2719A07D0043CDD7 /* ShippingLabelAddressTopBannerFactoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC77488D2719A07D0043CDD7 /* ShippingLabelAddressTopBannerFactoryTests.swift */; };
@@ -3032,6 +3034,7 @@
30323034
CC254F3326C4113B005F3C82 /* ShippingLabelPackageSelection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShippingLabelPackageSelection.swift; sourceTree = "<group>"; };
30333035
CC254F3526C437AB005F3C82 /* ShippingLabelCustomPackageForm.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShippingLabelCustomPackageForm.swift; sourceTree = "<group>"; };
30343036
CC254F3726C43B52005F3C82 /* ShippingLabelCustomPackageFormViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShippingLabelCustomPackageFormViewModel.swift; sourceTree = "<group>"; };
3037+
CC2A08012862400100510C4B /* orders_3337_add_shipping.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = orders_3337_add_shipping.json; sourceTree = "<group>"; };
30353038
CC2E72F627B6BFB800A62872 /* ProductVariationFormatterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductVariationFormatterTests.swift; sourceTree = "<group>"; };
30363039
CC440E1D2770C6AF0074C264 /* ProductInOrderViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductInOrderViewModel.swift; sourceTree = "<group>"; };
30373040
CC4A4E952655273D00B75DCD /* ShippingLabelPaymentMethods.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShippingLabelPaymentMethods.swift; sourceTree = "<group>"; };
@@ -3055,6 +3058,7 @@
30553058
CC666F2527F359590045AF1E /* OrdersTopBannerFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrdersTopBannerFactory.swift; sourceTree = "<group>"; };
30563059
CC69236126010946002FB669 /* LoginProloguePages.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginProloguePages.swift; sourceTree = "<group>"; };
30573060
CC6923AB26010D8D002FB669 /* LoginProloguePageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginProloguePageViewController.swift; sourceTree = "<group>"; };
3061+
CC71353A2862285300A28B42 /* AddShippingScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddShippingScreen.swift; sourceTree = "<group>"; };
30583062
CC72BB6327BD842500837876 /* DisclosureIndicator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisclosureIndicator.swift; sourceTree = "<group>"; };
30593063
CC770C8927B1497700CE6ABC /* SearchHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchHeader.swift; sourceTree = "<group>"; };
30603064
CC77488D2719A07D0043CDD7 /* ShippingLabelAddressTopBannerFactoryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShippingLabelAddressTopBannerFactoryTests.swift; sourceTree = "<group>"; };
@@ -6905,6 +6909,7 @@
69056909
CC5C278A27EE314E00B25D2A /* orders_3337_create_order.json */,
69066910
CCF27B33280EF69600B755E1 /* orders_3337_add_product.json */,
69076911
C0A37CB7282957EB00E0826D /* orders_3337_add_customer_details.json */,
6912+
CC2A08012862400100510C4B /* orders_3337_add_shipping.json */,
69086913
CCF27B39280EF98F00B755E1 /* orders_3337.json */,
69096914
800A5B9A2755E0B9009DE2CD /* orders_any.json */,
69106915
800A5B9F27562EE5009DE2CD /* orders_processing.json */,
@@ -8076,6 +8081,7 @@
80768081
F997173C23DBFBBF00592D8E /* OrderSearchScreen.swift */,
80778082
CC1AB56727FC5821003DEF43 /* OrderStatusScreen.swift */,
80788083
C044961228058FE8003B3081 /* AddProductScreen.swift */,
8084+
CC71353A2862285300A28B42 /* AddShippingScreen.swift */,
80798085
);
80808086
path = Orders;
80818087
sourceTree = "<group>";
@@ -8586,6 +8592,7 @@
85868592
800A5BB027586898009DE2CD /* products_2132.json in Resources */,
85878593
800A5BA6275719E5009DE2CD /* orders_2201_refunds.json in Resources */,
85888594
800A5BA827586126009DE2CD /* products_2129.json in Resources */,
8595+
CC2A08022862400100510C4B /* orders_3337_add_shipping.json in Resources */,
85898596
800A5BC027586AFC009DE2CD /* products_reviews_6164.json in Resources */,
85908597
800A5BC5275889ED009DE2CD /* reports_revenue_stats_day.json in Resources */,
85918598
800A5B972755BA02009DE2CD /* status.json in Resources */,
@@ -8782,6 +8789,7 @@
87828789
3FF314EA26FC751B0012E68E /* XCTest+Extensions.swift in Sources */,
87838790
3F0CF3002704490A00EF3D71 /* OrderSearchScreen.swift in Sources */,
87848791
3F0CF3012704490A00EF3D71 /* ReviewsScreen.swift in Sources */,
8792+
CC71353B2862285300A28B42 /* AddShippingScreen.swift in Sources */,
87858793
3F0CF30A2704490A00EF3D71 /* OrdersScreen.swift in Sources */,
87868794
C044961328058FE8003B3081 /* AddProductScreen.swift in Sources */,
87878795
3F0CF3132704490A00EF3D71 /* PrologueScreen.swift in Sources */,

WooCommerce/WooCommerceUITests/Mocks/mappings/jetpack-blogs/wc/orders/orders_3337.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
"date_modified": "{{now offset='-10 minutes' format=customformat}}",
2626
"discount_total": "0.00",
2727
"discount_tax": "0.00",
28-
"shipping_total": "0.00",
28+
"shipping_total": "1.25",
2929
"shipping_tax": "0.00",
3030
"cart_tax": "0.00",
31-
"total": "110.00",
31+
"total": "111.25",
3232
"total_tax": "0.00",
3333
"customer_id": 0,
3434
"order_key": "abc123",
@@ -86,7 +86,15 @@
8686
"price": 110
8787
}],
8888
"tax_lines": [],
89-
"shipping_lines": [],
89+
"shipping_lines": [{
90+
"id": 1,
91+
"method_title": "Flat Rate",
92+
"method_id": "other",
93+
"total": "1.25",
94+
"total_tax": "0.00",
95+
"taxes": [],
96+
"meta_data": []
97+
}],
9098
"fee_lines": [],
9199
"coupon_lines": [],
92100
"refunds": [],

WooCommerce/WooCommerceUITests/Mocks/mappings/jetpack-blogs/wc/orders/orders_3337_add_customer_details.json

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,13 @@
22
"request": {
33
"method": "POST",
44
"urlPath": "/rest/v1.1/jetpack-blogs/161477129/rest-api/",
5-
"bodyPatterns": [ {
6-
"matches": ".*path=/wc/v3/orders/3337%26_method%3Dpost.*",
7-
"equalToJson": {
8-
"line_items": [{
9-
"quantity": 1,
10-
"total": "110.00",
11-
"subtotal": "110.00",
12-
"id": 1,
13-
"product_id": 2129
14-
}],
15-
"fee_lines": [],
16-
"shipping_lines": [],
17-
"billing": {
18-
"first_name": "Mira",
19-
"last_name": "",
20-
"company": "",
21-
"address_1": "",
22-
"address_2": "",
23-
"city": "",
24-
"state": "",
25-
"postcode": "",
26-
"country": "",
27-
"email": null,
28-
"phone": ""
29-
},
30-
"shipping": {
31-
"first_name": "Mira",
32-
"last_name": "",
33-
"company": "",
34-
"address_1": "",
35-
"address_2": "",
36-
"city": "",
37-
"state": "",
38-
"postcode": "",
39-
"country": "",
40-
"email": null,
41-
"phone": ""
42-
}
43-
}
44-
} ]
5+
"bodyPatterns": [
6+
{ "matches": ".*path=/wc/v3/orders/3337%26_method%3Dpost.*" },
7+
{ "contains": "%22product_id%22%3A2129" },
8+
{ "contains": "%22fee_lines%22%3A%5B%5D" },
9+
{ "contains": "%22shipping_lines%22%3A%5B%5D" },
10+
{ "contains": "%22first_name%22%3A%22Mira%22" }
11+
]
4512
},
4613
"response": {
4714
"status": 200,

WooCommerce/WooCommerceUITests/Mocks/mappings/jetpack-blogs/wc/orders/orders_3337_add_product.json

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,11 @@
22
"request": {
33
"method": "POST",
44
"urlPath": "/rest/v1.1/jetpack-blogs/161477129/rest-api/",
5-
"bodyPatterns": [ {
6-
"matches": ".*path=/wc/v3/orders%26_method%3Dpost.*",
7-
"equalToJson": {
8-
"line_items": [{
9-
"quantity": 1,
10-
"id": 0,
11-
"product_id": 2129
12-
}],
13-
"customer_note": "",
14-
"status": "auto-draft",
15-
"fee_lines": [],
16-
"shipping_lines": []
17-
}
18-
} ]
5+
"bodyPatterns": [
6+
{ "matches": ".*path=/wc/v3/orders%26_method%3Dpost.*" },
7+
{ "contains": "%22status%22%3A%22auto-draft%22" },
8+
{ "contains": "%22product_id%22%3A2129" }
9+
]
1910
},
2011
"response": {
2112
"status": 200,

0 commit comments

Comments
 (0)