test for create page type (#1213)

This commit is contained in:
Karolina Rakoczy 2021-07-15 14:22:04 +03:00 committed by GitHub
parent f68410b7cb
commit 0c21788d61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 137 additions and 19 deletions

View file

@ -1,10 +1,14 @@
export function createAttribute(name, attributeValues = ["value"]) {
export function createAttribute({
name,
attributeValues = ["value"],
type = "PRODUCT_TYPE"
}) {
const values = attributeValues.map(element => `{name:"${element}"}`);
const mutation = `mutation{
attributeCreate(input:{
name:"${name}"
valueRequired:false
type:PRODUCT_TYPE
type:${type}
values: [${values}]
}){
attribute{

View file

@ -0,0 +1,28 @@
export function getPageType(pageTypeId) {
const query = `query{
pageType(id:"${pageTypeId}"){
id
name
attributes{
name
}
}
}`;
return cy.sendRequestWithQuery(query).its("body.data.pageType");
}
export function createPageType(name) {
const mutation = `mutation{
pageTypeCreate(input:{ name: "${name}"}){
pageType{
name
id
}
errors{
field
message
}
}
}`;
return cy.sendRequestWithQuery(mutation).its("body.data.pageTypeCreate");
}

View file

@ -0,0 +1,4 @@
export const PAGE_TYPE_DETAILS = {
nameInput: '[name="name"]',
assignAttributesButton: '[data-test-id="assignAttributes"]'
};

View file

@ -0,0 +1,3 @@
export const PAGE_TYPES_LIST = {
createPageTypeButton: '[data-test-id="createPageType"]'
};

View file

@ -19,7 +19,7 @@ describe("Tests for product types", () => {
before(() => {
cy.clearSessionData().loginUserViaRequest();
deleteProductsStartsWith(startsWith);
createAttribute(startsWith);
createAttribute({ name: startsWith });
});
beforeEach(() => {

View file

@ -0,0 +1,61 @@
import faker from "faker";
import { createAttribute } from "../../../apiRequests/Attribute";
import { createPageType, getPageType } from "../../../apiRequests/PageTypes";
import { PAGE_TYPE_DETAILS } from "../../../elements/pageTypes/pageTypeDetails";
import { PAGE_TYPES_LIST } from "../../../elements/pageTypes/pageTypesList";
import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors";
import { SHARED_ELEMENTS } from "../../../elements/shared/sharedElements";
import { assignElements } from "../../../steps/shared/assignElements";
import { confirmationMessageShouldDisappear } from "../../../steps/shared/confirmationMessage";
import { pageTypeDetailsUrl, urlList } from "../../../url/urlList";
describe("Tests for page types", () => {
const startsWith = "PageTypes";
beforeEach(() => {
cy.clearSessionData().loginUserViaRequest();
});
it("should create page type", () => {
const randomName = startsWith + faker.datatype.number();
cy.visit(urlList.pageTypes)
.get(PAGE_TYPES_LIST.createPageTypeButton)
.click()
.get(PAGE_TYPE_DETAILS.nameInput)
.type(randomName)
.addAliasToGraphRequest("PageTypeCreate")
.get(BUTTON_SELECTORS.confirm)
.click();
confirmationMessageShouldDisappear();
cy.wait("@PageTypeCreate")
.its("response.body.data.pageTypeCreate.pageType")
.then(pageType => {
getPageType(pageType.id);
})
.then(pageType => {
expect(pageType.name).to.eq(randomName);
});
});
it("should assign attribute", () => {
const randomName = startsWith + faker.datatype.number();
createAttribute({ name: randomName, type: "PAGE_TYPE" });
createPageType(randomName)
.then(({ pageType }) => {
cy.visit(pageTypeDetailsUrl(pageType.id))
.get(SHARED_ELEMENTS.progressBar)
.should("be.not.visible")
.get(PAGE_TYPE_DETAILS.assignAttributesButton)
.click();
assignElements(randomName, false);
confirmationMessageShouldDisappear();
getPageType(pageType.id);
})
.then(pageType => {
expect(pageType.attributes[0].name).to.eq(randomName);
});
});
});

View file

@ -62,7 +62,7 @@ describe("Purchase products with all products types", () => {
shippingMethod = shippingMethodResp;
}
);
createAttribute(name)
createAttribute({ name })
.then(attributeResp => {
attribute = attributeResp;
createCategory(name);

View file

@ -51,7 +51,7 @@ describe("Create product", () => {
before(() => {
cy.clearSessionData().loginUserViaRequest();
productUtils.deleteProductsStartsWith(startsWith);
createAttribute(name).then(attributeResp => {
createAttribute({ name }).then(attributeResp => {
attribute = attributeResp;
});
});

View file

@ -1,26 +1,28 @@
export const urlList = {
apiUri: Cypress.env("API_URI"),
addProduct: "products/add",
apps: "apps/",
attributes: "attributes/",
channels: "channels/",
categories: "categories/",
collections: "collections/",
configuration: "configuration/",
customers: "customers/",
draftOrders: "orders/drafts/",
homePage: "/",
newPassword: "new-password/",
orders: "orders/",
pageTypes: "page-types/",
permissionsGroups: "permission-groups/",
products: "products/",
addProduct: "products/add",
warehouses: "warehouses/",
productTypes: "product-types/",
shippingMethods: "shipping/",
sales: "discounts/sales/",
collections: "collections/",
vouchers: "discounts/vouchers/",
shippingMethods: "shipping/",
staffMembers: "staff/",
newPassword: "new-password/",
permissionsGroups: "permission-groups/",
categories: "categories/",
weightRete: "weight/",
attributes: "attributes/",
productTypes: "product-types/",
apps: "apps/",
customers: "customers/"
vouchers: "discounts/vouchers/",
warehouses: "warehouses/",
weightRete: "weight/"
};
export const productDetailsUrl = productId => `${urlList.products}${productId}`;
@ -48,4 +50,7 @@ export const warehouseDetailsUrl = warehouseId =>
export const productTypeDetailsUrl = productTypeId =>
`${urlList.productTypes}${productTypeId}`;
export const pageTypeDetailsUrl = pageTypeId =>
`${urlList.pageTypes}${pageTypeId}`;
export const appDetailsUrl = appId => `${urlList.apps}custom/${appId}`;

View file

@ -73,7 +73,7 @@ export function createTypeAttributeAndCategoryForProduct(
let productType;
let category;
return attributeRequest
.createAttribute(name, attributeValues)
.createAttribute({ name, attributeValues })
.then(attributeResp => {
attribute = attributeResp;
createTypeProduct({ name, attributeId: attributeResp.id });

View file

@ -91,6 +91,7 @@ const PageTypeAttributes: React.FC<PageTypeAttributesProps> = props => {
color="primary"
variant="text"
onClick={() => onAttributeAssign(AttributeTypeEnum[type])}
data-test-id="assignAttributes"
>
<FormattedMessage
defaultMessage="Assign attribute"

View file

@ -48,7 +48,12 @@ const PageTypeListPage: React.FC<PageTypeListPageProps> = ({
{intl.formatMessage(sectionNames.configuration)}
</AppHeader>
<PageHeader title={intl.formatMessage(sectionNames.pageTypes)}>
<Button color="primary" variant="contained" onClick={onAdd}>
<Button
color="primary"
variant="contained"
onClick={onAdd}
data-test-id="createPageType"
>
<FormattedMessage
defaultMessage="create page type"
description="button"

View file

@ -151492,6 +151492,7 @@ exports[`Storyshots Views / Page types / Page type details default 1`] = `
>
<button
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-text-id MuiButton-textPrimary-id"
data-test-id="assignAttributes"
tabindex="0"
type="button"
>
@ -152359,6 +152360,7 @@ exports[`Storyshots Views / Page types / Page type details form errors 1`] = `
>
<button
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-text-id MuiButton-textPrimary-id"
data-test-id="assignAttributes"
tabindex="0"
type="button"
>
@ -153228,6 +153230,7 @@ exports[`Storyshots Views / Page types / Page type details loading 1`] = `
>
<button
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-text-id MuiButton-textPrimary-id"
data-test-id="assignAttributes"
tabindex="0"
type="button"
>
@ -153615,6 +153618,7 @@ exports[`Storyshots Views / Page types / Page type details no attributes 1`] = `
>
<button
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-text-id MuiButton-textPrimary-id"
data-test-id="assignAttributes"
tabindex="0"
type="button"
>
@ -153985,6 +153989,7 @@ exports[`Storyshots Views / Page types / Page types list default 1`] = `
>
<button
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
data-test-id="createPageType"
tabindex="0"
type="button"
>
@ -154398,6 +154403,7 @@ exports[`Storyshots Views / Page types / Page types list loading 1`] = `
>
<button
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
data-test-id="createPageType"
tabindex="0"
type="button"
>
@ -154720,6 +154726,7 @@ exports[`Storyshots Views / Page types / Page types list no data 1`] = `
>
<button
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
data-test-id="createPageType"
tabindex="0"
type="button"
>