Skip to content

Commit d2514dc

Browse files
author
Ernesto Carrión
committed
Improve tests that succeed on an empty loop
1 parent 0a5faa7 commit d2514dc

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

WooCommerce/WooCommerceTests/ViewRelated/Products/Edit Product/Categories/ProductCategoryViewModelBuilderTests.swift

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,23 @@ final class ProductCategoryViewModelBuilderTests: XCTestCase {
5959
let rootCategoriesNames = rootCategories.map { $0.name }
6060
let subCategories1Names = subCategories1.map { $0.name }
6161
let subCategories2Names = subCategories2.map { $0.name }
62-
for viewModel in viewModels {
63-
if rootCategoriesNames.contains(viewModel.name) {
64-
XCTAssertEqual(viewModel.indentationLevel, 0)
65-
}
66-
67-
if subCategories1Names.contains(viewModel.name) {
68-
XCTAssertEqual(viewModel.indentationLevel, 1)
69-
}
70-
71-
if subCategories2Names.contains(viewModel.name) {
72-
XCTAssertEqual(viewModel.indentationLevel, 2)
73-
}
62+
63+
let rootViewModels = viewModels.filter { rootCategoriesNames.contains($0.name) }
64+
XCTAssertEqual(rootViewModels.count, rootCategories.count)
65+
rootViewModels.forEach {
66+
XCTAssertEqual($0.indentationLevel, 0)
67+
}
68+
69+
let subViewModels = viewModels.filter { subCategories1Names.contains($0.name) }
70+
XCTAssertEqual(subViewModels.count, subCategories1.count)
71+
subViewModels.forEach {
72+
XCTAssertEqual($0.indentationLevel, 1)
73+
}
74+
75+
let subViewModels2 = viewModels.filter { subCategories2Names.contains($0.name) }
76+
XCTAssertEqual(subViewModels2.count, subCategories2.count)
77+
subViewModels2.forEach {
78+
XCTAssertEqual($0.indentationLevel, 2)
7479
}
7580
}
7681

0 commit comments

Comments
 (0)