Skip to content

Commit 4a207f9

Browse files
authored
Merge pull request #7128 from woocommerce/issue/6524-orders-test-with-note
[Order Creation] Expand new order UI test to include adding customer note
2 parents 52d0509 + 824173d commit 4a207f9

File tree

10 files changed

+118
-11
lines changed

10 files changed

+118
-11
lines changed

WooCommerce/Classes/ViewRelated/Orders/Order Creation/CustomerNoteSection/CustomerNoteSection.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ private struct CustomerNoteSectionContent: View {
8383
}
8484
.buttonStyle(PlusButtonStyle())
8585
.padding([.leading, .bottom, .trailing])
86+
.accessibilityIdentifier("add-customer-note-button")
8687
}
8788
}
8889

WooCommerce/Classes/ViewRelated/Orders/Order Details/Order Notes Section/Customer Note/EditCustomerNote.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ struct EditCustomerNote<ViewModel: EditCustomerNoteViewModelProtocol>: View {
5454
.padding()
5555
.navigationTitle(Localization.title)
5656
.navigationBarTitleDisplayMode(.inline)
57+
.accessibilityIdentifier("edit-note-text-editor")
5758
.toolbar {
5859
ToolbarItem(placement: .cancellationAction) {
5960
Button(Localization.cancel, action: {
@@ -63,6 +64,7 @@ struct EditCustomerNote<ViewModel: EditCustomerNoteViewModelProtocol>: View {
6364
}
6465
ToolbarItem(placement: .confirmationAction) {
6566
navigationBarTrailingItem()
67+
.accessibilityIdentifier("edit-note-done-button")
6668
}
6769
}
6870
}

WooCommerce/UITestsFoundation/OrderDataStructs.swift

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,41 @@
1+
/// Mock for a list of Orders
2+
public struct OrdersMock: Codable {
3+
public let response: OrdersResponseData
4+
}
5+
6+
/// Mocks for a single Order
17
public struct OrderMock: Codable {
28
public let response: OrderResponseData
39
}
410

11+
public struct OrdersResponseData: Codable {
12+
public let status: Int
13+
public let jsonBody: OrdersBodyData
14+
}
15+
516
public struct OrderResponseData: Codable {
617
public let status: Int
718
public let jsonBody: OrderBodyData
819
}
920

10-
public struct OrderBodyData: Codable {
21+
public struct OrdersBodyData: Codable {
1122
public let data: [OrderData]
1223
}
1324

25+
public struct OrderBodyData: Codable {
26+
public let data: OrderData
27+
}
28+
1429
public struct OrderData: Codable {
1530
public let id: Int
1631
public let number: String
1732
public let status: String
1833
public var total: String
1934
public let line_items: [LineItems]
2035
public let billing: BillingInformation
36+
public let shipping_lines: [ShippingLine]
37+
public let fee_lines: [FeeLine]
38+
public let customer_note: String
2139
}
2240

2341
public struct LineItems: Codable {
@@ -29,3 +47,12 @@ public struct BillingInformation: Codable {
2947
public let first_name: String
3048
public let last_name: String
3149
}
50+
51+
public struct ShippingLine: Codable {
52+
public let method_title: String
53+
public let total: String
54+
}
55+
56+
public struct FeeLine: Codable {
57+
public let amount: String
58+
}
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 CustomerNoteScreen: ScreenObject {
5+
6+
private let noteTextEditorGetter: (XCUIApplication) -> XCUIElement = {
7+
$0.textViews["edit-note-text-editor"]
8+
}
9+
10+
private let doneButtonGetter: (XCUIApplication) -> XCUIElement = {
11+
$0.buttons["edit-note-done-button"]
12+
}
13+
14+
private var noteTextEditor: XCUIElement { noteTextEditorGetter(app) }
15+
16+
private var doneButton: XCUIElement { doneButtonGetter(app) }
17+
18+
init(app: XCUIApplication = XCUIApplication()) throws {
19+
try super.init(
20+
expectedElementGetters: [ noteTextEditorGetter ],
21+
app: app
22+
)
23+
}
24+
25+
/// Enters a customer note.
26+
/// - Parameter text: Text to enter as the customer note.
27+
/// - Returns: Customer Note screen object.
28+
@discardableResult
29+
public func enterNote(_ text: String) throws -> Self {
30+
noteTextEditor.typeText(text)
31+
return self
32+
}
33+
34+
/// Confirms entered note and closes Customer Note screen.
35+
/// - Returns: New Order screen object.
36+
@discardableResult
37+
public func confirmNote() throws -> NewOrderScreen {
38+
doneButton.tap()
39+
return try NewOrderScreen()
40+
}
41+
}

WooCommerce/UITestsFoundation/Screens/Orders/NewOrderScreen.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ public final class NewOrderScreen: ScreenObject {
3131
$0.buttons["add-fee-button"]
3232
}
3333

34+
private let addNoteButtonGetter: (XCUIApplication) -> XCUIElement = {
35+
$0.buttons["add-customer-note-button"]
36+
}
37+
3438
private var createButton: XCUIElement { createButtonGetter(app) }
3539

3640
/// Cancel button in the Navigation bar.
@@ -57,6 +61,10 @@ public final class NewOrderScreen: ScreenObject {
5761
///
5862
private var addFeeButton: XCUIElement { addFeeButtonGetter(app) }
5963

64+
/// Add Note button in the Customer Note section.
65+
///
66+
private var addNoteButton: XCUIElement { addNoteButtonGetter(app) }
67+
6068
public init(app: XCUIApplication = XCUIApplication()) throws {
6169
try super.init(
6270
expectedElementGetters: [ createButtonGetter ],
@@ -106,6 +114,14 @@ public final class NewOrderScreen: ScreenObject {
106114
return try AddFeeScreen()
107115
}
108116

117+
/// Opens the Customer Note screen.
118+
/// - Returns: Customer Note screen object.
119+
@discardableResult
120+
public func openCustomerNoteScreen() throws -> CustomerNoteScreen {
121+
addNoteButton.tap()
122+
return try CustomerNoteScreen()
123+
}
124+
109125
// MARK: - High-level Order Creation actions
110126

111127
/// Creates a remote order with all of the entered order data.
@@ -161,6 +177,15 @@ public final class NewOrderScreen: ScreenObject {
161177
.confirmFee()
162178
}
163179

180+
/// Adds a note on the Customer Note screen.
181+
/// - Parameter text: Text to enter as the customer note.
182+
/// - Returns: New Order screen object.
183+
public func addCustomerNote(_ text: String) throws -> NewOrderScreen {
184+
return try openCustomerNoteScreen()
185+
.enterNote(text)
186+
.confirmNote()
187+
}
188+
164189
/// Cancels Order Creation process
165190
/// - Returns: Orders Screen object.
166191
@discardableResult

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,7 @@
12631263
CC2A08022862400100510C4B /* orders_3337_add_shipping.json in Resources */ = {isa = PBXBuildFile; fileRef = CC2A08012862400100510C4B /* orders_3337_add_shipping.json */; };
12641264
CC2A08042863206000510C4B /* AddFeeScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC2A08032863206000510C4B /* AddFeeScreen.swift */; };
12651265
CC2A08062863222500510C4B /* orders_3337_add_fee.json in Resources */ = {isa = PBXBuildFile; fileRef = CC2A08052863222500510C4B /* orders_3337_add_fee.json */; };
1266+
CC2A0808286337A300510C4B /* CustomerNoteScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC2A0807286337A300510C4B /* CustomerNoteScreen.swift */; };
12661267
CC2E72F727B6BFB800A62872 /* ProductVariationFormatterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC2E72F627B6BFB800A62872 /* ProductVariationFormatterTests.swift */; };
12671268
CC440E1E2770C6AF0074C264 /* ProductInOrderViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC440E1D2770C6AF0074C264 /* ProductInOrderViewModel.swift */; };
12681269
CC4A4E962655273D00B75DCD /* ShippingLabelPaymentMethods.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC4A4E952655273D00B75DCD /* ShippingLabelPaymentMethods.swift */; };
@@ -3039,6 +3040,7 @@
30393040
CC2A08012862400100510C4B /* orders_3337_add_shipping.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = orders_3337_add_shipping.json; sourceTree = "<group>"; };
30403041
CC2A08032863206000510C4B /* AddFeeScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddFeeScreen.swift; sourceTree = "<group>"; };
30413042
CC2A08052863222500510C4B /* orders_3337_add_fee.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = orders_3337_add_fee.json; sourceTree = "<group>"; };
3043+
CC2A0807286337A300510C4B /* CustomerNoteScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomerNoteScreen.swift; sourceTree = "<group>"; };
30423044
CC2E72F627B6BFB800A62872 /* ProductVariationFormatterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductVariationFormatterTests.swift; sourceTree = "<group>"; };
30433045
CC440E1D2770C6AF0074C264 /* ProductInOrderViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductInOrderViewModel.swift; sourceTree = "<group>"; };
30443046
CC4A4E952655273D00B75DCD /* ShippingLabelPaymentMethods.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShippingLabelPaymentMethods.swift; sourceTree = "<group>"; };
@@ -8088,6 +8090,7 @@
80888090
C044961228058FE8003B3081 /* AddProductScreen.swift */,
80898091
CC71353A2862285300A28B42 /* AddShippingScreen.swift */,
80908092
CC2A08032863206000510C4B /* AddFeeScreen.swift */,
8093+
CC2A0807286337A300510C4B /* CustomerNoteScreen.swift */,
80918094
);
80928095
path = Orders;
80938096
sourceTree = "<group>";
@@ -8776,6 +8779,7 @@
87768779
3F0CF30F2704490A00EF3D71 /* SingleProductScreen.swift in Sources */,
87778780
3F0CF30C2704490A00EF3D71 /* LoginPasswordScreen.swift in Sources */,
87788781
C02747102822673800985EAE /* CustomerDetailsScreen.swift in Sources */,
8782+
CC2A0808286337A300510C4B /* CustomerNoteScreen.swift in Sources */,
87798783
3F0CF30E2704490A00EF3D71 /* PasswordScreen.swift in Sources */,
87808784
3F0CF3092704490A00EF3D71 /* BetaFeaturesScreen.swift in Sources */,
87818785
80B8D34C278E8A0C00FE6E6B /* MenuScreen.swift in Sources */,

WooCommerce/WooCommerceUITests/Flows/MockDataReader.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class GetMocks {
5353
}
5454

5555
static func readOrdersData() throws -> [OrderData] {
56-
let originalData = try JSONDecoder().decode(OrderMock.self, from: self.getMockData(test: OrdersTests.self, filename: "orders_any"))
56+
let originalData = try JSONDecoder().decode(OrdersMock.self, from: self.getMockData(test: OrdersTests.self, filename: "orders_any"))
5757
var updatedData = originalData.response.jsonBody.data
5858

5959
for index in 0..<updatedData.count {
@@ -66,5 +66,10 @@ class GetMocks {
6666
}
6767

6868
return updatedData
69-
}
69+
}
70+
71+
static func readNewOrderData() throws -> OrderData {
72+
let originalData = try JSONDecoder().decode(OrderMock.self, from: self.getMockData(test: OrdersTests.self, filename: "orders_3337"))
73+
return try XCTUnwrap(originalData.response.jsonBody.data)
74+
}
7075
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"customer_ip_address": "",
6464
"customer_user_agent": "",
6565
"created_via": "rest-api",
66-
"customer_note": "",
66+
"customer_note": "Adipiscing Ipsum Amet Ipsum Amet",
6767
"date_completed": null,
6868
"date_paid": null,
6969
"cart_hash": "",

WooCommerce/WooCommerceUITests/Tests/OrdersTests.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@ final class OrdersTests: XCTestCase {
2727

2828
func test_create_new_order() throws {
2929
let products = try GetMocks.readProductsData()
30+
let order = try GetMocks.readNewOrderData()
3031

3132
try TabNavComponent().goToOrdersScreen()
3233
.startOrderCreation()
3334
.editOrderStatus()
3435
.addProduct(byName: products[0].name)
35-
.addCustomerDetails(name: "Mira")
36-
.addShipping(amount: "1.25", name: "Flat Rate")
37-
.addFee(amount: "2.34")
36+
.addCustomerDetails(name: order.billing.first_name)
37+
.addShipping(amount: order.shipping_lines[0].total, name: order.shipping_lines[0].method_title)
38+
.addFee(amount: order.fee_lines[0].amount)
39+
.addCustomerNote(order.customer_note)
3840
.createOrder()
3941
}
4042

docs/UI-TESTS.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ The following flows are covered/planned to be covered by UI tests. Tests that ar
2626
- [ ] Update order status
2727
- [ ] Issue refund
2828
- [ ] Add shipping details
29-
- [ ] Create a new order:
29+
- [x] Create a new order:
3030
- [x] With a selected order status
3131
- [x] With a product
3232
- [x] With customer details
33-
- [ ] With shipping
34-
- [ ] With a fee
35-
- [ ] With a customer note
33+
- [x] With shipping
34+
- [x] With a fee
35+
- [x] With a customer note
3636
- [x] Order Creation flow can be dismissed
3737
4. [Products](../WooCommerce/WooCommerceUITests/Tests/ProductsTests.swift)
3838
- [x] Products list and single product screens load

0 commit comments

Comments
 (0)