Update tests
This commit is contained in:
parent
5262e97b20
commit
cd7426c7a9
3 changed files with 120 additions and 70 deletions
|
@ -625,7 +625,7 @@ Object {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"priceOverride": "49.99",
|
"priceOverride": "26.99",
|
||||||
"sku": "",
|
"sku": "",
|
||||||
"stocks": Array [
|
"stocks": Array [
|
||||||
Object {
|
Object {
|
||||||
|
@ -1652,13 +1652,13 @@ Object {
|
||||||
Object {
|
Object {
|
||||||
"slug": "val-1-1",
|
"slug": "val-1-1",
|
||||||
"value": Array [
|
"value": Array [
|
||||||
undefined,
|
13,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
"slug": "val-1-7",
|
"slug": "val-1-7",
|
||||||
"value": Array [
|
"value": Array [
|
||||||
undefined,
|
19,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -1689,7 +1689,7 @@ Object {
|
||||||
"sku": "",
|
"sku": "",
|
||||||
"stocks": Array [
|
"stocks": Array [
|
||||||
Object {
|
Object {
|
||||||
"quantity": undefined,
|
"quantity": 13,
|
||||||
"warehouse": "wh-1",
|
"warehouse": "wh-1",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -1719,7 +1719,7 @@ Object {
|
||||||
"sku": "",
|
"sku": "",
|
||||||
"stocks": Array [
|
"stocks": Array [
|
||||||
Object {
|
Object {
|
||||||
"quantity": undefined,
|
"quantity": 13,
|
||||||
"warehouse": "wh-1",
|
"warehouse": "wh-1",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -1749,7 +1749,7 @@ Object {
|
||||||
"sku": "",
|
"sku": "",
|
||||||
"stocks": Array [
|
"stocks": Array [
|
||||||
Object {
|
Object {
|
||||||
"quantity": undefined,
|
"quantity": 13,
|
||||||
"warehouse": "wh-1",
|
"warehouse": "wh-1",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -1779,7 +1779,7 @@ Object {
|
||||||
"sku": "",
|
"sku": "",
|
||||||
"stocks": Array [
|
"stocks": Array [
|
||||||
Object {
|
Object {
|
||||||
"quantity": undefined,
|
"quantity": 13,
|
||||||
"warehouse": "wh-1",
|
"warehouse": "wh-1",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -1809,7 +1809,7 @@ Object {
|
||||||
"sku": "",
|
"sku": "",
|
||||||
"stocks": Array [
|
"stocks": Array [
|
||||||
Object {
|
Object {
|
||||||
"quantity": undefined,
|
"quantity": 19,
|
||||||
"warehouse": "wh-1",
|
"warehouse": "wh-1",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -1839,7 +1839,7 @@ Object {
|
||||||
"sku": "",
|
"sku": "",
|
||||||
"stocks": Array [
|
"stocks": Array [
|
||||||
Object {
|
Object {
|
||||||
"quantity": undefined,
|
"quantity": 19,
|
||||||
"warehouse": "wh-1",
|
"warehouse": "wh-1",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -1869,7 +1869,7 @@ Object {
|
||||||
"sku": "",
|
"sku": "",
|
||||||
"stocks": Array [
|
"stocks": Array [
|
||||||
Object {
|
Object {
|
||||||
"quantity": undefined,
|
"quantity": 19,
|
||||||
"warehouse": "wh-1",
|
"warehouse": "wh-1",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -1899,7 +1899,7 @@ Object {
|
||||||
"sku": "",
|
"sku": "",
|
||||||
"stocks": Array [
|
"stocks": Array [
|
||||||
Object {
|
Object {
|
||||||
"quantity": undefined,
|
"quantity": 19,
|
||||||
"warehouse": "wh-1",
|
"warehouse": "wh-1",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
@ -22,34 +22,47 @@ describe("Reducer is able to", () => {
|
||||||
it("select attribute values", () => {
|
it("select attribute values", () => {
|
||||||
const state = execActions(secondStep, reducer, [
|
const state = execActions(secondStep, reducer, [
|
||||||
{
|
{
|
||||||
attributeId: attributes[0].id,
|
selectValue: {
|
||||||
type: ProductVariantCreateReducerActionType.selectValue,
|
attributeId: attributes[0].id,
|
||||||
valueId: attributes[0].values[0]
|
valueId: attributes[0].values[0]
|
||||||
|
},
|
||||||
|
type: ProductVariantCreateReducerActionType.selectValue
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
attributeId: attributes[0].id,
|
selectValue: {
|
||||||
type: ProductVariantCreateReducerActionType.selectValue,
|
attributeId: attributes[0].id,
|
||||||
valueId: attributes[0].values[6]
|
valueId: attributes[0].values[6]
|
||||||
|
},
|
||||||
|
|
||||||
|
type: ProductVariantCreateReducerActionType.selectValue
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
attributeId: attributes[1].id,
|
selectValue: {
|
||||||
type: ProductVariantCreateReducerActionType.selectValue,
|
attributeId: attributes[1].id,
|
||||||
valueId: attributes[1].values[1]
|
valueId: attributes[1].values[1]
|
||||||
|
},
|
||||||
|
type: ProductVariantCreateReducerActionType.selectValue
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
attributeId: attributes[1].id,
|
selectValue: {
|
||||||
type: ProductVariantCreateReducerActionType.selectValue,
|
attributeId: attributes[1].id,
|
||||||
valueId: attributes[1].values[3]
|
valueId: attributes[1].values[3]
|
||||||
|
},
|
||||||
|
type: ProductVariantCreateReducerActionType.selectValue
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
attributeId: attributes[3].id,
|
selectValue: {
|
||||||
type: ProductVariantCreateReducerActionType.selectValue,
|
attributeId: attributes[3].id,
|
||||||
valueId: attributes[3].values[0]
|
valueId: attributes[3].values[0]
|
||||||
|
},
|
||||||
|
type: ProductVariantCreateReducerActionType.selectValue
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
attributeId: attributes[3].id,
|
selectValue: {
|
||||||
type: ProductVariantCreateReducerActionType.selectValue,
|
attributeId: attributes[3].id,
|
||||||
valueId: attributes[3].values[4]
|
valueId: attributes[3].values[4]
|
||||||
|
},
|
||||||
|
type: ProductVariantCreateReducerActionType.selectValue
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -63,12 +76,16 @@ describe("Reducer is able to", () => {
|
||||||
const value = "45.99";
|
const value = "45.99";
|
||||||
const state = execActions(thirdStep, reducer, [
|
const state = execActions(thirdStep, reducer, [
|
||||||
{
|
{
|
||||||
all: true,
|
applyPriceOrStockToAll: {
|
||||||
|
all: true
|
||||||
|
},
|
||||||
type: ProductVariantCreateReducerActionType.applyPriceToAll
|
type: ProductVariantCreateReducerActionType.applyPriceToAll
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: ProductVariantCreateReducerActionType.changeApplyPriceToAllValue,
|
changeApplyPriceToAllValue: {
|
||||||
value
|
value
|
||||||
|
},
|
||||||
|
type: ProductVariantCreateReducerActionType.changeApplyPriceToAllValue
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: ProductVariantCreateReducerActionType.reload
|
type: ProductVariantCreateReducerActionType.reload
|
||||||
|
@ -81,16 +98,21 @@ describe("Reducer is able to", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("select stock for all variants", () => {
|
it("select stock for all variants", () => {
|
||||||
const quantity = 45.99;
|
const quantity = 45;
|
||||||
|
const warehouseIndex = 1;
|
||||||
const state = execActions(thirdStep, reducer, [
|
const state = execActions(thirdStep, reducer, [
|
||||||
{
|
{
|
||||||
all: true,
|
applyPriceOrStockToAll: {
|
||||||
|
all: true
|
||||||
|
},
|
||||||
type: ProductVariantCreateReducerActionType.applyStockToAll
|
type: ProductVariantCreateReducerActionType.applyStockToAll
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
quantity,
|
changeApplyStockToAllValue: {
|
||||||
type: ProductVariantCreateReducerActionType.changeApplyStockToAllValue,
|
quantity,
|
||||||
warehouseIndex: 1
|
warehouseIndex
|
||||||
|
},
|
||||||
|
type: ProductVariantCreateReducerActionType.changeApplyStockToAllValue
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: ProductVariantCreateReducerActionType.reload
|
type: ProductVariantCreateReducerActionType.reload
|
||||||
|
@ -98,7 +120,7 @@ describe("Reducer is able to", () => {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
expect(state.stock.all).toBeTruthy();
|
expect(state.stock.all).toBeTruthy();
|
||||||
expect(state.stock.value[1]).toBe(quantity);
|
expect(state.stock.value[warehouseIndex]).toBe(quantity);
|
||||||
expect(state).toMatchSnapshot();
|
expect(state).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -107,23 +129,31 @@ describe("Reducer is able to", () => {
|
||||||
const value = 45.99;
|
const value = 45.99;
|
||||||
const state = execActions(thirdStep, reducer, [
|
const state = execActions(thirdStep, reducer, [
|
||||||
{
|
{
|
||||||
all: false,
|
applyPriceOrStockToAll: {
|
||||||
|
all: false
|
||||||
|
},
|
||||||
type: ProductVariantCreateReducerActionType.applyPriceToAll
|
type: ProductVariantCreateReducerActionType.applyPriceToAll
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
attributeId: attribute.id,
|
changeApplyPriceOrStockToAttributeId: {
|
||||||
|
attributeId: attribute.id
|
||||||
|
},
|
||||||
type:
|
type:
|
||||||
ProductVariantCreateReducerActionType.changeApplyPriceToAttributeId
|
ProductVariantCreateReducerActionType.changeApplyPriceToAttributeId
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: ProductVariantCreateReducerActionType.changeAttributeValuePrice,
|
changeAttributeValuePrice: {
|
||||||
value: value.toString(),
|
price: value.toString(),
|
||||||
valueId: attribute.values[0]
|
valueId: attribute.values[0]
|
||||||
|
},
|
||||||
|
type: ProductVariantCreateReducerActionType.changeAttributeValuePrice
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: ProductVariantCreateReducerActionType.changeAttributeValuePrice,
|
changeAttributeValuePrice: {
|
||||||
value: (value + 6).toString(),
|
price: (value + 6).toString(),
|
||||||
valueId: attribute.values[1]
|
valueId: attribute.values[1]
|
||||||
|
},
|
||||||
|
type: ProductVariantCreateReducerActionType.changeAttributeValuePrice
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: ProductVariantCreateReducerActionType.reload
|
type: ProductVariantCreateReducerActionType.reload
|
||||||
|
@ -140,26 +170,36 @@ describe("Reducer is able to", () => {
|
||||||
|
|
||||||
it("select stock to each attribute value", () => {
|
it("select stock to each attribute value", () => {
|
||||||
const attribute = thirdStep.attributes[0];
|
const attribute = thirdStep.attributes[0];
|
||||||
const value = 13;
|
const quantity = 13;
|
||||||
const state = execActions(thirdStep, reducer, [
|
const state = execActions(thirdStep, reducer, [
|
||||||
{
|
{
|
||||||
all: false,
|
applyPriceOrStockToAll: {
|
||||||
|
all: false
|
||||||
|
},
|
||||||
type: ProductVariantCreateReducerActionType.applyStockToAll
|
type: ProductVariantCreateReducerActionType.applyStockToAll
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
attributeId: attribute.id,
|
changeApplyPriceOrStockToAttributeId: {
|
||||||
|
attributeId: attribute.id
|
||||||
|
},
|
||||||
type:
|
type:
|
||||||
ProductVariantCreateReducerActionType.changeApplyStockToAttributeId
|
ProductVariantCreateReducerActionType.changeApplyStockToAttributeId
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: ProductVariantCreateReducerActionType.changeAttributeValueStock,
|
changeAttributeValueStock: {
|
||||||
value: value.toString(),
|
quantity,
|
||||||
valueId: attribute.values[0]
|
valueId: attribute.values[0],
|
||||||
|
warehouseIndex: 0
|
||||||
|
},
|
||||||
|
type: ProductVariantCreateReducerActionType.changeAttributeValueStock
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: ProductVariantCreateReducerActionType.changeAttributeValueStock,
|
changeAttributeValueStock: {
|
||||||
value: (value + 6).toString(),
|
quantity: quantity + 6,
|
||||||
valueId: attribute.values[1]
|
valueId: attribute.values[1],
|
||||||
|
warehouseIndex: 0
|
||||||
|
},
|
||||||
|
type: ProductVariantCreateReducerActionType.changeAttributeValueStock
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: ProductVariantCreateReducerActionType.reload
|
type: ProductVariantCreateReducerActionType.reload
|
||||||
|
@ -181,10 +221,12 @@ describe("Reducer is able to", () => {
|
||||||
|
|
||||||
const state = execActions(fourthStep, reducer, [
|
const state = execActions(fourthStep, reducer, [
|
||||||
{
|
{
|
||||||
field,
|
changeVariantData: {
|
||||||
type: ProductVariantCreateReducerActionType.changeVariantData,
|
field,
|
||||||
value,
|
value,
|
||||||
variantIndex
|
variantIndex
|
||||||
|
},
|
||||||
|
type: ProductVariantCreateReducerActionType.changeVariantData
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -201,12 +243,14 @@ describe("Reducer is able to", () => {
|
||||||
|
|
||||||
const state = execActions(fourthStep, reducer, [
|
const state = execActions(fourthStep, reducer, [
|
||||||
{
|
{
|
||||||
stock: {
|
changeVariantStockData: {
|
||||||
quantity,
|
stock: {
|
||||||
warehouse: warehouses[0].id
|
quantity,
|
||||||
|
warehouse: warehouses[0].id
|
||||||
|
},
|
||||||
|
variantIndex
|
||||||
},
|
},
|
||||||
type: ProductVariantCreateReducerActionType.changeVariantStockData,
|
type: ProductVariantCreateReducerActionType.changeVariantStockData
|
||||||
variantIndex
|
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -222,8 +266,10 @@ describe("Reducer is able to", () => {
|
||||||
|
|
||||||
const state = execActions(fourthStep, reducer, [
|
const state = execActions(fourthStep, reducer, [
|
||||||
{
|
{
|
||||||
type: ProductVariantCreateReducerActionType.deleteVariant,
|
deleteVariant: {
|
||||||
variantIndex
|
variantIndex
|
||||||
|
},
|
||||||
|
type: ProductVariantCreateReducerActionType.deleteVariant
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
|
@ -283,7 +283,9 @@ function changeVariantData(
|
||||||
value: string,
|
value: string,
|
||||||
variantIndex: number
|
variantIndex: number
|
||||||
): ProductVariantCreateFormData {
|
): ProductVariantCreateFormData {
|
||||||
const variant = state.variants[variantIndex];
|
const variant = {
|
||||||
|
...state.variants[variantIndex]
|
||||||
|
};
|
||||||
if (field === "price") {
|
if (field === "price") {
|
||||||
variant.priceOverride = value;
|
variant.priceOverride = value;
|
||||||
} else if (field === "sku") {
|
} else if (field === "sku") {
|
||||||
|
@ -301,7 +303,9 @@ function changeVariantStockData(
|
||||||
stock: StockInput,
|
stock: StockInput,
|
||||||
variantIndex: number
|
variantIndex: number
|
||||||
): ProductVariantCreateFormData {
|
): ProductVariantCreateFormData {
|
||||||
const variant = state.variants[variantIndex];
|
const variant = {
|
||||||
|
...state.variants[variantIndex]
|
||||||
|
};
|
||||||
variant.stocks = update(
|
variant.stocks = update(
|
||||||
stock,
|
stock,
|
||||||
variant.stocks,
|
variant.stocks,
|
||||||
|
@ -342,7 +346,7 @@ function reduceProductVariantCreateFormData(
|
||||||
return selectValue(
|
return selectValue(
|
||||||
prevState,
|
prevState,
|
||||||
action.selectValue.attributeId,
|
action.selectValue.attributeId,
|
||||||
action.selectValue.attributeId
|
action.selectValue.valueId
|
||||||
);
|
);
|
||||||
case ProductVariantCreateReducerActionType.applyPriceToAll:
|
case ProductVariantCreateReducerActionType.applyPriceToAll:
|
||||||
return applyPriceToAll(prevState, action.applyPriceOrStockToAll.all);
|
return applyPriceToAll(prevState, action.applyPriceOrStockToAll.all);
|
||||||
|
@ -398,7 +402,7 @@ function reduceProductVariantCreateFormData(
|
||||||
case ProductVariantCreateReducerActionType.deleteVariant:
|
case ProductVariantCreateReducerActionType.deleteVariant:
|
||||||
return deleteVariant(prevState, action.deleteVariant.variantIndex);
|
return deleteVariant(prevState, action.deleteVariant.variantIndex);
|
||||||
case ProductVariantCreateReducerActionType.reload:
|
case ProductVariantCreateReducerActionType.reload:
|
||||||
return action.reload.data || createVariantMatrix(prevState);
|
return action.reload?.data || createVariantMatrix(prevState);
|
||||||
default:
|
default:
|
||||||
return prevState;
|
return prevState;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue