saleor-dashboard/cypress/integration/pages/pages.js

104 lines
3.3 KiB
JavaScript
Raw Normal View History

import faker from "faker";
import { createAttribute } from "../../apiRequests/Attribute";
import { getPage } from "../../apiRequests/Page";
import { createPageType } from "../../apiRequests/PageTypes";
import { attributesTypes, createPage } from "../../steps/pageSteps";
import { deleteAttributesStartsWith } from "../../utils/attributes/attributeUtils";
import { deletePageTypesStartsWith } from "../../utils/pageTypeUtils";
describe("Tests for pages", () => {
const startsWith = `Pages`;
const name = `${startsWith}${faker.datatype.number()}`;
let attribute;
const attributeValuesOnPage = {
NUMERIC: 1,
RICH_TEXT: faker.lorem.sentence(),
DROPDOWN: "value",
MULTISELECT: "value",
BOOLEAN: true
};
before(() => {
cy.clearSessionData().loginUserViaRequest();
deleteAttributesStartsWith(startsWith);
deletePageTypesStartsWith(startsWith);
createAttribute({ name, type: "PAGE_TYPE" }).then(attributeResp => {
attribute = attributeResp;
createPageType({ name, attributeId: attribute.id });
});
});
beforeEach(() => {
cy.clearSessionData().loginUserViaRequest();
});
it("should create not published page", () => {
const randomName = `${startsWith}${faker.datatype.number()}`;
createPage({ pageName: randomName, pageTypeName: name })
.then(page => {
getPage(page.id);
})
.then(page => {
expect(page.title).to.eq(randomName);
expect(page.isPublished).to.be.false;
expect(page.attributes[0].attribute.id).to.eq(attribute.id);
getPage(page.id, "token").should("be.null");
});
});
it("should create published page", () => {
const randomName = `${startsWith}${faker.datatype.number()}`;
createPage({ pageName: randomName, pageTypeName: name, isPublished: true })
.then(page => {
getPage(page.id, "token");
})
.then(page => {
expect(page.title).to.eq(randomName);
expect(page.isPublished).to.be.true;
expect(page.attributes[0].attribute.id).to.eq(attribute.id);
});
});
Object.keys(attributesTypes).forEach(attributeType => {
it(`should create page with ${attributeType} attribute`, () => {
const randomName = `${startsWith}${faker.datatype.number()}`;
const attributeValues = [attributeValuesOnPage[attributeType]];
createAttribute({
name: randomName,
type: "PAGE_TYPE",
inputType: attributeType,
attributeValues
}).then(attributeResp => {
attribute = attributeResp;
createPageType({ name: randomName, attributeId: attribute.id });
});
createPage({
pageName: randomName,
pageTypeName: randomName,
attributeType,
attributeValue: attributeValuesOnPage[attributeType]
})
.then(page => {
getPage(page.id);
})
.then(page => {
expect(page.attributes[0].values[0].inputType).to.eq(attributeType);
if (attributeType !== "BOOLEAN") {
expect(page.attributes[0].values[0].name).to.eq(
attributeValuesOnPage[attributeType].toString()
);
} else {
expect(page.attributes[0].values[0].name).to.includes(
"Yes".toString()
);
}
});
});
});
});