Saleor 4581 tests for products images (#1450)
* tests for images on product list * image on product details page should be displayed * test for upload image * fix collection utils import * fix creating test data * update jest
This commit is contained in:
parent
185a48b421
commit
5bee739872
11 changed files with 363 additions and 2 deletions
|
@ -19,5 +19,9 @@ export const PRODUCT_DETAILS = {
|
||||||
variantRow: "[data-test-id='product-variant-row']",
|
variantRow: "[data-test-id='product-variant-row']",
|
||||||
variantPrice: '[data-test="price"]',
|
variantPrice: '[data-test="price"]',
|
||||||
collectionRemoveButtons: '[data-test-id="collectionRemove"]',
|
collectionRemoveButtons: '[data-test-id="collectionRemove"]',
|
||||||
variantRow: "[data-test-id='product-variant-row']"
|
productImage: '[data-test="product-image"]',
|
||||||
|
uploadImageButton: '[data-test="button-upload-image"]',
|
||||||
|
uploadSavedImagesButton: '[data-test="uploadImages"]',
|
||||||
|
uploadMediaUrlButton: '[data-test="uploadMediaUrl"]',
|
||||||
|
saveUploadUrlButton: '[data-test-id="upload-url-button"]'
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,6 +4,8 @@ export const PRODUCTS_LIST = {
|
||||||
createProductBtn: "[data-test='add-product']",
|
createProductBtn: "[data-test='add-product']",
|
||||||
searchProducts: "[placeholder='Search Products...']",
|
searchProducts: "[placeholder='Search Products...']",
|
||||||
emptyProductRow: "[data-test-id='skeleton']",
|
emptyProductRow: "[data-test-id='skeleton']",
|
||||||
|
productImage: "[class='MuiAvatar-img']",
|
||||||
|
tableCellAvatar: "[data-test-id='tableCellAvatar']",
|
||||||
productRowElements: {
|
productRowElements: {
|
||||||
name: '[data-test="name"]',
|
name: '[data-test="name"]',
|
||||||
type: '[data-test="product-type"]',
|
type: '[data-test="product-type"]',
|
||||||
|
|
|
@ -10,6 +10,9 @@ export const SHARED_ELEMENTS = {
|
||||||
dialog: '[role="dialog"]',
|
dialog: '[role="dialog"]',
|
||||||
searchInput: '[data-test-id="searchInput"]',
|
searchInput: '[data-test-id="searchInput"]',
|
||||||
selectOption: '[data-test="selectFieldOption"]',
|
selectOption: '[data-test="selectFieldOption"]',
|
||||||
|
svgImage: "svg",
|
||||||
|
fileInput: 'input[type="file"]',
|
||||||
|
urlInput: 'input[type="url"]',
|
||||||
richTextEditor: {
|
richTextEditor: {
|
||||||
loader: '[class*="codex-editor__loader"]',
|
loader: '[class*="codex-editor__loader"]',
|
||||||
empty: '[class*="codex-editor--empty"]'
|
empty: '[class*="codex-editor--empty"]'
|
||||||
|
|
BIN
cypress/fixtures/images/saleorDemoProductSneakers.png
Normal file
BIN
cypress/fixtures/images/saleorDemoProductSneakers.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 200 KiB |
3
cypress/fixtures/products.js
Normal file
3
cypress/fixtures/products.js
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
export const demoProductsNames = {
|
||||||
|
appleJuice: "Apple Juice"
|
||||||
|
};
|
91
cypress/integration/products/images.js
Normal file
91
cypress/integration/products/images.js
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
/// <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";
|
||||||
|
import { loginDeleteProductsAndCreateNewOneWithNewDataAndDefaultChannel } from "../../support/api/utils/products/productsUtils";
|
||||||
|
import filterTests from "../../support/filterTests";
|
||||||
|
|
||||||
|
filterTests({ definedTags: ["all"] }, () => {
|
||||||
|
describe("Tests for images", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
cy.clearSessionData().loginUserViaRequest();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Images on product list should be displayed", () => {
|
||||||
|
cy.addAliasToGraphRequest("ProductList")
|
||||||
|
.visit(urlList.products)
|
||||||
|
.wait("@ProductList")
|
||||||
|
.its("response.body")
|
||||||
|
.then(resp => {
|
||||||
|
const data = resp.find(element =>
|
||||||
|
element.data.hasOwnProperty("products")
|
||||||
|
).data;
|
||||||
|
const products = data.products.edges;
|
||||||
|
cy.get(PRODUCTS_LIST.productImage)
|
||||||
|
.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;
|
||||||
|
cy.get(PRODUCTS_LIST.tableCellAvatar)
|
||||||
|
.find(SHARED_ELEMENTS.svgImage)
|
||||||
|
.should("have.length", expectedProductsSvgAvatars);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should display product image", () => {
|
||||||
|
getFirstProducts(1, demoProductsNames.appleJuice)
|
||||||
|
.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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should upload saved image", () => {
|
||||||
|
const name = "CyImages";
|
||||||
|
|
||||||
|
loginDeleteProductsAndCreateNewOneWithNewDataAndDefaultChannel({ name })
|
||||||
|
.then(product => {
|
||||||
|
cy.visit(productDetailsUrl(product.id))
|
||||||
|
.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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -24,6 +24,7 @@ export function getFirstProducts(first, search) {
|
||||||
.sendRequestWithQuery(query)
|
.sendRequestWithQuery(query)
|
||||||
.then(resp => resp.body.data.products.edges);
|
.then(resp => resp.body.data.products.edges);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateProduct(productId, input) {
|
export function updateProduct(productId, input) {
|
||||||
const mutation = `mutation {
|
const mutation = `mutation {
|
||||||
productUpdate(id:"${productId}", input:${stringify(input)} ){
|
productUpdate(id:"${productId}", input:${stringify(input)} ){
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import * as attributeRequest from "../../requests/Attribute";
|
import * as attributeRequest from "../../requests/Attribute";
|
||||||
import * as categoryRequest from "../../requests/Category";
|
import * as categoryRequest from "../../requests/Category";
|
||||||
|
import { createCollection } from "../../requests/Collections";
|
||||||
import * as productRequest from "../../requests/Product";
|
import * as productRequest from "../../requests/Product";
|
||||||
import {
|
import {
|
||||||
createTypeProduct,
|
createTypeProduct,
|
||||||
|
@ -7,6 +8,8 @@ import {
|
||||||
getProductTypes
|
getProductTypes
|
||||||
} from "../../requests/ProductType";
|
} from "../../requests/ProductType";
|
||||||
import { deleteAttributesStartsWith } from "../attributes/attributeUtils";
|
import { deleteAttributesStartsWith } from "../attributes/attributeUtils";
|
||||||
|
import { deleteCollectionsStartsWith } from "../catalog/collectionsUtils";
|
||||||
|
import { getDefaultChannel } from "../channelsUtils";
|
||||||
|
|
||||||
export function createProductInChannel({
|
export function createProductInChannel({
|
||||||
name,
|
name,
|
||||||
|
@ -103,3 +106,38 @@ export function deleteProductsStartsWith(startsWith) {
|
||||||
startsWith
|
startsWith
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function loginDeleteProductsAndCreateNewOneWithNewDataAndDefaultChannel({
|
||||||
|
name,
|
||||||
|
description = name
|
||||||
|
}) {
|
||||||
|
let defaultChannel;
|
||||||
|
let collection;
|
||||||
|
let attribute;
|
||||||
|
|
||||||
|
cy.clearSessionData().loginUserViaRequest();
|
||||||
|
deleteProductsStartsWith(name);
|
||||||
|
deleteCollectionsStartsWith(name);
|
||||||
|
return getDefaultChannel()
|
||||||
|
.then(channel => {
|
||||||
|
defaultChannel = channel;
|
||||||
|
createCollection(name);
|
||||||
|
})
|
||||||
|
.then(collectionResp => {
|
||||||
|
collection = collectionResp;
|
||||||
|
createTypeAttributeAndCategoryForProduct({ name });
|
||||||
|
})
|
||||||
|
.then(({ attribute: attributeResp, category, productType }) => {
|
||||||
|
attribute = attributeResp;
|
||||||
|
createProductInChannel({
|
||||||
|
attributeId: attribute.id,
|
||||||
|
categoryId: category.id,
|
||||||
|
productTypeId: productType.id,
|
||||||
|
channelId: defaultChannel.id,
|
||||||
|
name,
|
||||||
|
collectionId: collection.id,
|
||||||
|
description
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.then(({ product: productResp }) => productResp);
|
||||||
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import "./customCommands/sharedElementsOperations/progressBar.js";
|
||||||
import "./customCommands/sharedElementsOperations/selects.js";
|
import "./customCommands/sharedElementsOperations/selects.js";
|
||||||
import "./customCommands/sharedElementsOperations/tables";
|
import "./customCommands/sharedElementsOperations/tables";
|
||||||
import "cypress-mailhog";
|
import "cypress-mailhog";
|
||||||
|
import "cypress-file-upload";
|
||||||
|
|
||||||
import { urlList } from "../fixtures/urlList";
|
import { urlList } from "../fixtures/urlList";
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,11 @@ const TableCellAvatar: React.FC<TableCellAvatarProps> = props => {
|
||||||
const classes = useStyles(props);
|
const classes = useStyles(props);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TableCell className={classNames(classes.root, className)} {...rest}>
|
<TableCell
|
||||||
|
className={classNames(classes.root, className)}
|
||||||
|
data-test-id="tableCellAvatar"
|
||||||
|
{...rest}
|
||||||
|
>
|
||||||
<Avatar {...rest} />
|
<Avatar {...rest} />
|
||||||
</TableCell>
|
</TableCell>
|
||||||
);
|
);
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue