Skip to content

Commit 52d0509

Browse files
authored
Merge pull request #7127 from woocommerce/issue/6524-orders-test-with-fee
[Order Creation] Expand new order UI test to include adding fee
2 parents d484f29 + 5f8c7bc commit 52d0509

File tree

8 files changed

+217
-2
lines changed

8 files changed

+217
-2
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ struct FeeLineDetails: View {
9999
presentation.wrappedValue.dismiss()
100100
}
101101
.disabled(viewModel.shouldDisableDoneButton)
102+
.accessibilityIdentifier("add-fee-done-button")
102103
}
103104
}
104105
}
@@ -120,6 +121,7 @@ struct FeeLineDetails: View {
120121
.onTapGesture {
121122
focusFixedAmountInput = true
122123
}
124+
.accessibilityIdentifier("add-fee-fixed-amount-field")
123125
}
124126
}
125127
.frame(minHeight: Layout.rowHeight)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ struct OrderPaymentSection: View {
8282
}
8383
.buttonStyle(PlusButtonStyle())
8484
.padding()
85+
.accessibilityIdentifier("add-fee-button")
8586
}
8687
}
8788
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import ScreenObject
2+
import XCTest
3+
4+
public final class AddFeeScreen: ScreenObject {
5+
6+
private let feeFixedAmountGetter: (XCUIApplication) -> XCUIElement = {
7+
$0.textFields["add-fee-fixed-amount-field"]
8+
}
9+
10+
private let doneButtonGetter: (XCUIApplication) -> XCUIElement = {
11+
$0.buttons["add-fee-done-button"]
12+
}
13+
14+
private var feeFixedAmountField: XCUIElement { feeFixedAmountGetter(app) }
15+
16+
private var doneButton: XCUIElement { doneButtonGetter(app) }
17+
18+
init(app: XCUIApplication = XCUIApplication()) throws {
19+
try super.init(
20+
expectedElementGetters: [ feeFixedAmountGetter ],
21+
app: app
22+
)
23+
}
24+
25+
/// Enters a fixed fee amount.
26+
/// - Returns: Add Fee screen object.
27+
@discardableResult
28+
public func enterFixedFee(amount: String) throws -> Self {
29+
feeFixedAmountField.tap()
30+
feeFixedAmountField.typeText(amount)
31+
return self
32+
}
33+
34+
/// Confirms entered fee and closes Add Fee screen.
35+
/// - Returns: New Order screen object.
36+
@discardableResult
37+
public func confirmFee() throws -> NewOrderScreen {
38+
doneButton.tap()
39+
return try NewOrderScreen()
40+
}
41+
}

WooCommerce/UITestsFoundation/Screens/Orders/NewOrderScreen.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public final class NewOrderScreen: ScreenObject {
2727
$0.buttons["add-shipping-button"]
2828
}
2929

30+
private let addFeeButtonGetter: (XCUIApplication) -> XCUIElement = {
31+
$0.buttons["add-fee-button"]
32+
}
33+
3034
private var createButton: XCUIElement { createButtonGetter(app) }
3135

