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