Sku triggers variant name change (#3470)

* Sku triggers variant name change

* fixes product variants failing tests SALEOR_2901 and SALEOR_2902

* fix should be able to create several variants visible for the customers. TC: SALEOR_2902

---------

Co-authored-by: wojteknowacki <wojciech.nowacki@saleor.io>
This commit is contained in:
Patryk Andrzejewski 2023-05-05 11:34:35 +02:00 committed by GitHub
parent 65a329ebe4
commit 97b682c805
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 13 deletions

View file

@ -82,6 +82,8 @@ describe("As an admin I should be able to create variant", () => {
const name = `${startsWith}${faker.datatype.number()}`; const name = `${startsWith}${faker.datatype.number()}`;
const price = 10; const price = 10;
let createdProduct; let createdProduct;
// TODO fix name for proper one when problem with typing in grid will be solved - now only first letter of string is able to be typed in grid cell
const variantName = "A";
createProduct({ createProduct({
attributeId: attribute.id, attributeId: attribute.id,
@ -103,25 +105,27 @@ describe("As an admin I should be able to create variant", () => {
cy.visit( cy.visit(
`${urlList.products}${createdProduct.id}`, `${urlList.products}${createdProduct.id}`,
).waitForProgressBarToNotBeVisible(); ).waitForProgressBarToNotBeVisible();
addVariantToDataGrid(name); addVariantToDataGrid(variantName);
enterVariantEditPage(); enterVariantEditPage();
selectChannelsForVariant(); selectChannelsForVariant();
cy.addAliasToGraphRequest("VariantUpdate");
createVariant({ createVariant({
channelName: [defaultChannel.name, newChannel.name], channelName: [defaultChannel.name, newChannel.name],
sku: name, sku: name,
price, price,
attributeName: attributeValues[0], attributeName: attributeValues[0],
}); });
cy.wait("@VariantUpdate");
getProductVariants(createdProduct.id, defaultChannel.slug); getProductVariants(createdProduct.id, defaultChannel.slug);
}) })
.then(([variant]) => { .then(([variant]) => {
expect(variant).to.have.property("name", name); expect(variant).to.have.property("name", variantName);
expect(variant).to.have.property("price", price); expect(variant).to.have.property("price", price);
expect(variant).to.have.property("currency", "USD"); expect(variant).to.have.property("currency", "USD");
getProductVariants(createdProduct.id, newChannel.slug); getProductVariants(createdProduct.id, newChannel.slug);
}) })
.then(([variant]) => { .then(([variant]) => {
expect(variant).to.have.property("name", name); expect(variant).to.have.property("name", variantName);
expect(variant).to.have.property("price", price); expect(variant).to.have.property("price", price);
expect(variant).to.have.property("currency", "PLN"); expect(variant).to.have.property("currency", "PLN");
}); });
@ -164,6 +168,7 @@ describe("As an admin I should be able to create variant", () => {
() => { () => {
const name = `${startsWith}${faker.datatype.number()}`; const name = `${startsWith}${faker.datatype.number()}`;
const secondVariantSku = `${startsWith}${faker.datatype.number()}`; const secondVariantSku = `${startsWith}${faker.datatype.number()}`;
const secondVariantName = `${startsWith}${faker.datatype.number()}`;
const variants = [{ price: 7 }, { name: attributeValues[1], price: 16 }]; const variants = [{ price: 7 }, { name: attributeValues[1], price: 16 }];
let createdProduct; let createdProduct;
@ -182,25 +187,26 @@ describe("As an admin I should be able to create variant", () => {
cy.visit(`${urlList.products}${createdProduct.id}`); cy.visit(`${urlList.products}${createdProduct.id}`);
cy.get(PRODUCT_DETAILS.dataGridTable).scrollIntoView(); cy.get(PRODUCT_DETAILS.dataGridTable).scrollIntoView();
enterVariantEditPage(); enterVariantEditPage();
cy.get(PRODUCT_DETAILS.addVariantButton) cy.get(PRODUCT_DETAILS.addVariantButton)
.click() .click()
.then(() => { .then(() => {
cy.addAliasToGraphRequest("VariantCreate");
createVariant({ createVariant({
sku: secondVariantSku, sku: secondVariantSku,
attributeName: variants[1].name, attributeName: variants[1].name,
price: variants[1].price, price: variants[1].price,
channelName: defaultChannel.name, channelName: defaultChannel.name,
variantName: secondVariantName,
}); });
cy.wait("@VariantCreate");
getProductVariants(createdProduct.id, defaultChannel.slug); getProductVariants(createdProduct.id, defaultChannel.slug);
}) })
.then(([secondVariant, firstVariant]) => { .then(([secondVariant, firstVariant]) => {
expect(firstVariant).to.have.property("price", variants[0].price); expect(firstVariant).to.have.property("price", variants[0].price);
expect(firstVariant).to.have.property("name", "value"); expect(firstVariant).to.have.property("name", "value");
expect(firstVariant).to.have.property("currency", "USD"); expect(firstVariant).to.have.property("currency", "USD");
expect(secondVariant).to.have.property("name", secondVariantSku); expect(secondVariant).to.have.property("name", secondVariantName);
expect(secondVariant).to.have.property( expect(secondVariant).to.have.property(
"price", "price",
variants[1].price, variants[1].price,

View file

@ -80,7 +80,6 @@ export function fillUpVariantDetails({
.each(input => { .each(input => {
cy.wrap(input).type(costPrice); cy.wrap(input).type(costPrice);
}); });
if (variantName) { if (variantName) {
cy.get(VARIANTS_SELECTORS.variantNameInput).type(variantName); cy.get(VARIANTS_SELECTORS.variantNameInput).type(variantName);
} }

View file

@ -123,12 +123,6 @@ export const ProductStocks: React.FC<ProductStocksProps> = ({
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => { const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
onFormDataChange(e); onFormDataChange(e);
onFormDataChange({
target: {
name: "variantName",
value: e.target.value,
},
});
}; };
return ( return (