Improve test coverage
This commit is contained in:
parent
e52b2bb74a
commit
e167a6450e
8 changed files with 605 additions and 69 deletions
|
@ -80,16 +80,18 @@ const ProductVariantCreatorContent: React.FC<ProductVariantCreatorContentProps>
|
|||
changeApplyPriceToAllValue: {
|
||||
price
|
||||
},
|
||||
type: ProductVariantCreateReducerActionType.applyPriceToAll
|
||||
type:
|
||||
ProductVariantCreateReducerActionType.changeApplyPriceToAllValue
|
||||
})
|
||||
}
|
||||
onApplyToAllStockChange={(warehouseIndex, quantity) =>
|
||||
onApplyToAllStockChange={(quantity, warehouseIndex) =>
|
||||
dispatchFormDataAction({
|
||||
changeApplyStockToAllValue: {
|
||||
quantity: parseInt(quantity, 10),
|
||||
quantity,
|
||||
warehouseIndex
|
||||
},
|
||||
type: ProductVariantCreateReducerActionType.applyStockToAll
|
||||
type:
|
||||
ProductVariantCreateReducerActionType.changeApplyStockToAllValue
|
||||
})
|
||||
}
|
||||
onAttributeSelect={(attributeId, type) =>
|
||||
|
|
|
@ -21,7 +21,7 @@ export interface ProductVariantCreatorPriceAndSkuProps {
|
|||
type: PriceOrStock
|
||||
) => void;
|
||||
onApplyToAllPriceChange: (value: string) => void;
|
||||
onApplyToAllStockChange: (warehouseIndex: number, value: string) => void;
|
||||
onApplyToAllStockChange: (quantity: number, warehouseIndex: number) => void;
|
||||
onAttributeSelect: (id: string, type: PriceOrStock) => void;
|
||||
onAttributePriceChange: (id: string, value: string) => void;
|
||||
onAttributeStockChange: (
|
||||
|
|
|
@ -84,7 +84,7 @@ export interface ProductVariantCreatorStockProps {
|
|||
data: ProductVariantCreateFormData;
|
||||
warehouses: WarehouseFragment[];
|
||||
onApplyToAllChange: (mode: VariantCreatorPricesAndSkuMode) => void;
|
||||
onApplyToAllStockChange: (warehouseIndex: number, value: string) => void;
|
||||
onApplyToAllStockChange: (quantity: number, warehouseIndex: number) => void;
|
||||
onAttributeSelect: (id: string) => void;
|
||||
onAttributeValueChange: (
|
||||
id: string,
|
||||
|
@ -203,8 +203,8 @@ const ProductVariantCreatorStock: React.FC<ProductVariantCreatorStockProps> = pr
|
|||
value={data.stock.value[warehouseIndex]}
|
||||
onChange={event =>
|
||||
onApplyToAllStockChange(
|
||||
warehouseIndex,
|
||||
event.target.value
|
||||
parseInt(event.target.value, 10),
|
||||
warehouseIndex
|
||||
)
|
||||
}
|
||||
/>
|
||||
|
|
|
@ -26,8 +26,8 @@ Object {
|
|||
},
|
||||
],
|
||||
"price": Object {
|
||||
"all": false,
|
||||
"attribute": "attr-2",
|
||||
"mode": "attribute",
|
||||
"value": "",
|
||||
"values": Array [
|
||||
Object {
|
||||
|
@ -41,8 +41,8 @@ Object {
|
|||
],
|
||||
},
|
||||
"stock": Object {
|
||||
"all": false,
|
||||
"attribute": "attr-4",
|
||||
"mode": "attribute",
|
||||
"value": Array [],
|
||||
"values": Array [
|
||||
Object {
|
||||
|
@ -438,8 +438,8 @@ Object {
|
|||
},
|
||||
],
|
||||
"price": Object {
|
||||
"all": false,
|
||||
"attribute": "attr-2",
|
||||
"mode": "attribute",
|
||||
"value": "",
|
||||
"values": Array [
|
||||
Object {
|
||||
|
@ -453,8 +453,8 @@ Object {
|
|||
],
|
||||
},
|
||||
"stock": Object {
|
||||
"all": false,
|
||||
"attribute": "attr-4",
|
||||
"mode": "attribute",
|
||||
"value": Array [],
|
||||
"values": Array [
|
||||
Object {
|
||||
|
@ -850,14 +850,14 @@ Object {
|
|||
},
|
||||
],
|
||||
"price": Object {
|
||||
"all": true,
|
||||
"attribute": undefined,
|
||||
"mode": "all",
|
||||
"value": "10.99",
|
||||
"values": Array [],
|
||||
},
|
||||
"stock": Object {
|
||||
"all": true,
|
||||
"attribute": undefined,
|
||||
"mode": "all",
|
||||
"value": Array [],
|
||||
"values": Array [],
|
||||
},
|
||||
|
@ -892,15 +892,20 @@ Object {
|
|||
},
|
||||
],
|
||||
"price": Object {
|
||||
"all": true,
|
||||
"attribute": undefined,
|
||||
"mode": "all",
|
||||
"value": "45.99",
|
||||
"values": Array [],
|
||||
},
|
||||
"stock": Object {
|
||||
"all": true,
|
||||
"attribute": undefined,
|
||||
"value": Array [],
|
||||
"mode": "all",
|
||||
"value": Array [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
],
|
||||
"values": Array [],
|
||||
},
|
||||
"variants": Array [
|
||||
|
@ -927,7 +932,24 @@ Object {
|
|||
],
|
||||
"priceOverride": "45.99",
|
||||
"sku": "",
|
||||
"stocks": Array [],
|
||||
"stocks": Array [
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-1",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-2",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-3",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-4",
|
||||
},
|
||||
],
|
||||
},
|
||||
Object {
|
||||
"attributes": Array [
|
||||
|
@ -952,7 +974,24 @@ Object {
|
|||
],
|
||||
"priceOverride": "45.99",
|
||||
"sku": "",
|
||||
"stocks": Array [],
|
||||
"stocks": Array [
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-1",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-2",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-3",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-4",
|
||||
},
|
||||
],
|
||||
},
|
||||
Object {
|
||||
"attributes": Array [
|
||||
|
@ -977,7 +1016,24 @@ Object {
|
|||
],
|
||||
"priceOverride": "45.99",
|
||||
"sku": "",
|
||||
"stocks": Array [],
|
||||
"stocks": Array [
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-1",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-2",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-3",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-4",
|
||||
},
|
||||
],
|
||||
},
|
||||
Object {
|
||||
"attributes": Array [
|
||||
|
@ -1002,7 +1058,24 @@ Object {
|
|||
],
|
||||
"priceOverride": "45.99",
|
||||
"sku": "",
|
||||
"stocks": Array [],
|
||||
"stocks": Array [
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-1",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-2",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-3",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-4",
|
||||
},
|
||||
],
|
||||
},
|
||||
Object {
|
||||
"attributes": Array [
|
||||
|
@ -1027,7 +1100,24 @@ Object {
|
|||
],
|
||||
"priceOverride": "45.99",
|
||||
"sku": "",
|
||||
"stocks": Array [],
|
||||
"stocks": Array [
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-1",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-2",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-3",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-4",
|
||||
},
|
||||
],
|
||||
},
|
||||
Object {
|
||||
"attributes": Array [
|
||||
|
@ -1052,7 +1142,24 @@ Object {
|
|||
],
|
||||
"priceOverride": "45.99",
|
||||
"sku": "",
|
||||
"stocks": Array [],
|
||||
"stocks": Array [
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-1",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-2",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-3",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-4",
|
||||
},
|
||||
],
|
||||
},
|
||||
Object {
|
||||
"attributes": Array [
|
||||
|
@ -1077,7 +1184,24 @@ Object {
|
|||
],
|
||||
"priceOverride": "45.99",
|
||||
"sku": "",
|
||||
"stocks": Array [],
|
||||
"stocks": Array [
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-1",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-2",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-3",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-4",
|
||||
},
|
||||
],
|
||||
},
|
||||
Object {
|
||||
"attributes": Array [
|
||||
|
@ -1102,7 +1226,24 @@ Object {
|
|||
],
|
||||
"priceOverride": "45.99",
|
||||
"sku": "",
|
||||
"stocks": Array [],
|
||||
"stocks": Array [
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-1",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-2",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-3",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-4",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
"warehouses": Array [
|
||||
|
@ -1140,8 +1281,8 @@ Object {
|
|||
},
|
||||
],
|
||||
"price": Object {
|
||||
"all": false,
|
||||
"attribute": "attr-1",
|
||||
"mode": "attribute",
|
||||
"value": "10.99",
|
||||
"values": Array [
|
||||
Object {
|
||||
|
@ -1155,9 +1296,14 @@ Object {
|
|||
],
|
||||
},
|
||||
"stock": Object {
|
||||
"all": true,
|
||||
"attribute": undefined,
|
||||
"value": Array [],
|
||||
"mode": "all",
|
||||
"value": Array [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
],
|
||||
"values": Array [],
|
||||
},
|
||||
"variants": Array [
|
||||
|
@ -1184,7 +1330,24 @@ Object {
|
|||
],
|
||||
"priceOverride": "45.99",
|
||||
"sku": "",
|
||||
"stocks": Array [],
|
||||
"stocks": Array [
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-1",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-2",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-3",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-4",
|
||||
},
|
||||
],
|
||||
},
|
||||
Object {
|
||||
"attributes": Array [
|
||||
|
@ -1209,7 +1372,24 @@ Object {
|
|||
],
|
||||
"priceOverride": "45.99",
|
||||
"sku": "",
|
||||
"stocks": Array [],
|
||||
"stocks": Array [
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-1",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-2",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-3",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-4",
|
||||
},
|
||||
],
|
||||
},
|
||||
Object {
|
||||
"attributes": Array [
|
||||
|
@ -1234,7 +1414,24 @@ Object {
|
|||
],
|
||||
"priceOverride": "45.99",
|
||||
"sku": "",
|
||||
"stocks": Array [],
|
||||
"stocks": Array [
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-1",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-2",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-3",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-4",
|
||||
},
|
||||
],
|
||||
},
|
||||
Object {
|
||||
"attributes": Array [
|
||||
|
@ -1259,7 +1456,24 @@ Object {
|
|||
],
|
||||
"priceOverride": "45.99",
|
||||
"sku": "",
|
||||
"stocks": Array [],
|
||||
"stocks": Array [
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-1",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-2",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-3",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-4",
|
||||
},
|
||||
],
|
||||
},
|
||||
Object {
|
||||
"attributes": Array [
|
||||
|
@ -1284,7 +1498,24 @@ Object {
|
|||
],
|
||||
"priceOverride": "51.99",
|
||||
"sku": "",
|
||||
"stocks": Array [],
|
||||
"stocks": Array [
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-1",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-2",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-3",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-4",
|
||||
},
|
||||
],
|
||||
},
|
||||
Object {
|
||||
"attributes": Array [
|
||||
|
@ -1309,7 +1540,24 @@ Object {
|
|||
],
|
||||
"priceOverride": "51.99",
|
||||
"sku": "",
|
||||
"stocks": Array [],
|
||||
"stocks": Array [
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-1",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-2",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-3",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-4",
|
||||
},
|
||||
],
|
||||
},
|
||||
Object {
|
||||
"attributes": Array [
|
||||
|
@ -1334,7 +1582,24 @@ Object {
|
|||
],
|
||||
"priceOverride": "51.99",
|
||||
"sku": "",
|
||||
"stocks": Array [],
|
||||
"stocks": Array [
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-1",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-2",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-3",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-4",
|
||||
},
|
||||
],
|
||||
},
|
||||
Object {
|
||||
"attributes": Array [
|
||||
|
@ -1359,7 +1624,24 @@ Object {
|
|||
],
|
||||
"priceOverride": "51.99",
|
||||
"sku": "",
|
||||
"stocks": Array [],
|
||||
"stocks": Array [
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-1",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-2",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-3",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-4",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
"warehouses": Array [
|
||||
|
@ -1397,15 +1679,20 @@ Object {
|
|||
},
|
||||
],
|
||||
"price": Object {
|
||||
"all": true,
|
||||
"attribute": undefined,
|
||||
"mode": "all",
|
||||
"value": "10.99",
|
||||
"values": Array [],
|
||||
},
|
||||
"stock": Object {
|
||||
"all": true,
|
||||
"attribute": undefined,
|
||||
"value": "45.99",
|
||||
"mode": "all",
|
||||
"value": Array [
|
||||
0,
|
||||
45,
|
||||
0,
|
||||
0,
|
||||
],
|
||||
"values": Array [],
|
||||
},
|
||||
"variants": Array [
|
||||
|
@ -1431,8 +1718,25 @@ Object {
|
|||
},
|
||||
],
|
||||
"priceOverride": "10.99",
|
||||
"quantity": 45,
|
||||
"sku": "",
|
||||
"stocks": Array [
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-1",
|
||||
},
|
||||
Object {
|
||||
"quantity": 45,
|
||||
"warehouse": "wh-2",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-3",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-4",
|
||||
},
|
||||
],
|
||||
},
|
||||
Object {
|
||||
"attributes": Array [
|
||||
|
@ -1456,8 +1760,25 @@ Object {
|
|||
},
|
||||
],
|
||||
"priceOverride": "10.99",
|
||||
"quantity": 45,
|
||||
"sku": "",
|
||||
"stocks": Array [
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-1",
|
||||
},
|
||||
Object {
|
||||
"quantity": 45,
|
||||
"warehouse": "wh-2",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-3",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-4",
|
||||
},
|
||||
],
|
||||
},
|
||||
Object {
|
||||
"attributes": Array [
|
||||
|
@ -1481,8 +1802,25 @@ Object {
|
|||
},
|
||||
],
|
||||
"priceOverride": "10.99",
|
||||
"quantity": 45,
|
||||
"sku": "",
|
||||
"stocks": Array [
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-1",
|
||||
},
|
||||
Object {
|
||||
"quantity": 45,
|
||||
"warehouse": "wh-2",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-3",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-4",
|
||||
},
|
||||
],
|
||||
},
|
||||
Object {
|
||||
"attributes": Array [
|
||||
|
@ -1506,8 +1844,25 @@ Object {
|
|||
},
|
||||
],
|
||||
"priceOverride": "10.99",
|
||||
"quantity": 45,
|
||||
"sku": "",
|
||||
"stocks": Array [
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-1",
|
||||
},
|
||||
Object {
|
||||
"quantity": 45,
|
||||
"warehouse": "wh-2",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-3",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-4",
|
||||
},
|
||||
],
|
||||
},
|
||||
Object {
|
||||
"attributes": Array [
|
||||
|
@ -1531,8 +1886,25 @@ Object {
|
|||
},
|
||||
],
|
||||
"priceOverride": "10.99",
|
||||
"quantity": 45,
|
||||
"sku": "",
|
||||
"stocks": Array [
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-1",
|
||||
},
|
||||
Object {
|
||||
"quantity": 45,
|
||||
"warehouse": "wh-2",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-3",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-4",
|
||||
},
|
||||
],
|
||||
},
|
||||
Object {
|
||||
"attributes": Array [
|
||||
|
@ -1556,8 +1928,25 @@ Object {
|
|||
},
|
||||
],
|
||||
"priceOverride": "10.99",
|
||||
"quantity": 45,
|
||||
"sku": "",
|
||||
"stocks": Array [
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-1",
|
||||
},
|
||||
Object {
|
||||
"quantity": 45,
|
||||
"warehouse": "wh-2",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-3",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-4",
|
||||
},
|
||||
],
|
||||
},
|
||||
Object {
|
||||
"attributes": Array [
|
||||
|
@ -1581,8 +1970,25 @@ Object {
|
|||
},
|
||||
],
|
||||
"priceOverride": "10.99",
|
||||
"quantity": 45,
|
||||
"sku": "",
|
||||
"stocks": Array [
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-1",
|
||||
},
|
||||
Object {
|
||||
"quantity": 45,
|
||||
"warehouse": "wh-2",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-3",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-4",
|
||||
},
|
||||
],
|
||||
},
|
||||
Object {
|
||||
"attributes": Array [
|
||||
|
@ -1606,9 +2012,32 @@ Object {
|
|||
},
|
||||
],
|
||||
"priceOverride": "10.99",
|
||||
"quantity": 45,
|
||||
"sku": "",
|
||||
"stocks": Array [
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-1",
|
||||
},
|
||||
Object {
|
||||
"quantity": 45,
|
||||
"warehouse": "wh-2",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-3",
|
||||
},
|
||||
Object {
|
||||
"quantity": 0,
|
||||
"warehouse": "wh-4",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
"warehouses": Array [
|
||||
"wh-1",
|
||||
"wh-2",
|
||||
"wh-3",
|
||||
"wh-4",
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
@ -1639,15 +2068,20 @@ Object {
|
|||
},
|
||||
],
|
||||
"price": Object {
|
||||
"all": true,
|
||||
"attribute": undefined,
|
||||
"mode": "all",
|
||||
"value": "10.99",
|
||||
"values": Array [],
|
||||
},
|
||||
"stock": Object {
|
||||
"all": false,
|
||||
"attribute": "attr-1",
|
||||
"value": Array [],
|
||||
"mode": "attribute",
|
||||
"value": Array [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
],
|
||||
"values": Array [
|
||||
Object {
|
||||
"slug": "val-1-1",
|
||||
|
@ -1913,3 +2347,51 @@ Object {
|
|||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Reducer is able to select warehouses in which stock will be created 1`] = `
|
||||
Object {
|
||||
"attributes": Array [
|
||||
Object {
|
||||
"id": "attr-1",
|
||||
"values": Array [
|
||||
"val-1-1",
|
||||
"val-1-7",
|
||||
],
|
||||
},
|
||||
Object {
|
||||
"id": "attr-2",
|
||||
"values": Array [
|
||||
"val-2-2",
|
||||
"val-2-4",
|
||||
],
|
||||
},
|
||||
Object {
|
||||
"id": "attr-4",
|
||||
"values": Array [
|
||||
"val-4-1",
|
||||
"val-4-5",
|
||||
],
|
||||
},
|
||||
],
|
||||
"price": Object {
|
||||
"attribute": undefined,
|
||||
"mode": "all",
|
||||
"value": "10.99",
|
||||
"values": Array [],
|
||||
},
|
||||
"stock": Object {
|
||||
"attribute": undefined,
|
||||
"mode": "all",
|
||||
"value": Array [
|
||||
0,
|
||||
0,
|
||||
],
|
||||
"values": Array [],
|
||||
},
|
||||
"variants": Array [],
|
||||
"warehouses": Array [
|
||||
"wh-2",
|
||||
"wh-4",
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
|
|
@ -24,12 +24,12 @@ describe("Creates variant matrix", () => {
|
|||
...thirdStep,
|
||||
price: {
|
||||
...thirdStep.price,
|
||||
all: true,
|
||||
mode: "all",
|
||||
value: price
|
||||
},
|
||||
stock: {
|
||||
...thirdStep.stock,
|
||||
all: true,
|
||||
mode: "all",
|
||||
value: stock
|
||||
}
|
||||
};
|
||||
|
@ -61,8 +61,8 @@ describe("Creates variant matrix", () => {
|
|||
...thirdStep,
|
||||
price: {
|
||||
...thirdStep.price,
|
||||
all: false,
|
||||
attribute: attribute.id,
|
||||
mode: "attribute",
|
||||
values: attribute.values.map((attributeValue, attributeValueIndex) => ({
|
||||
slug: attributeValue,
|
||||
value: (price * (attributeValueIndex + 1)).toString()
|
||||
|
@ -70,7 +70,7 @@ describe("Creates variant matrix", () => {
|
|||
},
|
||||
stock: {
|
||||
...thirdStep.stock,
|
||||
all: true,
|
||||
mode: "all",
|
||||
value: stock
|
||||
}
|
||||
};
|
||||
|
@ -116,13 +116,13 @@ describe("Creates variant matrix", () => {
|
|||
...thirdStep,
|
||||
price: {
|
||||
...thirdStep.price,
|
||||
all: true,
|
||||
mode: "all",
|
||||
value: price
|
||||
},
|
||||
stock: {
|
||||
...thirdStep.stock,
|
||||
all: false,
|
||||
attribute: attribute.id,
|
||||
mode: "attribute",
|
||||
values: attribute.values.map((attributeValue, attributeValueIndex) => ({
|
||||
slug: attributeValue,
|
||||
value: stock.map(
|
||||
|
@ -173,8 +173,8 @@ describe("Creates variant matrix", () => {
|
|||
...thirdStep,
|
||||
price: {
|
||||
...thirdStep.price,
|
||||
all: false,
|
||||
attribute: attribute.id,
|
||||
mode: "attribute",
|
||||
values: attribute.values.map((attributeValue, attributeValueIndex) => ({
|
||||
slug: attributeValue,
|
||||
value: (price * (attributeValueIndex + 1)).toString()
|
||||
|
@ -182,8 +182,8 @@ describe("Creates variant matrix", () => {
|
|||
},
|
||||
stock: {
|
||||
...thirdStep.stock,
|
||||
all: false,
|
||||
attribute: attribute.id,
|
||||
mode: "attribute",
|
||||
values: attribute.values.map((attributeValue, attributeValueIndex) => ({
|
||||
slug: attributeValue,
|
||||
value: stock.map(
|
||||
|
|
|
@ -90,12 +90,16 @@ export const thirdStep: ProductVariantCreateFormData = {
|
|||
values: [0, 4].map(index => attributes[3].values[index])
|
||||
}
|
||||
],
|
||||
stock: {
|
||||
...secondStep.stock,
|
||||
value: warehouses.map(() => 0)
|
||||
},
|
||||
warehouses: warehouses.map(warehouse => warehouse.id)
|
||||
};
|
||||
|
||||
const price: AllOrAttribute<string> = {
|
||||
all: false,
|
||||
attribute: thirdStep.attributes[1].id,
|
||||
mode: "attribute",
|
||||
value: "",
|
||||
values: [
|
||||
{
|
||||
|
@ -109,8 +113,8 @@ const price: AllOrAttribute<string> = {
|
|||
]
|
||||
};
|
||||
const stock: AllOrAttribute<number[]> = {
|
||||
all: false,
|
||||
attribute: thirdStep.attributes[2].id,
|
||||
mode: "attribute",
|
||||
value: [],
|
||||
values: [
|
||||
{
|
||||
|
|
|
@ -77,7 +77,7 @@ describe("Reducer is able to", () => {
|
|||
const state = execActions(thirdStep, reducer, [
|
||||
{
|
||||
applyPriceOrStockToAll: {
|
||||
all: true
|
||||
mode: "all"
|
||||
},
|
||||
type: ProductVariantCreateReducerActionType.applyPriceToAll
|
||||
},
|
||||
|
@ -92,18 +92,38 @@ describe("Reducer is able to", () => {
|
|||
}
|
||||
]);
|
||||
|
||||
expect(state.price.all).toBeTruthy();
|
||||
expect(state.price.mode).toBe("all");
|
||||
expect(state.price.value).toBe(price);
|
||||
expect(state).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("select warehouses in which stock will be created", () => {
|
||||
const state = execActions(thirdStep, reducer, [
|
||||
{
|
||||
changeWarehouses: {
|
||||
warehouseId: warehouses[0].id
|
||||
},
|
||||
type: ProductVariantCreateReducerActionType.changeWarehouses
|
||||
},
|
||||
{
|
||||
changeWarehouses: {
|
||||
warehouseId: warehouses[2].id
|
||||
},
|
||||
type: ProductVariantCreateReducerActionType.changeWarehouses
|
||||
}
|
||||
]);
|
||||
|
||||
expect(state.warehouses).toHaveLength(2);
|
||||
expect(state).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("select stock for all variants", () => {
|
||||
const quantity = 45;
|
||||
const warehouseIndex = 1;
|
||||
const state = execActions(thirdStep, reducer, [
|
||||
{
|
||||
applyPriceOrStockToAll: {
|
||||
all: true
|
||||
mode: "all"
|
||||
},
|
||||
type: ProductVariantCreateReducerActionType.applyStockToAll
|
||||
},
|
||||
|
@ -119,7 +139,7 @@ describe("Reducer is able to", () => {
|
|||
}
|
||||
]);
|
||||
|
||||
expect(state.stock.all).toBeTruthy();
|
||||
expect(state.stock.mode).toBe("all");
|
||||
expect(state.stock.value[warehouseIndex]).toBe(quantity);
|
||||
expect(state).toMatchSnapshot();
|
||||
});
|
||||
|
@ -130,7 +150,7 @@ describe("Reducer is able to", () => {
|
|||
const state = execActions(thirdStep, reducer, [
|
||||
{
|
||||
applyPriceOrStockToAll: {
|
||||
all: false
|
||||
mode: "attribute"
|
||||
},
|
||||
type: ProductVariantCreateReducerActionType.applyPriceToAll
|
||||
},
|
||||
|
@ -160,7 +180,7 @@ describe("Reducer is able to", () => {
|
|||
}
|
||||
]);
|
||||
|
||||
expect(state.price.all).toBeFalsy();
|
||||
expect(state.price.mode).toBe("attribute");
|
||||
expect(state.price.values).toHaveLength(
|
||||
state.attributes.find(attribute => state.price.attribute === attribute.id)
|
||||
.values.length
|
||||
|
@ -174,7 +194,7 @@ describe("Reducer is able to", () => {
|
|||
const state = execActions(thirdStep, reducer, [
|
||||
{
|
||||
applyPriceOrStockToAll: {
|
||||
all: false
|
||||
mode: "attribute"
|
||||
},
|
||||
type: ProductVariantCreateReducerActionType.applyStockToAll
|
||||
},
|
||||
|
@ -206,7 +226,7 @@ describe("Reducer is able to", () => {
|
|||
}
|
||||
]);
|
||||
|
||||
expect(state.stock.all).toBeFalsy();
|
||||
expect(state.stock.mode).toBe("attribute");
|
||||
expect(state.stock.values).toHaveLength(
|
||||
state.attributes.find(attribute => state.stock.attribute === attribute.id)
|
||||
.values.length
|
||||
|
|
|
@ -335,9 +335,37 @@ function changeWarehouses(
|
|||
state: ProductVariantCreateFormData,
|
||||
warehouseId: string
|
||||
): ProductVariantCreateFormData {
|
||||
const warehouses = toggle(warehouseId, state.warehouses, (a, b) => a === b);
|
||||
const added = warehouses.length > state.warehouses.length;
|
||||
|
||||
if (added) {
|
||||
return {
|
||||
...state,
|
||||
warehouses: toggle(warehouseId, state.warehouses, (a, b) => a === b)
|
||||
stock: {
|
||||
...state.stock,
|
||||
value: [...state.stock.value, 0],
|
||||
values: state.stock.values.map(stockValue => ({
|
||||
...stockValue,
|
||||
value: [...stockValue.value, 0]
|
||||
}))
|
||||
},
|
||||
warehouses
|
||||
};
|
||||
}
|
||||
|
||||
const warehouseIndex = state.warehouses.indexOf(warehouseId);
|
||||
|
||||
return {
|
||||
...state,
|
||||
stock: {
|
||||
...state.stock,
|
||||
value: removeAtIndex(state.stock.value, warehouseIndex),
|
||||
values: state.stock.values.map(stockValue => ({
|
||||
...stockValue,
|
||||
value: removeAtIndex(stockValue.value, warehouseIndex)
|
||||
}))
|
||||
},
|
||||
warehouses
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue