Skip to content

Commit 51b1a71

Browse files
committed
add simple physical product ui test
1 parent 4a72b01 commit 51b1a71

File tree

11 files changed

+212
-110
lines changed

11 files changed

+212
-110
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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,15 @@ 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+
87+
return try SingleProductScreen()
88+
}
7889
}

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"].tap()
36+
app.cells["product-title"].typeText(productTitle)
37+
return self
38+
}
39+
40+
public func publishProduct() throws -> Self {
41+
app.buttons["publish-product-button"].tap()
42+
return self
43+
}
44+
45+
public func verifyNewProductScreenLoaded() {
46+
XCTAssertTrue(app.buttons["save-product-button"].exists)
47+
XCTAssertTrue(app.staticTexts["TIP"].exists)
48+
}
3349
}

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,7 @@
11531153
800A5BC7275889ED009DE2CD /* reports_revenue_stats_month.json in Resources */ = {isa = PBXBuildFile; fileRef = 800A5BC3275889EC009DE2CD /* reports_revenue_stats_month.json */; };
11541154
800A5BC8275889ED009DE2CD /* reports_revenue_stats_year.json in Resources */ = {isa = PBXBuildFile; fileRef = 800A5BC4275889EC009DE2CD /* reports_revenue_stats_year.json */; };
11551155
800A5BCB2759CE4B009DE2CD /* ProductsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 800A5BCA2759CE4B009DE2CD /* ProductsTests.swift */; };
1156+
806062F229432BB8006BB1F9 /* products_add_new.json in Resources */ = {isa = PBXBuildFile; fileRef = 806062F129432BB8006BB1F9 /* products_add_new.json */; };
11561157
80AD2CA22782B4EB00A63DE8 /* products_list_1.json in Resources */ = {isa = PBXBuildFile; fileRef = 80AD2CA12782B4EB00A63DE8 /* products_list_1.json */; };
11571158
80AD2CA427858BAB00A63DE8 /* StatsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80AD2CA327858BAB00A63DE8 /* StatsTests.swift */; };
11581159
80AD2CA627859B4400A63DE8 /* reports_leaderboards_stats_day.json in Resources */ = {isa = PBXBuildFile; fileRef = 80AD2CA527859B4400A63DE8 /* reports_leaderboards_stats_day.json */; };
@@ -3153,6 +3154,7 @@
31533154
800A5BC3275889EC009DE2CD /* reports_revenue_stats_month.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = reports_revenue_stats_month.json; sourceTree = "<group>"; };
31543155
800A5BC4275889EC009DE2CD /* reports_revenue_stats_year.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = reports_revenue_stats_year.json; sourceTree = "<group>"; };
31553156
800A5BCA2759CE4B009DE2CD /* ProductsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductsTests.swift; sourceTree = "<group>"; };
3157+
806062F129432BB8006BB1F9 /* products_add_new.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = products_add_new.json; sourceTree = "<group>"; };
31563158
80AD2CA12782B4EB00A63DE8 /* products_list_1.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = products_list_1.json; sourceTree = "<group>"; };
31573159
80AD2CA327858BAB00A63DE8 /* StatsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatsTests.swift; sourceTree = "<group>"; };
31583160
80AD2CA527859B4400A63DE8 /* reports_leaderboards_stats_day.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = reports_leaderboards_stats_day.json; sourceTree = "<group>"; };
@@ -7822,6 +7824,7 @@
78227824
80AD2CA12782B4EB00A63DE8 /* products_list_1.json */,
78237825
80B8D3442785A08900FE6E6B /* products_list_2.json */,
78247826
80B8D3482785A0A900FE6E6B /* products_list_3.json */,
7827+
806062F129432BB8006BB1F9 /* products_add_new.json */,
78257828
);
78267829
path = products;
78277830
sourceTree = "<group>";
@@ -9672,6 +9675,7 @@
96729675
800A5BC8275889ED009DE2CD /* reports_revenue_stats_year.json in Resources */,
96739676
CC2A08062863222500510C4B /* orders_3337_add_fee.json in Resources */,
96749677
800A5BBC27586AE1009DE2CD /* products_reviews_6162.json in Resources */,
9678+
806062F229432BB8006BB1F9 /* products_add_new.json in Resources */,
96759679
800A5B6127548F53009DE2CD /* sites_posts_password.json in Resources */,
96769680
800A5BB427586A0E009DE2CD /* products_reviews_6155.json in Resources */,
96779681
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/products/products.json

