Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HACK week] Enables favorite products filter feature #14597

Open
wants to merge 10 commits into
base: trunk
Choose a base branch
from
2 changes: 1 addition & 1 deletion Experiments/Experiments/DefaultFeatureFlagService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public struct DefaultFeatureFlagService: FeatureFlagService {
case .blazeCampaignObjective:
return true
case .favoriteProducts:
return buildConfig == .localDeveloper || buildConfig == .alpha
return true
case .productGlobalUniqueIdentifierSupport:
return true
case .paymentsOnboardingInPointOfSale:
Expand Down
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- [Internal] Updated storage usage in SitePluginStore [https://github.com/woocommerce/woocommerce-ios/pull/14560]
- [Internal] Updated storage usage in ShippingLabelStore [https://github.com/woocommerce/woocommerce-ios/pull/14566]
- [*] Fixed: Improved the error message displayed when Bluetooth permission is denied during the card reader connection process. [https://github.com/woocommerce/woocommerce-ios/pull/14561]
- [*] Merchants can mark and filter favorite products for quicker access. [https://github.com/woocommerce/woocommerce-ios/pull/14597]
- [*] Payments: error details are now displayed for more Stripe errors, instead of a generic error message. [https://github.com/woocommerce/woocommerce-ios/pull/14583]

21.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ struct FavoriteProductsFilter: Equatable, FilterType {
let description = Localization.favoriteProducts

let isActive = true

let analyticsDescription = "favorite_products"
}

private extension FavoriteProductsFilter {
Expand Down Expand Up @@ -45,13 +47,11 @@ struct DefaultFavoriteProductsUseCase: FavoriteProductsUseCase {
self.featureFlagService = featureFlagService
}

@MainActor
func markAsFavorite(productID: Int64) {
let action = AppSettingsAction.setProductIDAsFavorite(productID: productID, siteID: siteID)
stores.dispatch(action)
}

@MainActor
func removeFromFavorite(productID: Int64) {
let action = AppSettingsAction.removeProductIDAsFavorite(productID: productID, siteID: siteID)
stores.dispatch(action)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -876,12 +876,10 @@ extension ProductFormViewModel {
await favoriteProductsUseCase.isFavorite(productID: product.productID)
}

@MainActor
func markAsFavorite() {
favoriteProductsUseCase.markAsFavorite(productID: product.productID)
}

@MainActor
func removeFromFavorite() {
favoriteProductsUseCase.removeFromFavorite(productID: product.productID)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ final class FilterProductListViewModel: FilterListViewModel {

// Generate a string based on populated filters, like "instock,publish,simple,clothes"
var analyticsDescription: String {
let elements: [String?] = [stockStatus?.rawValue, productStatus?.rawValue, promotableProductType?.productType.rawValue, productCategory?.slug]
let elements: [String?] = [stockStatus?.rawValue,
productStatus?.rawValue,
promotableProductType?.productType.rawValue,
productCategory?.slug,
favoriteProduct?.analyticsDescription]
return elements.compactMap { $0 }.joined(separator: ",")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ final class DefaultFavoriteProductsUseCaseTests: XCTestCase {
super.tearDown()
}

@MainActor
func test_it_sets_product_id_as_favorite_in_app_settings() async {
// Given
let usecase = DefaultFavoriteProductsUseCase(siteID: sampleSiteID,
Expand All @@ -39,7 +38,6 @@ final class DefaultFavoriteProductsUseCaseTests: XCTestCase {
XCTAssertEqual(receivedProductID, 4)
}

@MainActor
func test_it_removes_product_id_as_favorite_in_app_settings() async {
// Given
let usecase = DefaultFavoriteProductsUseCase(siteID: sampleSiteID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,13 @@ final class ProductFormViewModelTests: XCTestCase {
XCTAssertFalse(viewModel.canFavoriteProduct())
}

@MainActor
func test_markAsFavorite_marks_product_as_favorite() async {
// Given
let product = Product.fake()
let mockUseCase = MockFavoriteProductsUseCase()
let viewModel = createViewModel(product: product,
formType: .add,
formType: .edit,
stores: stores,
favoriteProductsUseCase: mockUseCase,
featureFlagService: MockFeatureFlagService(favoriteProducts: true))

Expand All @@ -278,13 +278,13 @@ final class ProductFormViewModelTests: XCTestCase {
XCTAssertEqual(mockUseCase.markAsFavoriteCalledForProductID, product.productID)
}

@MainActor
func test_removeFromFavorite_removes_product_as_favorite() async {
// Given
let product = Product.fake()
let mockUseCase = MockFavoriteProductsUseCase()
let viewModel = createViewModel(product: product,
formType: .add,
formType: .edit,
stores: stores,
favoriteProductsUseCase: mockUseCase,
featureFlagService: MockFeatureFlagService(favoriteProducts: true))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import XCTest
@testable import Yosemite

final class FilterProductListViewModelTests: XCTestCase {
let filterProductCategory = ProductCategory(categoryID: 0, siteID: 0, parentID: 0, name: "", slug: "")
let filterProductCategory = ProductCategory(categoryID: 0, siteID: 0, parentID: 0, name: "", slug: "category")

func testCriteriaWithDefaultFilters() {
// Given
Expand Down Expand Up @@ -69,6 +69,21 @@ final class FilterProductListViewModelTests: XCTestCase {
XCTAssertEqual(viewModel.criteria, expectedCriteria)
}

func test_it_provides_analytics_description_based_on_selected_filters() {
// Given
let filters = FilterProductListViewModel.Filters(stockStatus: .inStock,
productStatus: .draft,
promotableProductType: PromotableProductType(productType: .grouped,
isAvailable: true,
promoteUrl: nil),
productCategory: filterProductCategory,
favoriteProduct: FavoriteProductsFilter(),
numberOfActiveFilters: 5)

// Then
XCTAssertEqual(filters.analyticsDescription, "instock,draft,grouped,category,favorite_products")
}

// MARK: Favorite product feature flag

func test_filterTypeViewModels_does_not_contain_favorite_filter_view_model_when_feature_flag_off() {
Expand Down
Loading