Skip to content

Commit c2bb7fe

Browse files
authored
Merge pull request #8407 from woocommerce/add-virtual-product-ui-test
[UI Test] - Add validation on new product screen and new add product tests
2 parents dd6a894 + c9a64bc commit c2bb7fe

File tree

7 files changed

+59
-18
lines changed

7 files changed

+59
-18
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ private extension ProductFormTableViewDataSource {
271271
ratingCount: ratingCount,
272272
averageRating: averageRating)
273273
cell.accessoryType = .disclosureIndicator
274+
cell.accessibilityIdentifier = "product-review-cell"
274275
}
275276

276277
func configureSettingsRowWithASwitch(cell: UITableViewCell, viewModel: ProductFormSection.SettingsRow.SwitchableViewModel) {

WooCommerce/UITestsFoundation/Screens/Products/ProductsScreen.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ public final class ProductsScreen: ScreenObject {
8282
}
8383

8484
public func selectProductType(productType: String) throws -> SingleProductScreen {
85-
app.staticTexts[productType].tap()
85+
let productTypeLabel = NSPredicate(format: "label CONTAINS[c] %@", productType)
86+
app.staticTexts.containing(productTypeLabel).firstMatch.tap()
8687
return try SingleProductScreen()
8788
}
8889
}

WooCommerce/UITestsFoundation/Screens/Products/SingleProductScreen.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,29 @@ public final class SingleProductScreen: ScreenObject {
4646
XCTAssertTrue(app.staticTexts["TIP"].exists)
4747
XCTAssertTrue(app.textViews[productName].exists)
4848
}
49+
50+
public func verifyProductTypeScreenLoaded(productType: String) throws -> Self {
51+
let addPriceLabel = NSPredicate(format: "label == 'Add Price'")
52+
let inventoryLabel = NSPredicate(format: "label == 'Inventory'")
53+
let productTypeLabel = NSPredicate(format: "label ==[c] '\(productType)'")
54+
let addVariationLabel = NSPredicate(format: "label == 'Add variations'")
55+
56+
// the common fields on add product screen
57+
XCTAssertTrue(app.cells["product-review-cell"].exists)
58+
XCTAssertTrue(app.staticTexts.containing(productTypeLabel).firstMatch.exists)
59+
60+
// different product types displays different fields on add product screen
61+
// this is to validate that the correct screens are displayed
62+
switch productType {
63+
case "physical", "virtual":
64+
XCTAssertTrue(app.staticTexts.containing(addPriceLabel).firstMatch.exists)
65+
XCTAssertTrue(app.staticTexts.containing(inventoryLabel).firstMatch.exists)
66+
case "variable":
67+
XCTAssertTrue(app.staticTexts.containing(addVariationLabel).firstMatch.exists)
68+
XCTAssertTrue(app.staticTexts.containing(inventoryLabel).firstMatch.exists)
69+
default:
70+
fatalError("Product Type \(productType) doesn't exist!")
71+
}
72+
return self
73+
}
4974
}

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,7 @@
11351135
7E7C5F872719A93C00315B61 /* ProductCategoryListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E7C5F812719A93C00315B61 /* ProductCategoryListViewController.swift */; };
11361136
7E7C5F8B2719AEDA00315B61 /* EditProductCategoryListViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E7C5F8A2719AEDA00315B61 /* EditProductCategoryListViewModelTests.swift */; };
11371137
7E7C5F8F2719BA7300315B61 /* ProductCategoryCellViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E7C5F8E2719BA7300315B61 /* ProductCategoryCellViewModel.swift */; };
1138+
80089F182949B92D0078C671 /* ProductFlow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80089F172949B92D0078C671 /* ProductFlow.swift */; };
11381139
800A5B58275483D6009DE2CD /* OrdersTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 800A5B57275483D6009DE2CD /* OrdersTests.swift */; };
11391140
800A5B5F27548F31009DE2CD /* site_info_wordpress_com.json in Resources */ = {isa = PBXBuildFile; fileRef = 800A5B5E27548F31009DE2CD /* site_info_wordpress_com.json */; };
11401141
800A5B6127548F53009DE2CD /* sites_posts_password.json in Resources */ = {isa = PBXBuildFile; fileRef = 800A5B6027548F53009DE2CD /* sites_posts_password.json */; };
@@ -3149,6 +3150,7 @@
31493150
7E7C5F812719A93C00315B61 /* ProductCategoryListViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProductCategoryListViewController.swift; sourceTree = "<group>"; };
31503151
7E7C5F8A2719AEDA00315B61 /* EditProductCategoryListViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditProductCategoryListViewModelTests.swift; sourceTree = "<group>"; };
31513152
7E7C5F8E2719BA7300315B61 /* ProductCategoryCellViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProductCategoryCellViewModel.swift; sourceTree = "<group>"; };
3153+
80089F172949B92D0078C671 /* ProductFlow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductFlow.swift; sourceTree = "<group>"; };
31523154
800A5B57275483D6009DE2CD /* OrdersTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrdersTests.swift; sourceTree = "<group>"; };
31533155
800A5B5E27548F31009DE2CD /* site_info_wordpress_com.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = site_info_wordpress_com.json; sourceTree = "<group>"; };
31543156
800A5B6027548F53009DE2CD /* sites_posts_password.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = sites_posts_password.json; sourceTree = "<group>"; };
@@ -6823,6 +6825,7 @@
68236825
children = (
68246826
80E6FC742763579D0086CD67 /* MockDataReader.swift */,
68256827
800A5B9D275623FC009DE2CD /* LoginFlow.swift */,
6828+
80089F172949B92D0078C671 /* ProductFlow.swift */,
68266829
);
68276830
path = Flows;
68286831
sourceTree = "<group>";
@@ -11574,6 +11577,7 @@
1157411577
80C3626F277453E8005CEAD3 /* ReviewsTests.swift in Sources */,
1157511578
80E6FC79276C3FD60086CD67 /* MockDataReader.swift in Sources */,
1157611579
CCDC49CD23FFFFF4003166BA /* LoginTests.swift in Sources */,
11580+
80089F182949B92D0078C671 /* ProductFlow.swift in Sources */,
1157711581
800A5B58275483D6009DE2CD /* OrdersTests.swift in Sources */,
1157811582
80AD2CA427858BAB00A63DE8 /* StatsTests.swift in Sources */,
1157911583
800A5BCB2759CE4B009DE2CD /* ProductsTests.swift in Sources */,
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import UITestsFoundation
2+
import XCTest
3+
4+
class ProductFlow {
5+
6+
static func addAndVerifyNewProduct(productType: String) throws {
7+
let product = try GetMocks.readNewProductData()
8+
9+
try TabNavComponent().goToProductsScreen()
10+
.tapAddProduct()
11+
.selectProductType(productType: productType)
12+
.verifyProductTypeScreenLoaded(productType: productType)
13+
.addProductTitle(productTitle: product.name)
14+
.publishProduct()
15+
.verifyNewProductScreenLoaded(productName: product.name)
16+
}
17+
}