Lines changed: 0 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -18,113 +18,6 @@
1818
"status": 200,
1919
"jsonBody": {
2020
"data": [{
21-
"id": 2129,
22-
"name": "Akoya Pearl shades",
23-
"slug": "akoya-pearl-shades",
24-
"permalink": "https:\/\/automatticwidgets.wpcomstaging.com\/product\/akoya-pearl-shades\/",
25-
"date_created": "2020-01-28T09:53:36",
26-
"date_created_gmt": "2020-01-28T09:53:36",
27-
"date_modified": "2020-01-28T09:57:12",
28-
"date_modified_gmt": "2020-01-28T09:57:12",
29-
"type": "simple",
30-
"status": "publish",
31-
"featured": false,
32-
"catalog_visibility": "visible",
33-
"description": "",
34-
"short_description": "",
35-
"sku": "",
36-
"price": "110",
37-
"regular_price": "110",
38-
"sale_price": "",
39-
"date_on_sale_from": null,
40-
"date_on_sale_from_gmt": null,
41-
"date_on_sale_to": null,
42-
"date_on_sale_to_gmt": null,
43-
"on_sale": false,
44-
"purchasable": true,
45-
"total_sales": 5,
46-
"virtual": false,
47-
"downloadable": false,
48-
"downloads": [],
49-
"download_limit": -1,
50-
"download_expiry": -1,
51-
"external_url": "",
52-
"button_text": "",
53-
"tax_status": "taxable",
54-
"tax_class": "",
55-
"manage_stock": false,
56-
"stock_quantity": null,
57-
"backorders": "no",
58-
"backorders_allowed": false,
59-
"backordered": false,
60-
"low_stock_amount": null,
61-
"sold_individually": false,
62-
"weight": "",
63-
"dimensions": {
64-
"length": "",
65-
"width": "",
66-
"height": ""
67-
},
68-
"shipping_required": true,
69-
"shipping_taxable": true,
70-
"shipping_class": "",
71-
"shipping_class_id": 0,
72-
"reviews_allowed": false,
73-
"average_rating": "0.00",
74-
"rating_count": 0,
75-
"upsell_ids": [],
76-
"cross_sell_ids": [],
77-
"parent_id": 0,
78-
"purchase_note": "",
79-
"categories": [],
80-
"tags": [],
81-
"images": [{
82-
"id": 2127,
83-
"date_created": "2020-01-28T09:52:58",
84-
"date_created_gmt": "2020-01-28T09:52:58",
85-
"date_modified": "2020-01-28T09:52:58",
86-
"date_modified_gmt": "2020-01-28T09:52:58",
87-
"src": "https:\/\/i0.wp.com\/automatticwidgets.wpcomstaging.com\/wp-content\/uploads\/2020\/01\/Mask-Group-2.png?fit=200%2C201&ssl=1",
88-
"name": "Mask Group-2",
89-
"alt": ""
90-
}],
91-
"attributes": [],
92-
"default_attributes": [],
93-
"variations": [],
94-
"grouped_products": [],
95-
"menu_order": 0,
96-
"price_html": "<span class=\"woocommerce-Price-amount amount\"><bdi><span class=\"woocommerce-Price-currencySymbol\">&#36;<\/span>110.00<\/bdi><\/span>",
97-
"related_ids": [],
98-
"meta_data": [{
99-
"id": 2596,
100-
"key": "_product_addons",
101-
"value": []
102-
}, {
103-
"id": 2597,
104-
"key": "_product_addons_exclude_global",
105-
"value": "0"
106-
}, {
107-
"id": 2613,
108-
"key": "_wpas_done_all",
109-
"value": "1"
110-
}, {
111-
"id": 4051,
112-
"key": "_last_editor_used_jetpack",
113-
"value": "classic-editor"
114-
}],
115-
"stock_status": "instock",
116-
"jetpack_publicize_connections": [],
117-
"jetpack_likes_enabled": false,
118-
"jetpack_sharing_enabled": true,
119-
"_links": {
120-
"self": [{
121-
"href": "https:\/\/automatticwidgets.wpcomstaging.com\/wp-json\/wc\/v3\/products\/2129"
122-
}],
123-
"collection": [{
124-
"href": "https:\/\/automatticwidgets.wpcomstaging.com\/wp-json\/wc\/v3\/products"
125-
}]
126-
}
127-
}, {
12821
"id": 2130,
12922
"name": "Black Coral shades",
13023
"slug": "black-coral-shades",
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/products%26_method%3Dpost" },
7+
{ "contains": "name%22%3A%22Akoya%20Pearl%20shades" }
8+
]
9+
},
10+
"response": {
11+
"status": 200,
12+
"jsonBody": {
13+
"data": {
14+
"id": 2129,
15+
"name": "Akoya Pearl shades",
16+
"slug": "akoya-pearl-shades",
17+
"permalink": "https:\/\/automatticwidgets.wpcomstaging.com\/product\/akoya-pearl-shades\/",
18+
"date_created": "{{#assign 'customformat'}}yyyy-MM-dd'T'HH:mm:ss{{/assign}}{{now format=customformat}}",
19+
"date_created_gmt": "{{now format=customformat}}",
20+
"date_modified": "{{now format=customformat}}",
21+
"date_modified_gmt": "{{now format=customformat}}",
22+
"type": "simple",
23+
"status": "publish",
24+
"featured": false,
25+
"catalog_visibility": "visible",
26+
"description": "",
27+
"short_description": "",
28+
"sku": "",
29+
"price": "110",
30+
"regular_price": "110",
31+
"sale_price": "",
32+
"date_on_sale_from": null,
33+
"date_on_sale_from_gmt": null,
34+
"date_on_sale_to": null,
35+
"date_on_sale_to_gmt": null,
36+
"on_sale": false,
37+
"purchasable": true,
38+
"total_sales": 0,
39+
"virtual": false,
40+
"downloadable": false,
41+
"downloads": [],
42+
"download_limit": -1,
43+
"download_expiry": -1,
44+
"external_url": "",
45+
"button_text": "",
46+
"tax_status": "taxable",
47+
"tax_class": "",
48+
"manage_stock": false,
49+
"stock_quantity": null,
50+
"backorders": "no",
51+
"backorders_allowed": false,
52+
"backordered": false,
53+
"low_stock_amount": null,
54+
"sold_individually": false,
55+
"weight": "",
56+
"dimensions": {
57+
"length": "",
58+
"width": "",
59+
"height": ""
60+
},
61+
"shipping_required": true,
62+
"shipping_taxable": true,
63+
"shipping_class": "",
64+
"shipping_class_id": 0,
65+
"reviews_allowed": true,
66+
"average_rating": "0",
67+
"rating_count": 0,
68+
"upsell_ids": [],
69+
"cross_sell_ids": [],
70+
"parent_id": 0,
71+
"purchase_note": "",
72+
"categories": [],
73+
"tags": [],
74+
"images": [{
75+
"id": 2127,
76+
"date_created": "2020-01-28T09:52:58",
77+
"date_created_gmt": "2020-01-28T09:52:58",
78+
"date_modified": "2020-01-28T09:52:58",
79+
"date_modified_gmt": "2020-01-28T09:52:58",
80+
"src": "https:\/\/i0.wp.com\/automatticwidgets.wpcomstaging.com\/wp-content\/uploads\/2020\/01\/Mask-Group-2.png?fit=200%2C201&ssl=1",
81+
"name": "Mask Group-2",
82+
"alt": ""
83+
}],
84+
"attributes": [],
85+
"default_attributes": [],
86+
"variations": [],
87+
"grouped_products": [],
88+
"menu_order": 0,
89+
"price_html": "",
90+
"related_ids": [],
91+
"meta_data": [{
92+
"id": 2596,
93+
"key": "_product_addons",
94+
"value": []
95+
}, {
96+
"id": 2597,
97+
"key": "_product_addons_exclude_global",
98+
"value": "0"
99+
}, {
100+
"id": 2613,
101+
"key": "_wpas_done_all",
102+
"value": "1"
103+
}, {
104+
"id": 4051,
105+
"key": "_last_editor_used_jetpack",
106+
"value": "classic-editor"
107+
}],
108+
"stock_status": "instock",
109+
"has_options": false,
110+
"jetpack_likes_enabled": true,
111+
"_links": {
112+
"self": [
113+
{
114+
"href": "https:\/\/automatticwidgets.wpcomstaging.com\/wp-json\/wc\/v3\/products\/2129"
115+
}
116+
],
117+
"collection": [
118+
{
119+
"href": "https:\/\/automatticwidgets.wpcomstaging.com\/wp-json\/wc\/v3\/products"
120+
}
121+
]
122+
}
123+
}
124+
}
125+
}
126+
}

WooCommerce/WooCommerceUITests/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ The following flows are covered/planned to be covered by UI tests. Tests that ar
4343
- [x] Order Creation flow can be dismissed
4444
4. Products
4545
- [x] Products list and single product screens load
46-
- [ ] Add new product - Simple physical product
46+
- [x] Add new product - Simple physical product
4747
- [ ] Add new product - Simple virtual product
4848
- [ ] Add new product - Variable product
4949
- [ ] Add new product - Grouped product

0 commit comments

Comments
 (0)