-
Notifications
You must be signed in to change notification settings - Fork 120
Fix certain M1 settings aren't accessible if the data are empty when M2 feature switch is off #2303
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
Changes from all commits
011c0c2
1a52c63
5a04581
768fd0f
353fd12
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import Yosemite | ||
|
|
||
| /// Creates actions for product form bottom sheet. | ||
| struct ProductFormBottomSheetActionsFactory { | ||
| private let product: Product | ||
| private let isEditProductsRelease2Enabled: Bool | ||
| private let isEditProductsRelease3Enabled: Bool | ||
|
|
||
| init(product: Product, isEditProductsRelease2Enabled: Bool, isEditProductsRelease3Enabled: Bool) { | ||
| self.product = product | ||
| self.isEditProductsRelease2Enabled = isEditProductsRelease2Enabled | ||
| self.isEditProductsRelease3Enabled = isEditProductsRelease3Enabled | ||
| } | ||
|
|
||
| /// Retruns an array of actions that are visible in the product form bottom sheet. | ||
| func actions() -> [ProductFormBottomSheetAction] { | ||
| let shouldShowShippingSettingsRow = product.isShippingEnabled | ||
| let shouldShowCategoriesRow = isEditProductsRelease3Enabled | ||
| let shouldShowShortDescriptionRow = isEditProductsRelease2Enabled | ||
| let actions: [ProductFormBottomSheetAction?] = [ | ||
| .editInventorySettings, | ||
| shouldShowShippingSettingsRow ? .editShippingSettings: nil, | ||
| shouldShowCategoriesRow ? .editCategories: nil, | ||
| shouldShowShortDescriptionRow ? .editBriefDescription: nil | ||
| ] | ||
| return actions.compactMap({ $0 }).filter({ $0.isVisible(product: product) }) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should also encapsulate the I wonder if we've outgrown the current architecture (expected and normal) and we need to do a review at some point in the future.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yea I think it'd be nice if we can merge the logic for making the bottom sheet actions and settings rows since they are based on the same data (product editing categories), maybe having both created from the same factory (a different name like |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| import XCTest | ||
| @testable import WooCommerce | ||
| @testable import Yosemite | ||
|
|
||
| final class ProductFormBottomSheetActionsFactoryTests: XCTestCase { | ||
|
|
||
| // M3 feature flag off & M2 feature flag off | ||
|
|
||
| func testDataHasNoEditProductsRelease2And3ActionsForAPhysicalProductWhenBothFeatureFlagsAreOff() { | ||
| let product = Fixtures.physicalProduct | ||
| let isEditProductsRelease2Enabled = false | ||
| let isEditProductsRelease3Enabled = false | ||
| let actions = ProductFormBottomSheetActionsFactory(product: product, | ||
| isEditProductsRelease2Enabled: isEditProductsRelease2Enabled, | ||
| isEditProductsRelease3Enabled: isEditProductsRelease3Enabled).actions() | ||
|
|
||
| let expectedActions: [ProductFormBottomSheetAction] = [ | ||
| .editInventorySettings, | ||
| .editShippingSettings | ||
| ] | ||
| XCTAssertEqual(actions, expectedActions) | ||
| } | ||
|
|
||
| func testDataHasNoEditProductsRelease2And3AndShippingActionsForAVirtualProductWhenBothFeatureFlagsAreOff() { | ||
| let product = Fixtures.virtualProduct | ||
| let isEditProductsRelease2Enabled = false | ||
| let isEditProductsRelease3Enabled = false | ||
| let actions = ProductFormBottomSheetActionsFactory(product: product, | ||
| isEditProductsRelease2Enabled: isEditProductsRelease2Enabled, | ||
| isEditProductsRelease3Enabled: isEditProductsRelease3Enabled).actions() | ||
|
|
||
| let expectedActions: [ProductFormBottomSheetAction] = [ | ||
| .editInventorySettings | ||
| ] | ||
| XCTAssertEqual(actions, expectedActions) | ||
| } | ||
|
|
||
| func testDataHasNoEditProductsRelease2And3AndShippingActionsForADownloadableProductWhenBothFeatureFlagsAreOff() { | ||
| let product = Fixtures.downloadableProduct | ||
| let isEditProductsRelease2Enabled = false | ||
| let isEditProductsRelease3Enabled = false | ||
| let actions = ProductFormBottomSheetActionsFactory(product: product, | ||
| isEditProductsRelease2Enabled: isEditProductsRelease2Enabled, | ||
| isEditProductsRelease3Enabled: isEditProductsRelease3Enabled).actions() | ||
|
|
||
| let expectedActions: [ProductFormBottomSheetAction] = [ | ||
| .editInventorySettings | ||
| ] | ||
| XCTAssertEqual(actions, expectedActions) | ||
| } | ||
|
|
||
| // M3 feature flag off & M2 feature flag on | ||
|
|
||
| func testDataHasNoEditProductsRelease3ActionsForAPhysicalProductWhenM3FeatureFlagIsOff() { | ||
| let product = Fixtures.physicalProduct | ||
| let isEditProductsRelease2Enabled = true | ||
| let isEditProductsRelease3Enabled = false | ||
| let actions = ProductFormBottomSheetActionsFactory(product: product, | ||
| isEditProductsRelease2Enabled: isEditProductsRelease2Enabled, | ||
| isEditProductsRelease3Enabled: isEditProductsRelease3Enabled).actions() | ||
|
|
||
| let expectedActions: [ProductFormBottomSheetAction] = [ | ||
| .editInventorySettings, | ||
| .editShippingSettings, | ||
| .editBriefDescription | ||
| ] | ||
| XCTAssertEqual(actions, expectedActions) | ||
| } | ||
|
|
||
| func testDataHasNoEditProductsRelease3AndShippingActionsForAVirtualProductWhenM3FeatureFlagIsOff() { | ||
| let product = Fixtures.virtualProduct | ||
| let isEditProductsRelease2Enabled = true | ||
| let isEditProductsRelease3Enabled = false | ||
| let actions = ProductFormBottomSheetActionsFactory(product: product, | ||
| isEditProductsRelease2Enabled: isEditProductsRelease2Enabled, | ||
| isEditProductsRelease3Enabled: isEditProductsRelease3Enabled).actions() | ||
|
|
||
| let expectedActions: [ProductFormBottomSheetAction] = [ | ||
| .editInventorySettings, | ||
| .editBriefDescription | ||
| ] | ||
| XCTAssertEqual(actions, expectedActions) | ||
| } | ||
|
|
||
| func testDataHasNoEditProductsRelease3AndShippingActionsForADownloadableProductWhenM3FeatureFlagIsOff() { | ||
| let product = Fixtures.downloadableProduct | ||
| let isEditProductsRelease2Enabled = true | ||
| let isEditProductsRelease3Enabled = false | ||
| let actions = ProductFormBottomSheetActionsFactory(product: product, | ||
| isEditProductsRelease2Enabled: isEditProductsRelease2Enabled, | ||
| isEditProductsRelease3Enabled: isEditProductsRelease3Enabled).actions() | ||
|
|
||
| let expectedActions: [ProductFormBottomSheetAction] = [ | ||
| .editInventorySettings, | ||
| .editBriefDescription | ||
| ] | ||
| XCTAssertEqual(actions, expectedActions) | ||
| } | ||
|
|
||
| // M3 feature flag on & M2 feature flag is on | ||
|
|
||
| func testDataHasEditProductsRelease3ActionsForAPhysicalProductWhenBothFeatureFlagsAreOn() { | ||
| let product = Fixtures.physicalProduct | ||
| let isEditProductsRelease2Enabled = true | ||
| let isEditProductsRelease3Enabled = true | ||
| let actions = ProductFormBottomSheetActionsFactory(product: product, | ||
| isEditProductsRelease2Enabled: isEditProductsRelease2Enabled, | ||
| isEditProductsRelease3Enabled: isEditProductsRelease3Enabled).actions() | ||
|
|
||
| let expectedActions: [ProductFormBottomSheetAction] = [ | ||
| .editInventorySettings, | ||
| .editShippingSettings, | ||
| .editCategories, | ||
| .editBriefDescription | ||
| ] | ||
| XCTAssertEqual(actions, expectedActions) | ||
| } | ||
|
|
||
| func testDataHasEditProductsRelease3ButNoShippingActionsForAVirtualProductWhenBothFeatureFlagsAreOn() { | ||
| let product = Fixtures.virtualProduct | ||
| let isEditProductsRelease2Enabled = true | ||
| let isEditProductsRelease3Enabled = true | ||
| let actions = ProductFormBottomSheetActionsFactory(product: product, | ||
| isEditProductsRelease2Enabled: isEditProductsRelease2Enabled, | ||
| isEditProductsRelease3Enabled: isEditProductsRelease3Enabled).actions() | ||
|
|
||
| let expectedActions: [ProductFormBottomSheetAction] = [ | ||
| .editInventorySettings, | ||
| .editCategories, | ||
| .editBriefDescription | ||
| ] | ||
| XCTAssertEqual(actions, expectedActions) | ||
| } | ||
|
|
||
| func testDataHasEditProductsRelease3ButNoShippingActionsForADownloadableProductWhenBothFeatureFlagsAreOn() { | ||
| let product = Fixtures.downloadableProduct | ||
| let isEditProductsRelease2Enabled = true | ||
| let isEditProductsRelease3Enabled = true | ||
| let actions = ProductFormBottomSheetActionsFactory(product: product, | ||
| isEditProductsRelease2Enabled: isEditProductsRelease2Enabled, | ||
| isEditProductsRelease3Enabled: isEditProductsRelease3Enabled).actions() | ||
|
|
||
| let expectedActions: [ProductFormBottomSheetAction] = [ | ||
| .editInventorySettings, | ||
| .editCategories, | ||
| .editBriefDescription | ||
| ] | ||
| XCTAssertEqual(actions, expectedActions) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| private extension ProductFormBottomSheetActionsFactoryTests { | ||
| enum Fixtures { | ||
| // downloadable: false, virtual: false, missing inventory/shipping/categories/brief description | ||
| static let physicalProduct = MockProduct().product(downloadable: false, briefDescription: "", manageStock: true, sku: nil, stockQuantity: nil, | ||
| dimensions: ProductDimensions(length: "", width: "", height: ""), weight: nil, | ||
| virtual: false, | ||
| categories: []) | ||
| // downloadable: false, virtual: true, missing inventory/shipping/categories/brief description | ||
| static let virtualProduct = MockProduct().product(downloadable: false, briefDescription: "", manageStock: true, sku: nil, stockQuantity: nil, | ||
| dimensions: ProductDimensions(length: "", width: "", height: ""), weight: nil, | ||
| virtual: true, | ||
| categories: []) | ||
| // downloadable: true, virtual: true, missing inventory/shipping/categories/brief description | ||
| static let downloadableProduct = MockProduct().product(downloadable: true, briefDescription: "", manageStock: true, sku: nil, stockQuantity: nil, | ||
| dimensions: ProductDimensions(length: "", width: "", height: ""), weight: nil, | ||
| virtual: true, | ||
| categories: []) | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.