3236
/// Cancel button in the Navigation bar.
@@ -49,6 +53,10 @@ public final class NewOrderScreen: ScreenObject {
4953
///
5054
private var addShippingButton: XCUIElement { addShippingButtonGetter(app) }
5155

56+
/// Add Fee button in the Payment section.
57+
///
58+
private var addFeeButton: XCUIElement { addFeeButtonGetter(app) }
59+
5260
public init(app: XCUIApplication = XCUIApplication()) throws {
5361
try super.init(
5462
expectedElementGetters: [ createButtonGetter ],
@@ -90,6 +98,14 @@ public final class NewOrderScreen: ScreenObject {
9098
return try AddShippingScreen()
9199
}
92100

101+
/// Opens the Add Fee screen.
102+
/// - Returns: Add Fee screen object.
103+
@discardableResult
104+
public func openAddFeeScreen() throws -> AddFeeScreen {
105+
addFeeButton.tap()
106+
return try AddFeeScreen()
107+
}
108+
93109
// MARK: - High-level Order Creation actions
94110

95111
/// Creates a remote order with all of the entered order data.
@@ -135,6 +151,16 @@ public final class NewOrderScreen: ScreenObject {
135151
.confirmShippingDetails()
136152
}
137153

154+
/// Adds a fee on the Add Fee screen.
155+
/// - Parameters:
156+
/// - amount: Amount (in the store currency) to add as a fee.
157+
/// - Returns: New Order screen object.
158+
public func addFee(amount: String) throws -> NewOrderScreen {
159+
return try openAddFeeScreen()
160+
.enterFixedFee(amount: amount)
161+
.confirmFee()
162+
}
163+
138164
/// Cancels Order Creation process
139165
/// - Returns: Orders Screen object.
140166
@discardableResult

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,8 @@
12611261
CC254F3626C437AB005F3C82 /* ShippingLabelCustomPackageForm.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC254F3526C437AB005F3C82 /* ShippingLabelCustomPackageForm.swift */; };
12621262
CC254F3826C43B52005F3C82 /* ShippingLabelCustomPackageFormViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC254F3726C43B52005F3C82 /* ShippingLabelCustomPackageFormViewModel.swift */; };
12631263
CC2A08022862400100510C4B /* orders_3337_add_shipping.json in Resources */ = {isa = PBXBuildFile; fileRef = CC2A08012862400100510C4B /* orders_3337_add_shipping.json */; };
1264+
CC2A08042863206000510C4B /* AddFeeScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC2A08032863206000510C4B /* AddFeeScreen.swift */; };
1265+
CC2A08062863222500510C4B /* orders_3337_add_fee.json in Resources */ = {isa = PBXBuildFile; fileRef = CC2A08052863222500510C4B /* orders_3337_add_fee.json */; };
12641266
CC2E72F727B6BFB800A62872 /* ProductVariationFormatterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC2E72F627B6BFB800A62872 /* ProductVariationFormatterTests.swift */; };
12651267
CC440E1E2770C6AF0074C264 /* ProductInOrderViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC440E1D2770C6AF0074C264 /* ProductInOrderViewModel.swift */; };
12661268
CC4A4E962655273D00B75DCD /* ShippingLabelPaymentMethods.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC4A4E952655273D00B75DCD /* ShippingLabelPaymentMethods.swift */; };
@@ -3035,6 +3037,8 @@
30353037
CC254F3526C437AB005F3C82 /* ShippingLabelCustomPackageForm.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShippingLabelCustomPackageForm.swift; sourceTree = "<group>"; };
30363038
CC254F3726C43B52005F3C82 /* ShippingLabelCustomPackageFormViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShippingLabelCustomPackageFormViewModel.swift; sourceTree = "<group>"; };
30373039
CC2A08012862400100510C4B /* orders_3337_add_shipping.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = orders_3337_add_shipping.json; sourceTree = "<group>"; };
3040+
CC2A08032863206000510C4B /* AddFeeScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddFeeScreen.swift; sourceTree = "<group>"; };
3041+
CC2A08052863222500510C4B /* orders_3337_add_fee.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = orders_3337_add_fee.json; sourceTree = "<group>"; };
30383042
CC2E72F627B6BFB800A62872 /* ProductVariationFormatterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductVariationFormatterTests.swift; sourceTree = "<group>"; };
30393043
CC440E1D2770C6AF0074C264 /* ProductInOrderViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductInOrderViewModel.swift; sourceTree = "<group>"; };
30403044
CC4A4E952655273D00B75DCD /* ShippingLabelPaymentMethods.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShippingLabelPaymentMethods.swift; sourceTree = "<group>"; };
@@ -6910,6 +6914,7 @@
69106914
CCF27B33280EF69600B755E1 /* orders_3337_add_product.json */,
69116915
C0A37CB7282957EB00E0826D /* orders_3337_add_customer_details.json */,
69126916
CC2A08012862400100510C4B /* orders_3337_add_shipping.json */,
6917+
CC2A08052863222500510C4B /* orders_3337_add_fee.json */,
69136918
CCF27B39280EF98F00B755E1 /* orders_3337.json */,
69146919
800A5B9A2755E0B9009DE2CD /* orders_any.json */,
69156920
800A5B9F27562EE5009DE2CD /* orders_processing.json */,
@@ -8082,6 +8087,7 @@
80828087
CC1AB56727FC5821003DEF43 /* OrderStatusScreen.swift */,
80838088
C044961228058FE8003B3081 /* AddProductScreen.swift */,
80848089
CC71353A2862285300A28B42 /* AddShippingScreen.swift */,
8090+
CC2A08032863206000510C4B /* AddFeeScreen.swift */,
80858091
);
80868092
path = Orders;
80878093
sourceTree = "<group>";
@@ -8597,6 +8603,7 @@
85978603
800A5BC5275889ED009DE2CD /* reports_revenue_stats_day.json in Resources */,
85988604
800A5B972755BA02009DE2CD /* status.json in Resources */,
85998605
800A5BC8275889ED009DE2CD /* reports_revenue_stats_year.json in Resources */,
8606+
CC2A08062863222500510C4B /* orders_3337_add_fee.json in Resources */,
86008607
800A5BBC27586AE1009DE2CD /* products_reviews_6162.json in Resources */,
86018608
800A5B6127548F53009DE2CD /* sites_posts_password.json in Resources */,
86028609
800A5BB427586A0E009DE2CD /* products_reviews_6155.json in Resources */,
@@ -8781,6 +8788,7 @@
87818788
3F0CF3042704490A00EF3D71 /* PeriodStatsTable.swift in Sources */,
87828789
3F0CF3142704494A00EF3D71 /* TabNavComponent.swift in Sources */,
87838790
3F0CF3072704490A00EF3D71 /* LoginEmailScreen.swift in Sources */,
8791+
CC2A08042863206000510C4B /* AddFeeScreen.swift in Sources */,
87848792
3F0CF30D2704490A00EF3D71 /* LoginSiteAddressScreen.swift in Sources */,
87858793
80C3626B27704EE1005CEAD3 /* ProductDataStructs.swift in Sources */,
87868794
80C3627127745737005CEAD3 /* ReviewDataStructs.swift in Sources */,

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"shipping_total": "1.25",
2929
"shipping_tax": "0.00",
3030
"cart_tax": "0.00",
31-
"total": "111.25",
31+
"total": "113.59",
3232
"total_tax": "0.00",
3333
"customer_id": 0,
3434
"order_key": "abc123",
@@ -95,7 +95,17 @@
9595
"taxes": [],
9696
"meta_data": []
9797
}],
98-
"fee_lines": [],
98+
"fee_lines": [{
99+
"id": 1,
100+
"name": "Fee",
101+
"tax_class": "",
102+
"tax_status": "taxable",
103+
"amount": "2.34",
104+
"total": "2.34",
105+
"total_tax": "0.00",
106+
"taxes": [],
107+
"meta_data": []
108+
}],
99109
"coupon_lines": [],
100110
"refunds": [],
101111
"date_created_gmt": "{{#assign 'customformat'}}yyyy-MM-dd'T'HH:mm:ss{{/assign}}{{now format=customformat}}",
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
{
2+
"request": {
3+
"method": "POST",
4+
"urlPath": "/rest/v1.1/jetpack-blogs/161477129/rest-api/",
5+
"bodyPatterns": [
6+
{ "matches": ".*path=/wc/v3/orders/3337%26_method%3Dpost.*" },
7+
{ "contains": "%22product_id%22%3A2129" },
8+
{ "contains": "%22name%22%3A%22Fee%22" },
9+
{ "contains": "%22method_title%22%3A%22Flat%20Rate%22" },
10+
{ "contains": "%22first_name%22%3A%22Mira%22" }
11+
]
12+
},
13+
"response": {
14+
"status": 200,
15+
"jsonBody": {
16+
"data": {
17+
"id": 3337,
18+
"parent_id": 0,
19+
"status": "auto-draft",
20+
"currency": "USD",
21+
"version": "6.3.1",
22+
"prices_include_tax": true,
23+
"date_created": "{{#assign 'customformat'}}yyyy-MM-dd'T'HH:mm:ss{{/assign}}{{now format=customformat}}",
24+
"date_modified": "{{now offset='-10 minutes' format=customformat}}",
25+
"discount_total": "0.00",
26+
"discount_tax": "0.00",
27+
"shipping_total": "1.25",
28+
"shipping_tax": "0.00",
29+
"cart_tax": "0.00",
30+
"total": "113.59",
31+
"total_tax": "0.00",
32+
"customer_id": 0,
33+
"order_key": "abc123",
34+
"billing": {
35+
"first_name": "Mira",
36+
"last_name": "",
37+
"company": "",
38+
"address_1": "",
39+
"address_2": "",
40+
"city": "",
41+
"state": "",
42+
"postcode": "",
43+
"country": "",
44+
"email": "",
45+
"phone": ""
46+
},
47+
"shipping": {
48+
"first_name": "",
49+
"last_name": "",
50+
"company": "",
51+
"address_1": "",
52+
"address_2": "",
53+
"city": "",
54+
"state": "",
55+
"postcode": "",
56+
"country": "",
57+
"phone": ""
58+
},
59+
"payment_method": "",
60+
"payment_method_title": "",
61+
"transaction_id": "",
62+
"customer_ip_address": "",
63+
"customer_user_agent": "",
64+
"created_via": "rest-api",
65+
"customer_note": "",
66+
"date_completed": null,
67+
"date_paid": null,
68+
"cart_hash": "",
69+
"number": "3337",
70+
"meta_data": [],
71+
"line_items": [{
72+
"id": 1,
73+
"name": "Akoya Pearl shades",
74+
"product_id": 2129,
75+
"variation_id": 0,
76+
"quantity": 1,
77+
"tax_class": "",
78+
"subtotal": "110.00",
79+
"subtotal_tax": "0.00",
80+
"total": "110.00",
81+
"total_tax": "0.00",
82+
"taxes": [],
83+
"meta_data": [],
84+
"sku": "",
85+
"price": 110
86+
}],
87+
"tax_lines": [],
88+
"shipping_lines": [{
89+
"id": 1,
90+
"method_title": "Flat Rate",
91+
"method_id": "other",
92+
"total": "1.25",
93+
"total_tax": "0.00",
94+
"taxes": [],
95+
"meta_data": []
96+
}],
97+
"fee_lines": [{
98+
"id": 1,
99+
"name": "Fee",
100+
"tax_class": "",
101+
"tax_status": "taxable",
102+
"amount": "2.34",
103+
"total": "2.34",
104+
"total_tax": "0.00",
105+
"taxes": [],
106+
"meta_data": []
107+
}],
108+
"coupon_lines": [],
109+
"refunds": [],
110+
"date_created_gmt": "{{#assign 'customformat'}}yyyy-MM-dd'T'HH:mm:ss{{/assign}}{{now format=customformat}}",
111+
"date_modified_gmt": "{{now offset='-10 minutes' format=customformat}}",
112+
"date_completed_gmt": null,
113+
"date_paid_gmt": null,
114+
"currency_symbol": "$",
115+
"_links": {
116+
"self": [{
117+
"href": ""
118+
}],
119+
"collection": [{
120+
"href": ""
121+
}]
122+
}
123+
}
124+
}
125+
}
126+
}

WooCommerce/WooCommerceUITests/Tests/OrdersTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ final class OrdersTests: XCTestCase {
3434
.addProduct(byName: products[0].name)
3535
.addCustomerDetails(name: "Mira")
3636
.addShipping(amount: "1.25", name: "Flat Rate")
37+
.addFee(amount: "2.34")
3738
.createOrder()
3839
}
3940

0 commit comments

Comments
 (0)