Skip to content

Commit 0dfcac1

Browse files
authored
Merge pull request #8380 from woocommerce/add-product-ui-test
[UI Test] - Add simple physical product UI Test
2 parents 262b573 + 718db71 commit 0dfcac1

File tree

16 files changed

+239
-134
lines changed

16 files changed

+239
-134
lines changed

WooCommerce/Classes/ViewRelated/Products/Edit Product/ProductFormTableViewDataSource.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ private extension ProductFormTableViewDataSource {
147147
}
148148

149149
cell.accessoryType = .none
150+
cell.accessibilityIdentifier = "product-title"
150151

151152
let placeholder = NSLocalizedString("Title", comment: "Placeholder in the Product Title row on Product form screen.")
152153

@@ -193,6 +194,7 @@ private extension ProductFormTableViewDataSource {
193194
cell.textLabel?.text = placeholder
194195
cell.textLabel?.applyBodyStyle()
195196
cell.textLabel?.textColor = .textSubtle
197+
cell.accessibilityIdentifier = "product-description"
196198
}
197199
if isEditable {
198200
cell.accessoryType = .disclosureIndicator

WooCommerce/Classes/ViewRelated/Products/Edit Product/ProductFormViewController.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -970,11 +970,21 @@ private extension ProductFormViewController {
970970
}
971971

972972
func createPublishBarButtonItem() -> UIBarButtonItem {
973-
return UIBarButtonItem(title: Localization.publishTitle, style: .done, target: self, action: #selector(publishProduct))
973+
let publishButton = UIBarButtonItem(title: Localization.publishTitle,
974+
style: .done,
975+
target: self,
976+
action: #selector(publishProduct))
977+
publishButton.accessibilityIdentifier = "publish-product-button"
978+
return publishButton
974979
}
975980

976981
func createSaveBarButtonItem() -> UIBarButtonItem {
977-
return UIBarButtonItem(title: Localization.saveTitle, style: .done, target: self, action: #selector(saveProductAndLogEvent))
982+
let saveButton = UIBarButtonItem(title: Localization.saveTitle,
983+
style: .done,
984+
target: self,
985+
action: #selector(saveProductAndLogEvent))
986+
saveButton.accessibilityIdentifier = "save-product-button"
987+
return saveButton
978988
}
979989

980990
func createPreviewBarButtonItem() -> UIBarButtonItem {

WooCommerce/UITestsFoundation/ProductDataStructs.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/// Mocks for products on product list
12
public struct ProductMock: Codable {
23
public let response: ProductResponseData
34
}
@@ -11,6 +12,20 @@ public struct ProductBodyData: Codable {
1112
public let data: [ProductData]
1213
}
1314

15+
/// Mocks for a new product
16+
public struct NewProductMock: Codable {
17+
public let response: NewProductResponseData
18+
}
19+
20+
public struct NewProductResponseData: Codable {
21+
public let status: Int
22+
public let jsonBody: NewProductBodyData
23+
}
24+
25+
public struct NewProductBodyData: Codable {
26+
public let data: ProductData
27+
}
28+
1429
public struct ProductData: Codable {
1530
public let id: Int
1631
public let name: String

WooCommerce/UITestsFoundation/Screens/Products/ProductsScreen.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,14 @@ public final class ProductsScreen: ScreenObject {
7575
XCTAssertTrue(isLoaded)
7676
return self
7777
}
78+
79+
public func tapAddProduct() throws -> Self {
80+
app.buttons["product-add-button"].tap()
81+
return self
82+
}
83+
84+
public func selectProductType(productType: String) throws -> SingleProductScreen {
85+
app.staticTexts[productType].tap()
86+
return try SingleProductScreen()
87+
}
7888
}

WooCommerce/UITestsFoundation/Screens/Products/SingleProductScreen.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,20 @@ public final class SingleProductScreen: ScreenObject {
3030

3131
return self
3232
}
33+
34+
public func addProductTitle(productTitle: String) throws -> Self {
35+
app.cells["product-title"].enterText(text: productTitle)
36+
return self
37+
}
38+
39+
public func publishProduct() throws -> Self {
40+
app.buttons["publish-product-button"].tap()
41+
return self
42+
}
43+
44+
public func verifyNewProductScreenLoaded(productName: String) {
45+
XCTAssertTrue(app.buttons["save-product-button"].exists)
46+
XCTAssertTrue(app.staticTexts["TIP"].exists)
47+
XCTAssertTrue(app.textViews[productName].exists)
48+
}
3349
}

WooCommerce/UITestsFoundation/XCTest+Extensions.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ extension XCUIElement {
1919
*/
2020
func clearAndEnterText(text: String) -> Void {
2121
clearTextIfNeeded()
22+
enterText(text: text)
23+
}
24+
25+
func enterText(text: String) -> Void {
2226
self.tap()
2327
self.typeText(text)
2428
}

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,7 @@
11571157
800A5BC7275889ED009DE2CD /* reports_revenue_stats_month.json in Resources */ = {isa = PBXBuildFile; fileRef = 800A5BC3275889EC009DE2CD /* reports_revenue_stats_month.json */; };
11581158
800A5BC8275889ED009DE2CD /* reports_revenue_stats_year.json in Resources */ = {isa = PBXBuildFile; fileRef = 800A5BC4275889EC009DE2CD /* reports_revenue_stats_year.json */; };
11591159
800A5BCB2759CE4B009DE2CD /* ProductsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 800A5BCA2759CE4B009DE2CD /* ProductsTests.swift */; };
1160+
806062F229432BB8006BB1F9 /* products_add_new.json in Resources */ = {isa = PBXBuildFile; fileRef = 806062F129432BB8006BB1F9 /* products_add_new.json */; };
11601161
80AD2CA22782B4EB00A63DE8 /* products_list_1.json in Resources */ = {isa = PBXBuildFile; fileRef = 80AD2CA12782B4EB00A63DE8 /* products_list_1.json */; };
11611162
80AD2CA427858BAB00A63DE8 /* StatsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80AD2CA327858BAB00A63DE8 /* StatsTests.swift */; };
11621163
80AD2CA627859B4400A63DE8 /* reports_leaderboards_stats_day.json in Resources */ = {isa = PBXBuildFile; fileRef = 80AD2CA527859B4400A63DE8 /* reports_leaderboards_stats_day.json */; };
@@ -3163,6 +3164,7 @@
31633164
800A5BC3275889EC009DE2CD /* reports_revenue_stats_month.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = reports_revenue_stats_month.json; sourceTree = "<group>"; };
31643165
800A5BC4275889EC009DE2CD /* reports_revenue_stats_year.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = reports_revenue_stats_year.json; sourceTree = "<group>"; };
31653166
800A5BCA2759CE4B009DE2CD /* ProductsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductsTests.swift; sourceTree = "<group>"; };
3167+
806062F129432BB8006BB1F9 /* products_add_new.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = products_add_new.json; sourceTree = "<group>"; };
31663168
80AD2CA12782B4EB00A63DE8 /* products_list_1.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = products_list_1.json; sourceTree = "<group>"; };
31673169
80AD2CA327858BAB00A63DE8 /* StatsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatsTests.swift; sourceTree = "<group>"; };
31683170
80AD2CA527859B4400A63DE8 /* reports_leaderboards_stats_day.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = reports_leaderboards_stats_day.json; sourceTree = "<group>"; };
@@ -7846,6 +7848,7 @@
78467848
80AD2CA12782B4EB00A63DE8 /* products_list_1.json */,
78477849
80B8D3442785A08900FE6E6B /* products_list_2.json */,
78487850
80B8D3482785A0A900FE6E6B /* products_list_3.json */,
7851+
806062F129432BB8006BB1F9 /* products_add_new.json */,
78497852
);
78507853
path = products;
78517854
sourceTree = "<group>";
@@ -9698,6 +9701,7 @@
96989701
800A5BC8275889ED009DE2CD /* reports_revenue_stats_year.json in Resources */,
96999702
CC2A08062863222500510C4B /* orders_3337_add_fee.json in Resources */,
97009703
800A5BBC27586AE1009DE2CD /* products_reviews_6162.json in Resources */,
9704+
806062F229432BB8006BB1F9 /* products_add_new.json in Resources */,
97019705
800A5B6127548F53009DE2CD /* sites_posts_password.json in Resources */,
97029706
800A5BB427586A0E009DE2CD /* products_reviews_6155.json in Resources */,
97039707
800A5B5F27548F31009DE2CD /* site_info_wordpress_com.json in Resources */,

WooCommerce/WooCommerceUITests/Flows/MockDataReader.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ class GetMocks {
3939
return updatedData
4040
}
4141

42+
static func readNewProductData() throws -> ProductData {
43+
let originalData = try JSONDecoder().decode(NewProductMock.self, from: self.getMockData(test: ProductsTests.self, filename: "products_add_new"))
44+
45+
return try XCTUnwrap(originalData.response.jsonBody.data)
46+
}
47+
4248
static func readReviewsData() throws -> [ReviewData] {
4349
let originalData = try JSONDecoder().decode(ReviewMock.self, from: self.getMockData(test: ReviewsTests.self, filename: "products_reviews_all"))
4450
var updatedData = originalData.response.jsonBody.data

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"urlPath": "/rest/v1.1/jetpack-blogs/161477129/rest-api/",
55
"bodyPatterns": [
66
{ "matches": ".*path=/wc/v3/orders/3337%26_method%3Dpost.*" },
7-
{ "contains": "%22product_id%22%3A2129" },
7+
{ "contains": "%22product_id%22%3A2130" },
88
{ "contains": "%22fee_lines%22%3A%5B%5D" },
99
{ "contains": "%22shipping_lines%22%3A%5B%5D" },
1010
{ "contains": "%22first_name%22%3A%22Mira%22" }
@@ -70,19 +70,19 @@
7070
"meta_data": [],
7171
"line_items": [{
7272
"id": 1,
73-
"name": "Akoya Pearl shades",
74-
"product_id": 2129,
73+
"name": "Black Coral shades",
74+
"product_id": 2130,
7575
"variation_id": 0,
7676
"quantity": 1,
7777
"tax_class": "",
78-
"subtotal": "110.00",
78+
"subtotal": "150.00",
7979
"subtotal_tax": "0.00",
80-
"total": "110.00",
80+
"total": "150.00",
8181
"total_tax": "0.00",
8282
"taxes": [],
8383
"meta_data": [],
8484
"sku": "",
85-
"price": 110
85+
"price": 150
8686
}],
8787
"tax_lines": [],
8888
"shipping_lines": [],

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"urlPath": "/rest/v1.1/jetpack-blogs/161477129/rest-api/",
55
"bodyPatterns": [
66
{ "matches": ".*path=/wc/v3/orders/3337%26_method%3Dpost.*" },
7-
{ "contains": "%22product_id%22%3A2129" },
7+
{ "contains": "%22product_id%22%3A2130" },
88
{ "contains": "%22name%22%3A%22Fee%22" },
99
{ "contains": "%22method_title%22%3A%22Flat%20Rate%22" },
1010
{ "contains": "%22first_name%22%3A%22Mira%22" }
@@ -70,19 +70,19 @@
7070
"meta_data": [],
7171
"line_items": [{
7272
"id": 1,
73-
"name": "Akoya Pearl shades",
74-
"product_id": 2129,
73+
"name": "Black Coral shades",
74+
"product_id": 2130,
7575
"variation_id": 0,
7676
"quantity": 1,
7777
"tax_class": "",
78-
"subtotal": "110.00",
78+
"subtotal": "150.00",
7979
"subtotal_tax": "0.00",
80-
"total": "110.00",
80+
"total": "150.00",
8181
"total_tax": "0.00",
8282
"taxes": [],
8383
"meta_data": [],
8484
"sku": "",
85-
"price": 110
85+
"price": 150
8686
}],
8787
"tax_lines": [],
8888
"shipping_lines": [{

0 commit comments

Comments
 (0)