2021-10-14 10:47:41 +00:00
|
|
|
/// <reference types="cypress"/>
|
|
|
|
/// <reference types="../../support"/>
|
|
|
|
|
|
|
|
import { PRODUCT_DETAILS } from "../../elements/catalog/products/product-details";
|
|
|
|
import { PRODUCTS_LIST } from "../../elements/catalog/products/products-list";
|
|
|
|
import { SHARED_ELEMENTS } from "../../elements/shared/sharedElements";
|
|
|
|
import { demoProductsNames } from "../../fixtures/products";
|
|
|
|
import { productDetailsUrl, urlList } from "../../fixtures/urlList";
|
|
|
|
import { getFirstProducts } from "../../support/api/requests/Product";
|
2022-09-01 08:35:19 +00:00
|
|
|
import { deleteCollectionsStartsWith } from "../../support/api/utils/catalog/collectionsUtils";
|
|
|
|
import {
|
|
|
|
createNewProductWithNewDataAndDefaultChannel,
|
|
|
|
deleteProductsStartsWith,
|
|
|
|
iterateThroughThumbnails,
|
|
|
|
} from "../../support/api/utils/products/productsUtils";
|
2021-10-14 10:47:41 +00:00
|
|
|
|
2022-09-01 08:35:19 +00:00
|
|
|
describe("Tests for images", () => {
|
2022-06-27 09:30:51 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
cy.clearSessionData().loginUserViaRequest();
|
|
|
|
});
|
2021-10-14 10:47:41 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
it(
|
|
|
|
"Images on product list should be displayed",
|
2022-09-01 08:35:19 +00:00
|
|
|
{ tags: ["@products", "@allEnv", "@stable"] },
|
2022-06-27 09:30:51 +00:00
|
|
|
() => {
|
2021-10-14 10:47:41 +00:00
|
|
|
cy.addAliasToGraphRequest("ProductList")
|
|
|
|
.visit(urlList.products)
|
|
|
|
.wait("@ProductList")
|
2022-09-01 08:35:19 +00:00
|
|
|
.its("response.body.data.products.edges")
|
|
|
|
.then(products => {
|
|
|
|
cy.get(SHARED_ELEMENTS.skeleton).should("not.exist");
|
2022-01-31 08:37:49 +00:00
|
|
|
cy.get(PRODUCTS_LIST.productImage)
|
2021-10-14 10:47:41 +00:00
|
|
|
.each($image => {
|
|
|
|
cy.wrap($image)
|
|
|
|
.invoke("attr", "src")
|
|
|
|
.then(imageUrl => {
|
|
|
|
cy.request(imageUrl);
|
|
|
|
})
|
|
|
|
.then(respImage => {
|
|
|
|
expect(respImage.status).to.eq(200);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.then(images => {
|
|
|
|
const expectedProductsSvgAvatars =
|
|
|
|
products.length - images.length;
|
2022-09-01 08:35:19 +00:00
|
|
|
cy.get(PRODUCTS_LIST.imageIcon).should(
|
|
|
|
"have.length",
|
|
|
|
expectedProductsSvgAvatars,
|
|
|
|
);
|
2021-10-14 10:47:41 +00:00
|
|
|
});
|
|
|
|
});
|
2022-06-27 16:49:35 +00:00
|
|
|
},
|
2022-06-27 09:30:51 +00:00
|
|
|
);
|
2021-10-14 10:47:41 +00:00
|
|
|
|
2022-09-01 08:35:19 +00:00
|
|
|
it(
|
|
|
|
"Should display product image",
|
|
|
|
{ tags: ["@products", "@allEnv", "@stable"] },
|
|
|
|
() => {
|
|
|
|
getFirstProducts(1, demoProductsNames.carrotJuice)
|
|
|
|
.then(resp => {
|
|
|
|
const product = resp[0].node;
|
|
|
|
cy.visit(productDetailsUrl(product.id))
|
|
|
|
.get(PRODUCT_DETAILS.productImage)
|
|
|
|
.find("img")
|
|
|
|
.invoke("attr", "src");
|
|
|
|
})
|
|
|
|
.then(imageUrl => {
|
|
|
|
cy.request(imageUrl);
|
|
|
|
})
|
|
|
|
.then(imageResp => {
|
|
|
|
expect(imageResp.status).to.equal(200);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
2021-10-14 10:47:41 +00:00
|
|
|
|
2022-09-01 08:35:19 +00:00
|
|
|
it(
|
|
|
|
"Should upload saved image",
|
|
|
|
{ tags: ["@products", "@allEnv", "@stable"] },
|
|
|
|
() => {
|
|
|
|
const name = "CyImages";
|
2021-10-14 10:47:41 +00:00
|
|
|
|
2022-09-01 08:35:19 +00:00
|
|
|
deleteProductsStartsWith(name);
|
|
|
|
deleteCollectionsStartsWith(name);
|
|
|
|
cy.clearSessionData().loginUserViaRequest();
|
|
|
|
createNewProductWithNewDataAndDefaultChannel({ name })
|
|
|
|
.then(({ product }) => {
|
|
|
|
cy.visit(productDetailsUrl(product.id))
|
|
|
|
.waitForProgressBarToNotBeVisible()
|
|
|
|
.get(PRODUCT_DETAILS.uploadImageButton)
|
|
|
|
.click()
|
|
|
|
.get(PRODUCT_DETAILS.uploadSavedImagesButton)
|
|
|
|
.click()
|
|
|
|
.get(SHARED_ELEMENTS.fileInput)
|
|
|
|
.attachFile("images/saleorDemoProductSneakers.png")
|
|
|
|
.get(PRODUCT_DETAILS.productImage)
|
|
|
|
.find("img")
|
|
|
|
.invoke("attr", "src");
|
|
|
|
})
|
|
|
|
.then(imageUrl => {
|
|
|
|
cy.request(imageUrl);
|
|
|
|
})
|
|
|
|
.then(imageResp => {
|
|
|
|
expect(imageResp.status).to.equal(200);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
it(
|
|
|
|
"should create thumbnail url after entering image url",
|
|
|
|
{ tags: ["@products", "@allEnv", "@stable"] },
|
|
|
|
() => {
|
|
|
|
let failedRequests;
|
|
|
|
getFirstProducts(100)
|
|
|
|
.then(products => {
|
|
|
|
const productsWithThumbnails = products.filter(
|
|
|
|
product => product.node.thumbnail !== null,
|
|
|
|
);
|
|
|
|
failedRequests = iterateThroughThumbnails(productsWithThumbnails);
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
if (failedRequests && failedRequests.length > 0) {
|
|
|
|
throw new Error(failedRequests.join("\n"));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
2021-10-14 10:47:41 +00:00
|
|
|
});
|