WooCommerce/WooCommerceUITests/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ The following flows are covered/planned to be covered by UI tests. Tests that ar
4444
4. Products
4545
- [x] Products list and single product screens load
4646
- [x] Add new product - Simple physical product
47-
- [ ] Add new product - Simple virtual product
48-
- [ ] Add new product - Variable product
47+
- [x] Add new product - Simple virtual product
48+
- [x] Add new product - Variable product
4949
- [ ] Add new product - Grouped product
5050
- [ ] Add new product - External product
5151
- [ ] Search for product

WooCommerce/WooCommerceUITests/Tests/ProductsTests.swift

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@ import XCTest
33

44
final class ProductsTests: XCTestCase {
55

6-
let productTypes = [
7-
"physical": "Simple physical product",
8-
"virtual": "Simple virtual product",
9-
"variable": "Variable product",
10-
"grouped": "Grouped product",
11-
"external": "External product"
12-
]
13-
146
override func setUpWithError() throws {
157
continueAfterFailure = false
168

@@ -33,13 +25,14 @@ final class ProductsTests: XCTestCase {
3325
}
3426

3527
func test_add_simple_physical_product() throws {
36-
let product = try GetMocks.readNewProductData()
28+
try ProductFlow.addAndVerifyNewProduct(productType: "physical")
29+
}
3730

38-
try TabNavComponent().goToProductsScreen()
39-
.tapAddProduct()
40-
.selectProductType(productType: productTypes["physical"]!)
41-
.addProductTitle(productTitle: product.name)
42-
.publishProduct()
43-
.verifyNewProductScreenLoaded(productName: product.name)
31+
func test_add_simple_virtual_product() throws {
32+
try ProductFlow.addAndVerifyNewProduct(productType: "virtual")
33+
}
34+
35+
func test_add_variable_product() throws {
36+
try ProductFlow.addAndVerifyNewProduct(productType: "variable")
4437
}
4538
}

0 commit comments

Comments
 (0)