diff --git a/cypress-tests/cypress/e2e/admin/formBuilder/forms/createForm.cy.ts b/cypress-tests/cypress/e2e/admin/formBuilder/forms/createForm.cy.ts index 74c76dd7bd1..1fb37b66c5d 100644 --- a/cypress-tests/cypress/e2e/admin/formBuilder/forms/createForm.cy.ts +++ b/cypress-tests/cypress/e2e/admin/formBuilder/forms/createForm.cy.ts @@ -1,13 +1,11 @@ -import { customAlphabet } from "nanoid"; - -const nanoid = customAlphabet("abcdefghijklmnopqrstuvwxyz"); +import { generateAlphaLowerCaseId } from "@webiny/utils/generateId"; context("Forms Creation", () => { beforeEach(() => cy.login()); describe("Create Form", () => { - const newFormTitle = `Test form 1 ${nanoid(10)}`; - const newFormTitle2 = `Test form 2 ${nanoid(10)}`; + const newFormTitle = `Test form 1 ${generateAlphaLowerCaseId(10)}`; + const newFormTitle2 = `Test form 2 ${generateAlphaLowerCaseId(10)}`; it("should be able to create form, rename it, publish it, create new revision and delete it", () => { cy.visit("/form-builder/forms"); diff --git a/cypress-tests/cypress/e2e/admin/pageBuilder/blocks/pageBlockPreview.cy.ts b/cypress-tests/cypress/e2e/admin/pageBuilder/blocks/pageBlockPreview.cy.ts new file mode 100644 index 00000000000..ef4fb7a2e5d --- /dev/null +++ b/cypress-tests/cypress/e2e/admin/pageBuilder/blocks/pageBlockPreview.cy.ts @@ -0,0 +1,78 @@ +import { generateAlphaLowerCaseId } from "@webiny/utils/generateId"; + +context("Page Builder - Block Preview", () => { + beforeEach(() => { + cy.login(); + cy.pbDeleteAllBlocks(); + cy.pbDeleteAllBlockCategories(); + cy.pbDeleteAllTemplates(); + }); + const blockName = ["Block1Name"]; + const headerTitle = "Header test"; + const headerTitleUpdate = "Edited Header Text"; + const templateData = "tester"; + + const blockCategoryData = { + name: generateAlphaLowerCaseId(10), + slug: generateAlphaLowerCaseId(10), + icon: "icon-name", + description: generateAlphaLowerCaseId(10) + }; + + it("Should be able to programatically create and assert a block exists with a proper heading", () => { + cy.pbCreateCategoryAndBlocks({ + blockCategory: blockCategoryData, + blockNames: blockName, + content: { + type: "heading", + text: headerTitle + } + }); + + cy.visit("/page-builder/page-blocks"); + + // Asserts the programatically created block contains the correct data. + cy.findByTestId("default-data-list").within(() => { + cy.get("li") + .first() + .within(() => cy.contains(blockCategoryData.name).should("exist").click()); + }); + cy.contains(blockName[0]).should("exist"); + cy.contains(headerTitle).should("exist"); + + // Edits the current header for headerTitleUpdate. + cy.findByTestId("pb-blocks-list-block-edit-btn").click(); + cy.get('pb-block:contains("Header test")').click(); + cy.get('[contenteditable="true"]').clear().type(headerTitleUpdate).click(); + cy.contains("Save Changes").click(); + + // Asserts the newly edited header/block contains the right information. + cy.contains(blockCategoryData.name).click(); + cy.contains(blockName[0]).should("exist"); + cy.contains(headerTitleUpdate).should("exist"); + + // Navigate to the template page and create a new template. + cy.visit("/page-builder/page-templates"); + cy.findAllByTestId("pb-templates-list-new-template-btn").click(); + cy.findByRole("textbox", { name: "Title" }).type(templateData); + cy.findByRole("textbox", { name: "Slug" }).type(templateData); + cy.findByRole("textbox", { name: "Description" }).type(templateData); + cy.findByRole("button", { name: "Create" }).click(); + + // Assert the block is being properly displayed. + cy.findByTestId("pb-content-add-block-button").click(); + cy.findByTestId("pb-editor-page-blocks-list-item-block-1-name").contains(headerTitleUpdate); + + // Add the block to the template. + cy.contains(blockCategoryData.name).click(); + cy.get('button[label="Click to Add"]').click({ force: true }); + cy.contains("Save Changes").click(); + + // Assert the template is being displayed properly on the left and then the right side of the screen. + cy.findByTestId("default-data-list") + .find("li.mdc-list-item") + .should("contain", templateData); + cy.findByTestId("default-data-list").find("li.mdc-list-item").first().click(); + cy.get('[data-testid="pb-page-templates-form"]').contains(headerTitleUpdate); + }); +}); diff --git a/cypress-tests/cypress/e2e/admin/pageBuilder/blocks/pageBlocks.cy.ts b/cypress-tests/cypress/e2e/admin/pageBuilder/blocks/pageBlocks.cy.ts index c5430410ef8..9aa8fcdbf4e 100644 --- a/cypress-tests/cypress/e2e/admin/pageBuilder/blocks/pageBlocks.cy.ts +++ b/cypress-tests/cypress/e2e/admin/pageBuilder/blocks/pageBlocks.cy.ts @@ -1,7 +1,6 @@ -import { customAlphabet } from "nanoid"; +import { generateAlphaLowerCaseId } from "@webiny/utils/generateId"; context("Page Builder - Blocks", () => { - const nanoid = customAlphabet("abcdefghijklmnopqrstuvwxyz"); beforeEach(() => { cy.login(); cy.pbDeleteAllBlocks(); @@ -15,31 +14,31 @@ context("Page Builder - Blocks", () => { const blockNames4 = ["!#$%&/()="]; const blockCategoryData1 = { - name: nanoid(10).toLowerCase(), - slug: nanoid(10).toLowerCase(), + name: generateAlphaLowerCaseId(10), + slug: generateAlphaLowerCaseId(10), icon: "icon-name", - description: nanoid(10).toLowerCase() + description: generateAlphaLowerCaseId(10) }; const blockCategoryData2 = { - name: nanoid(10).toLowerCase(), - slug: nanoid(10).toLowerCase(), + name: generateAlphaLowerCaseId(10), + slug: generateAlphaLowerCaseId(10), icon: "icon-name", - description: nanoid(10).toLowerCase() + description: generateAlphaLowerCaseId(10) }; const blockCategoryData3 = { - name: nanoid(10).toLowerCase(), - slug: nanoid(10).toLowerCase(), + name: generateAlphaLowerCaseId(10), + slug: generateAlphaLowerCaseId(10), icon: "icon-name", - description: nanoid(10).toLowerCase() + description: generateAlphaLowerCaseId(10) }; const blockCategoryData4 = { - name: nanoid(10).toLowerCase(), - slug: nanoid(10).toLowerCase(), + name: generateAlphaLowerCaseId(10), + slug: generateAlphaLowerCaseId(10), icon: "icon-name", - description: nanoid(10).toLowerCase() + description: generateAlphaLowerCaseId(10) }; it("Should be able to use the search bar as expected", () => { diff --git a/cypress-tests/cypress/e2e/admin/pageBuilder/blocks/pageBlocksCrud.cy.ts b/cypress-tests/cypress/e2e/admin/pageBuilder/blocks/pageBlocksCrud.cy.ts index fe35a5cdd31..419829941d0 100644 --- a/cypress-tests/cypress/e2e/admin/pageBuilder/blocks/pageBlocksCrud.cy.ts +++ b/cypress-tests/cypress/e2e/admin/pageBuilder/blocks/pageBlocksCrud.cy.ts @@ -1,9 +1,8 @@ -import { customAlphabet } from "nanoid"; +import { generateAlphaLowerCaseId } from "@webiny/utils/generateId"; context("Page Builder - Blocks", () => { - const nanoid = customAlphabet("abcdefghijklmnopqrstuvwxyz"); - const blockCategoryName = nanoid(10); // Generate a random 10-character lowercase string - const blockCategorySlug = nanoid(10); // Generate another random 10-character lowercase string + const blockCategoryName = generateAlphaLowerCaseId(10); + const blockCategorySlug = generateAlphaLowerCaseId(10); beforeEach(() => { cy.login(); diff --git a/cypress-tests/cypress/e2e/admin/pageBuilder/blocks/pageBlocksExportImport.cy.ts b/cypress-tests/cypress/e2e/admin/pageBuilder/blocks/pageBlocksExportImport.cy.ts index ead2e937481..209a1261aff 100644 --- a/cypress-tests/cypress/e2e/admin/pageBuilder/blocks/pageBlocksExportImport.cy.ts +++ b/cypress-tests/cypress/e2e/admin/pageBuilder/blocks/pageBlocksExportImport.cy.ts @@ -1,8 +1,6 @@ -import { customAlphabet } from "nanoid"; +import { generateAlphaLowerCaseId } from "@webiny/utils/generateId"; context("Page Builder - Blocks Export/Import", () => { - const nanoid = customAlphabet("abcdefghijklmnopqrstuvwxyz"); - beforeEach(() => { cy.login(); cy.pbDeleteAllBlocks(); @@ -10,31 +8,29 @@ context("Page Builder - Blocks Export/Import", () => { }); const blockNames1 = ["Block1Name"]; - const blockNames2 = ["Block1Name", "Block2Name"]; - const blockNames3 = ["Block1Name", "Block2Name", "Block3Name"]; //Data used for creating multible block categories const blockCategoryData1 = { - name: nanoid(10).toLowerCase(), - slug: nanoid(10).toLowerCase(), + name: generateAlphaLowerCaseId(10), + slug: generateAlphaLowerCaseId(10), icon: "icon-name", - description: nanoid(10).toLowerCase() + description: generateAlphaLowerCaseId(10) }; const blockCategoryData2 = { - name: nanoid(10).toLowerCase(), - slug: nanoid(10).toLowerCase(), + name: generateAlphaLowerCaseId(10), + slug: generateAlphaLowerCaseId(10), icon: "icon-name", - description: nanoid(10).toLowerCase() + description: generateAlphaLowerCaseId(10) }; const blockCategoryData3 = { - name: nanoid(10).toLowerCase(), - slug: nanoid(10).toLowerCase(), + name: generateAlphaLowerCaseId(10), + slug: generateAlphaLowerCaseId(10), icon: "icon-name", - description: nanoid(10).toLowerCase() + description: generateAlphaLowerCaseId(10) }; it("Test the importation and exportation of all blocks", () => { diff --git a/cypress-tests/cypress/e2e/admin/pageBuilder/category/pageCategoriesCrud.cy.ts b/cypress-tests/cypress/e2e/admin/pageBuilder/category/pageCategoriesCrud.cy.ts index e871f131208..b96ad50e27c 100644 --- a/cypress-tests/cypress/e2e/admin/pageBuilder/category/pageCategoriesCrud.cy.ts +++ b/cypress-tests/cypress/e2e/admin/pageBuilder/category/pageCategoriesCrud.cy.ts @@ -1,15 +1,14 @@ -import { customAlphabet } from "nanoid"; +import { generateAlphaLowerCaseId } from "@webiny/utils/generateId"; context("Page Builder - Categories CRUD", () => { - const nanoid = customAlphabet("abcdefghijklmnopqrstuvwxyz"); - const categoryName = nanoid(6); - const categoryNameEdited = nanoid(6); - const categorySlug = nanoid(6); - const categoryUrl = "/" + nanoid(6) + "/"; - const categoryUrlEdited = "/" + nanoid(6) + "/"; - const categoryNameValidate = nanoid(6); - const categorySlugValidate = nanoid(6); - const categoryUrlValidate = "/" + nanoid(6) + "/"; + const categoryName = generateAlphaLowerCaseId(6); + const categoryNameEdited = generateAlphaLowerCaseId(6); + const categorySlug = generateAlphaLowerCaseId(6); + const categoryUrl = "/" + generateAlphaLowerCaseId(6) + "/"; + const categoryUrlEdited = "/" + generateAlphaLowerCaseId(6) + "/"; + const categoryNameValidate = generateAlphaLowerCaseId(6); + const categorySlugValidate = generateAlphaLowerCaseId(6); + const categoryUrlValidate = "/" + generateAlphaLowerCaseId(6) + "/"; beforeEach(() => { cy.login(); diff --git a/cypress-tests/cypress/e2e/admin/pageBuilder/menus/menuCrud.cy.ts b/cypress-tests/cypress/e2e/admin/pageBuilder/menus/menuCrud.cy.ts index 7920a8dea7f..8190f3d60fb 100644 --- a/cypress-tests/cypress/e2e/admin/pageBuilder/menus/menuCrud.cy.ts +++ b/cypress-tests/cypress/e2e/admin/pageBuilder/menus/menuCrud.cy.ts @@ -1,9 +1,8 @@ -import { customAlphabet } from "nanoid"; +import { generateAlphaLowerCaseId } from "@webiny/utils/generateId"; context("Page Builder - Menu CRUD", () => { - const nanoid = customAlphabet("abcdefghijklmnopqrstuvwxyz"); - const menuName = nanoid(10); - const menuSlug = nanoid(10); + const menuName = generateAlphaLowerCaseId(10); + const menuSlug = generateAlphaLowerCaseId(10); const menuNameEdit = "Testing Menu123"; const menuDescEdit = "This is an edited description."; diff --git a/cypress-tests/cypress/e2e/admin/pageBuilder/menus/menuItems.cy.ts b/cypress-tests/cypress/e2e/admin/pageBuilder/menus/menuItems.cy.ts index 2bd8a3411b0..162e9214dcc 100644 --- a/cypress-tests/cypress/e2e/admin/pageBuilder/menus/menuItems.cy.ts +++ b/cypress-tests/cypress/e2e/admin/pageBuilder/menus/menuItems.cy.ts @@ -1,19 +1,17 @@ -import { customAlphabet } from "nanoid"; +import { generateAlphaLowerCaseId } from "@webiny/utils/generateId"; context("Page Builder - Menu Items", () => { - const nanoid = customAlphabet("abcdefghijklmnopqrstuvwxyz"); - - const pageListName = nanoid(10); + const pageListName = generateAlphaLowerCaseId(10); const pageListNameEdit = pageListName + "-edit"; - const linkName = nanoid(10); + const linkName = generateAlphaLowerCaseId(10); const linkURL = `/${linkName}/`; const linkNameEdit = linkName + "-edit"; const linkURLEdit = `/${linkNameEdit}/`; - const folderName = nanoid(10); + const folderName = generateAlphaLowerCaseId(10); const folderNameEdit = folderName + "-edit"; - const pageNameNew = nanoid(10); + const pageNameNew = generateAlphaLowerCaseId(10); const pageNameNewEdit = pageNameNew + "-edit"; const menuData = { diff --git a/cypress-tests/cypress/e2e/admin/pageBuilder/menus/pagesListMenuItemType.cy.js b/cypress-tests/cypress/e2e/admin/pageBuilder/menus/pagesListMenuItemType.cy.js index e271a861a72..902f3174195 100644 --- a/cypress-tests/cypress/e2e/admin/pageBuilder/menus/pagesListMenuItemType.cy.js +++ b/cypress-tests/cypress/e2e/admin/pageBuilder/menus/pagesListMenuItemType.cy.js @@ -92,7 +92,7 @@ describe.skip("Menus Module", () => { }); it(`Step 2: assert that menu item and pages are shown (descending order)`, () => { - cy.visit(Cypress.env("WEBSITE_URL") + `/page-${id}-${0}/`); + cy.visitWebsite(`/page-${id}-${0}/`); cy.reloadUntil(() => { // We wait until the document contains the newly added menu. @@ -130,7 +130,7 @@ describe.skip("Menus Module", () => { }); it(`Step 4: assert that menu item and pages are shown (ascending order)`, () => { - cy.visit(Cypress.env("WEBSITE_URL") + `/page-${id}-${0}/`); + cy.visitWebsite(`/page-${id}-${0}/`); cy.reloadUntil(() => { // We wait until the document contains the newly added menu. @@ -162,7 +162,7 @@ describe.skip("Menus Module", () => { }); it(`Step 6: assert that the pages list menu item does not exist`, () => { - cy.visit(Cypress.env("WEBSITE_URL") + `/page-${id}-${0}/`); + cy.visitWebsite(`/page-${id}-${0}/`); cy.reloadUntil(() => { // We wait until the document contains the newly added menu. diff --git a/cypress-tests/cypress/e2e/admin/pageBuilder/menus/pagesListMenuItemType.cy.ts b/cypress-tests/cypress/e2e/admin/pageBuilder/menus/pagesListMenuItemType.cy.ts index 48e3d06d3fe..5247f92d8bf 100644 --- a/cypress-tests/cypress/e2e/admin/pageBuilder/menus/pagesListMenuItemType.cy.ts +++ b/cypress-tests/cypress/e2e/admin/pageBuilder/menus/pagesListMenuItemType.cy.ts @@ -84,7 +84,7 @@ describe("Page Builder - List Menu Item Types", () => { cy.findByText("Menu saved successfully."); }); it(`Step 2: assert that menu item and pages are shown (descending order)`, () => { - cy.visit(Cypress.env("WEBSITE_URL") + `/page-${id}-${0}/`); + cy.visitWebsite(`/page-${id}-${0}/`); cy.reloadUntil(() => { // We wait until the document contains the newly added menu. @@ -122,7 +122,7 @@ describe("Page Builder - List Menu Item Types", () => { }); it(`Step 4: assert that menu item and pages are shown (ascending order)`, () => { - cy.visit(Cypress.env("WEBSITE_URL") + `/page-${id}-${0}/`); + cy.visitWebsite(`/page-${id}-${0}/`); cy.reloadUntil(() => { // We wait until the document contains the newly added menu. @@ -154,7 +154,7 @@ describe("Page Builder - List Menu Item Types", () => { }); it(`Step 6: assert that the pages list menu item does not exist`, () => { - cy.visit(Cypress.env("WEBSITE_URL") + `/page-${id}-${0}/`); + cy.visitWebsite(`/page-${id}-${0}/`); cy.reloadUntil(() => { // We wait until the document contains the newly added menu. diff --git a/cypress-tests/cypress/e2e/admin/pageBuilder/templates/pageTemplatesCrud.cy.ts b/cypress-tests/cypress/e2e/admin/pageBuilder/templates/pageTemplatesCrud.cy.ts index 0396446ebcf..c86f001b0e2 100644 --- a/cypress-tests/cypress/e2e/admin/pageBuilder/templates/pageTemplatesCrud.cy.ts +++ b/cypress-tests/cypress/e2e/admin/pageBuilder/templates/pageTemplatesCrud.cy.ts @@ -1,9 +1,8 @@ -import { customAlphabet } from "nanoid"; +import { generateAlphaLowerCaseId } from "@webiny/utils/generateId"; context("Page Builder - Template CRUD", () => { - const nanoid = customAlphabet("abcdefghijklmnopqrstuvwxyz"); - const templateName = nanoid(10); - const templateNameEdit = nanoid(10); + const templateName = generateAlphaLowerCaseId(10); + const templateNameEdit = generateAlphaLowerCaseId(10); beforeEach(() => { cy.login(); cy.pbDeleteAllTemplates(); diff --git a/cypress-tests/cypress/e2e/admin/pageBuilder/templates/pageTemplatesDialogSearch.cy.ts b/cypress-tests/cypress/e2e/admin/pageBuilder/templates/pageTemplatesDialogSearch.cy.ts index 8418a812957..d4d8913b3fe 100644 --- a/cypress-tests/cypress/e2e/admin/pageBuilder/templates/pageTemplatesDialogSearch.cy.ts +++ b/cypress-tests/cypress/e2e/admin/pageBuilder/templates/pageTemplatesDialogSearch.cy.ts @@ -1,40 +1,39 @@ -import { customAlphabet } from "nanoid"; +import { generateAlphaLowerCaseId } from "@webiny/utils/generateId"; context("Page Builder - Page Templates Dialog Search", () => { - const nanoid = customAlphabet("abcdefghijklmnopqrstuvwxyz"); - const titleString1 = nanoid(6); - const titleString2 = nanoid(6); - const titleString3 = nanoid(6); + const titleString1 = generateAlphaLowerCaseId(10); + const titleString2 = generateAlphaLowerCaseId(10); + const titleString3 = generateAlphaLowerCaseId(10); const titleString4 = "!#$%&/()=?*"; const pageTemplateData1 = { title: titleString1, - slug: nanoid(6), - description: nanoid(6), + slug: generateAlphaLowerCaseId(10), + description: generateAlphaLowerCaseId(10), tags: [], layout: "static", pageCategory: "static" }; const pageTemplateData2 = { title: titleString2, - slug: nanoid(6), - description: nanoid(6), + slug: generateAlphaLowerCaseId(10), + description: generateAlphaLowerCaseId(10), tags: [], layout: "static", pageCategory: "static" }; const pageTemplateData3 = { title: titleString3, - slug: nanoid(6), - description: nanoid(6), + slug: generateAlphaLowerCaseId(10), + description: generateAlphaLowerCaseId(10), tags: [], layout: "static", pageCategory: "static" }; const pageTemplateData4 = { title: titleString4, - slug: nanoid(6), - description: nanoid(6), + slug: generateAlphaLowerCaseId(10), + description: generateAlphaLowerCaseId(10), tags: [], layout: "static", pageCategory: "static" diff --git a/cypress-tests/cypress/e2e/admin/pageBuilder/templates/pageTemplatesExportImport.cy.ts b/cypress-tests/cypress/e2e/admin/pageBuilder/templates/pageTemplatesExportImport.cy.ts index 12d1cd1b025..c9aed80c595 100644 --- a/cypress-tests/cypress/e2e/admin/pageBuilder/templates/pageTemplatesExportImport.cy.ts +++ b/cypress-tests/cypress/e2e/admin/pageBuilder/templates/pageTemplatesExportImport.cy.ts @@ -1,40 +1,39 @@ -import { customAlphabet } from "nanoid"; +import { generateAlphaLowerCaseId } from "@webiny/utils/generateId"; context("Page Builder - Template Export&Import", () => { - const nanoid = customAlphabet("abcdefghijklmnopqrstuvwxyz"); let url = ""; - const titleString1 = nanoid(6); - const titleString2 = nanoid(6); - const titleString3 = nanoid(6); + const titleString1 = generateAlphaLowerCaseId(10); + const titleString2 = generateAlphaLowerCaseId(10); + const titleString3 = generateAlphaLowerCaseId(10); const titleString4 = "!#$%&/()=?*"; const pageTemplateData1 = { title: titleString1, - slug: nanoid(6), - description: nanoid(6), + slug: generateAlphaLowerCaseId(10), + description: generateAlphaLowerCaseId(10), tags: [], layout: "static", pageCategory: "static" }; const pageTemplateData2 = { title: titleString2, - slug: nanoid(6), - description: nanoid(6), + slug: generateAlphaLowerCaseId(10), + description: generateAlphaLowerCaseId(10), tags: [], layout: "static", pageCategory: "static" }; const pageTemplateData3 = { title: titleString3, - slug: nanoid(6), - description: nanoid(6), + slug: generateAlphaLowerCaseId(10), + description: generateAlphaLowerCaseId(10), tags: [], layout: "static", pageCategory: "static" }; const pageTemplateData4 = { title: titleString4, - slug: nanoid(6), - description: nanoid(6), + slug: generateAlphaLowerCaseId(10), + description: generateAlphaLowerCaseId(10), tags: [], layout: "static", pageCategory: "static" diff --git a/cypress-tests/cypress/e2e/admin/pageBuilder/templates/pageTemplatesSearch.cy.ts b/cypress-tests/cypress/e2e/admin/pageBuilder/templates/pageTemplatesSearch.cy.ts index ff021bd74c4..7efd66f0e4e 100644 --- a/cypress-tests/cypress/e2e/admin/pageBuilder/templates/pageTemplatesSearch.cy.ts +++ b/cypress-tests/cypress/e2e/admin/pageBuilder/templates/pageTemplatesSearch.cy.ts @@ -1,39 +1,37 @@ -import { customAlphabet } from "nanoid"; - +import { generateAlphaLowerCaseId } from "@webiny/utils/generateId"; context("Page Builder - Template Search", () => { - const nanoid = customAlphabet("abcdefghijklmnopqrstuvwxyz"); - const titleString1 = nanoid(6); - const titleString2 = nanoid(6); - const titleString3 = nanoid(6); + const titleString1 = generateAlphaLowerCaseId(10); + const titleString2 = generateAlphaLowerCaseId(10); + const titleString3 = generateAlphaLowerCaseId(10); const titleString4 = "!#$%&/()=?*"; const pageTemplateData1 = { title: titleString1, - slug: nanoid(6), - description: nanoid(6), + slug: generateAlphaLowerCaseId(10), + description: generateAlphaLowerCaseId(10), tags: [], layout: "static", pageCategory: "static" }; const pageTemplateData2 = { title: titleString2, - slug: nanoid(6), - description: nanoid(6), + slug: generateAlphaLowerCaseId(10), + description: generateAlphaLowerCaseId(10), tags: [], layout: "static", pageCategory: "static" }; const pageTemplateData3 = { title: titleString3, - slug: nanoid(6), - description: nanoid(6), + slug: generateAlphaLowerCaseId(10), + description: generateAlphaLowerCaseId(10), tags: [], layout: "static", pageCategory: "static" }; const pageTemplateData4 = { title: titleString4, - slug: nanoid(6), - description: nanoid(6), + slug: generateAlphaLowerCaseId(10), + description: generateAlphaLowerCaseId(10), tags: [], layout: "static", pageCategory: "static" diff --git a/cypress-tests/cypress/e2e/admin/pageBuilder/templates/pageTemplatesSorting.cy.ts b/cypress-tests/cypress/e2e/admin/pageBuilder/templates/pageTemplatesSorting.cy.ts index 8c03f1ea847..c314b019191 100644 --- a/cypress-tests/cypress/e2e/admin/pageBuilder/templates/pageTemplatesSorting.cy.ts +++ b/cypress-tests/cypress/e2e/admin/pageBuilder/templates/pageTemplatesSorting.cy.ts @@ -1,7 +1,6 @@ -import { customAlphabet } from "nanoid"; +import { generateAlphaLowerCaseId } from "@webiny/utils/generateId"; context("Page Builder - Template Sorting", () => { - const nanoid = customAlphabet("abcdefghijklmnopqrstuvwxyz"); const titleString1 = "ABC"; const titleString2 = "DEF"; const titleString3 = "GHI"; @@ -9,32 +8,32 @@ context("Page Builder - Template Sorting", () => { const pageTemplateData1 = { title: titleString1, - slug: nanoid(6), - description: nanoid(6), + slug: generateAlphaLowerCaseId(10), + description: generateAlphaLowerCaseId(10), tags: [], layout: "static", pageCategory: "static" }; const pageTemplateData2 = { title: titleString2, - slug: nanoid(6), - description: nanoid(6), + slug: generateAlphaLowerCaseId(10), + description: generateAlphaLowerCaseId(10), tags: [], layout: "static", pageCategory: "static" }; const pageTemplateData3 = { title: titleString3, - slug: nanoid(6), - description: nanoid(6), + slug: generateAlphaLowerCaseId(10), + description: generateAlphaLowerCaseId(10), tags: [], layout: "static", pageCategory: "static" }; const pageTemplateData4 = { title: titleString4, - slug: nanoid(6), - description: nanoid(6), + slug: generateAlphaLowerCaseId(10), + description: generateAlphaLowerCaseId(10), tags: [], layout: "static", pageCategory: "static" diff --git a/cypress-tests/cypress/e2e/admin/pageBuilder/templates/templatesVisible.cy.ts b/cypress-tests/cypress/e2e/admin/pageBuilder/templates/templatesVisible.cy.ts index c2c2931f7e8..c840292966e 100644 --- a/cypress-tests/cypress/e2e/admin/pageBuilder/templates/templatesVisible.cy.ts +++ b/cypress-tests/cypress/e2e/admin/pageBuilder/templates/templatesVisible.cy.ts @@ -1,11 +1,10 @@ -import { customAlphabet } from "nanoid"; +import { generateAlphaLowerCaseId } from "@webiny/utils/generateId"; context("Page Builder - Template Visibility", () => { - const nanoid = customAlphabet("abcdefghijklmnopqrstuvwxyz"); const pageTemplateData1 = { - title: nanoid(6), - slug: nanoid(6), - description: nanoid(6), + title: generateAlphaLowerCaseId(10), + slug: generateAlphaLowerCaseId(10), + description: generateAlphaLowerCaseId(10), tags: [], layout: "static", pageCategory: "static" diff --git a/cypress-tests/cypress/integration/admin/pageBuilder/blocks/pageBlocksExportImport.cy.ts b/cypress-tests/cypress/integration/admin/pageBuilder/blocks/pageBlocksExportImport.cy.ts deleted file mode 100644 index cb3fed5cd1b..00000000000 --- a/cypress-tests/cypress/integration/admin/pageBuilder/blocks/pageBlocksExportImport.cy.ts +++ /dev/null @@ -1,122 +0,0 @@ -import { customAlphabet } from "nanoid"; - -context("Page Builder - Blocks Export/Import", () => { - const nanoid = customAlphabet("abcdefghijklmnopqrstuvwxyz"); - - beforeEach(() => { - cy.login(); - cy.pbDeleteAllBlocks(); - cy.pbDeleteAllBlockCategories(); - }); - - const blockNames1 = ["Block1Name"]; - - const blockNames2 = ["Block1Name", "Block2Name"]; - - const blockNames3 = ["Block1Name", "Block2Name", "Block3Name"]; - - //Data used for creating multible block categories - const blockCategoryData1 = { - name: nanoid(10).toLowerCase(), - slug: nanoid(10).toLowerCase(), - icon: "icon-name", - description: nanoid(10).toLowerCase() - }; - - const blockCategoryData2 = { - name: nanoid(10).toLowerCase(), - slug: nanoid(10).toLowerCase(), - icon: "icon-name", - description: nanoid(10).toLowerCase() - }; - - const blockCategoryData3 = { - name: nanoid(10).toLowerCase(), - slug: nanoid(10).toLowerCase(), - icon: "icon-name", - description: nanoid(10).toLowerCase() - }; - - it("Test the importation and exportation of all blocks", () => { - cy.visit("/page-builder/page-blocks"); - // Exports all created data and saves the exported string value. - cy.pbCreateCategoryAndBlocks({ - blockCategory: blockCategoryData1, - blockNames: blockNames1 - }); - cy.pbCreateCategoryAndBlocks({ - blockCategory: blockCategoryData2, - blockNames: blockNames2 - }); - cy.pbCreateCategoryAndBlocks({ - blockCategory: blockCategoryData3, - blockNames: blockNames3 - }); - - cy.findByPlaceholderText("Search blocks").should("exist"); - cy.findByTestId("pb-blocks-list-options-menu").click(); - cy.findByText("Export all blocks").click(); - cy.findByText("Your export is now ready!").should("exist"); - - cy.get("pb-blocks-export-dialog-export-url") - .invoke("text") - .then(text => { - const url = text.trim(); - console.log(url); - cy.pbDeleteAllBlockCategories(); - cy.pbDeleteAllBlocks(); - - cy.visit("/page-builder/page-blocks"); - cy.findByPlaceholderText("Search blocks").should("exist"); - cy.findByTestId("pb-blocks-list-options-menu").click(); - cy.findByRole("menuitem", { name: "Import blocks" }).click(); - cy.contains("Paste File URL").should("exist").click(); - cy.contains("File URL").type(url); - cy.contains("Continue").click(); - cy.findByText("All blocks have been imported").should("exist"); - cy.contains("Continue").click(); - - // Validation of imported blocks and categories. - cy.contains(blockCategoryData1.name).should("exist"); - cy.contains(blockCategoryData2.name).should("exist"); - cy.contains(blockCategoryData3.name).should("exist"); - - cy.contains(blockCategoryData1.name).click(); - cy.contains(blockNames1[0]).should("exist"); - cy.contains(blockCategoryData1.name).click(); - cy.contains(blockNames2[0]).should("exist"); - cy.contains(blockCategoryData1.name).click(); - cy.contains(blockNames3[0]).should("exist"); - }); - }); - - it("Test the importation and exportation functionality of the import block button", () => { - cy.visit("/page-builder/page-blocks"); - cy.pbCreateCategoryAndBlocks({ - blockCategory: blockCategoryData1, - blockNames: blockNames1 - }); - - cy.contains(blockCategoryData1.name).click(); - cy.findByTestId("pb-blocks-list-block-export-btn").click(); - cy.findByText("Your export is now ready!").should("exist"); - cy.get("span.link-text.mdc-typography--body2") - .invoke("text") - .then(url => { - cy.pbDeleteAllBlockCategories(); - cy.pbDeleteAllBlocks(); - - cy.visit("/page-builder/page-blocks"); - cy.findByTestId("pb-blocks-list-options-menu").click(); - cy.findByRole("menuitem", { name: "Import blocks" }).click(); - cy.contains("Paste File URL").should("exist").click(); - cy.contains("File URL").type(url); - cy.contains("Continue").click(); - cy.findByText("All blocks have been imported").should("exist"); - cy.contains("Continue").click(); - - cy.visit("/page-builder/page-blocks"); - cy.contains(blockCategoryData1.name).should("exist"); - }); - }); -}); diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.js index e8d92d8aedb..78a86b95761 100644 --- a/cypress-tests/cypress/support/commands.js +++ b/cypress-tests/cypress/support/commands.js @@ -17,6 +17,7 @@ import "./pageBuilder/pbCreateCategoryAndBlocks"; import "./pageBuilder/pbUpdatePage"; import "./pageBuilder/pbCreateCategory"; import "./pageBuilder/pbDeleteAllCategories"; +import "./pageBuilder/pbUpdatePageBlock"; import "./pageBuilder/pbPublishPage"; import "./pageBuilder/pbDeleteAllPages"; import "./pageBuilder/pbDeletePage"; @@ -29,6 +30,7 @@ import "./pageBuilder/pbDeleteAllBlockCategories"; import "./pageBuilder/pbListBlockCategories"; import "./pageBuilder/pbCreateCategory"; import "./pageBuilder/pbDeleteCategory"; +import "./visitWebsite"; import "./headlessCms/cmsCreateContentModel"; import "./headlessCms/cmsUpdateContentModel"; import "./headlessCms/cmsDeleteContentModel"; diff --git a/cypress-tests/cypress/support/pageBuilder/pbCreateCategoryAndBlocks.ts b/cypress-tests/cypress/support/pageBuilder/pbCreateCategoryAndBlocks.ts index 5f521d912dc..95ea2b35f54 100644 --- a/cypress-tests/cypress/support/pageBuilder/pbCreateCategoryAndBlocks.ts +++ b/cypress-tests/cypress/support/pageBuilder/pbCreateCategoryAndBlocks.ts @@ -1,8 +1,15 @@ import { gqlClient } from "../utils"; +import { createHeadingBlock } from "./pbCreateCategoryAndBlocks/createHeadingBlock"; interface CreateCategoryAndBlocksParams { blockCategory: Record; blockNames: string[]; + content?: Content; +} + +interface Content { + type: "heading"; + text: string; } declare global { @@ -16,6 +23,16 @@ declare global { } } +const contentData = (contentText: string, contentType: string) => { + switch (contentType) { + case "heading": + return createHeadingBlock(contentText); + + default: + return {}; + } +}; + const CREATE_BLOCK_CATEGORY_MUTATION = /* GraphQL */ ` mutation CreateBlockCategory($data: PbBlockCategoryInput!) { pageBuilder { @@ -67,7 +84,7 @@ const CRATE_BLOCK_MUTATION = /* GraphQL */ ` } `; -Cypress.Commands.add("pbCreateCategoryAndBlocks", ({ blockCategory, blockNames }) => { +Cypress.Commands.add("pbCreateCategoryAndBlocks", ({ blockCategory, blockNames, content }) => { cy.login().then(user => { const createCategoryPromise = gqlClient .request({ @@ -86,15 +103,11 @@ Cypress.Commands.add("pbCreateCategoryAndBlocks", ({ blockCategory, blockNames } gqlClient.request({ query: CRATE_BLOCK_MUTATION, variables: { + id: "xyz", data: { name: blockName, blockCategory: categorySlug, - content: { - id: "xyz", - type: "block", - data: {}, - elements: [] - } + content: content ? contentData(content.text, content.type) : {} } }, authToken: user.idToken.jwtToken diff --git a/cypress-tests/cypress/support/pageBuilder/pbCreateCategoryAndBlocks/createHeadingBlock.ts b/cypress-tests/cypress/support/pageBuilder/pbCreateCategoryAndBlocks/createHeadingBlock.ts new file mode 100644 index 00000000000..3e50973bc2f --- /dev/null +++ b/cypress-tests/cypress/support/pageBuilder/pbCreateCategoryAndBlocks/createHeadingBlock.ts @@ -0,0 +1,35 @@ +export const createHeadingBlock = (blockText: string) => { + return { + type: "block", + data: {}, + elements: [ + { + type: "heading", + data: { + text: { + desktop: { + type: "heading", + alignment: "left", + tag: "h1" + }, + data: { + text: `{"root":{"children":[{"children":[{"detail":0,"format":0,"mode":"normal","style":"","text":"${blockText}","type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"heading-element","version":1,"tag":"h1","styles":[{"styleId":"heading1","type":"typography"}]}],"direction":"ltr","format":"","indent":0,"type":"root","version":1}}` + } + }, + settings: { + margin: { + desktop: { + all: "0px" + } + }, + padding: { + desktop: { + all: "0px" + } + } + } + } + } + ] + }; +}; diff --git a/cypress-tests/cypress/support/pageBuilder/pbUpdatePageBlock.ts b/cypress-tests/cypress/support/pageBuilder/pbUpdatePageBlock.ts new file mode 100644 index 00000000000..b541b7512f8 --- /dev/null +++ b/cypress-tests/cypress/support/pageBuilder/pbUpdatePageBlock.ts @@ -0,0 +1,42 @@ +import { createGqlQuery, GqlResponse } from "../utils"; + +const UPDATE_PAGE_BLOCK = /* GraphQL */ ` + mutation UpdatePageBlock($id: ID!, $data: PbUpdatePageBlockInput!) { + pageBuilder { + pageBlock: updatePageBlock(id: $id, data: $data) { + data { + id + blockCategory + name + content + createdOn + createdBy { + id + displayName + type + } + } + error { + code + message + data + } + } + } + } +`; + +declare global { + // eslint-disable-next-line @typescript-eslint/no-namespace + namespace Cypress { + interface Chainable { + pbUpdatePageBlock: typeof pbUpdatePageBlock; + } + } +} + +export const pbUpdatePageBlock = createGqlQuery, { id: string; data: object }>( + UPDATE_PAGE_BLOCK +); + +Cypress.Commands.add("pbUpdatePageBlock", pbUpdatePageBlock); diff --git a/cypress-tests/cypress/support/utils.ts b/cypress-tests/cypress/support/utils.ts index 1742da21140..d8252e18357 100644 --- a/cypress-tests/cypress/support/utils.ts +++ b/cypress-tests/cypress/support/utils.ts @@ -1,6 +1,6 @@ import { GraphQLClient } from "graphql-request"; -import { customAlphabet } from "nanoid"; import { getSuperAdminUser, User } from "./login"; +import { generateAlphaLowerCaseId } from "@webiny/utils/generateId"; const DEFAULT_TENANT_ID = "root"; @@ -107,5 +107,5 @@ export const createGqlQuery = >( }; export const generateId = () => { - return customAlphabet("abcdefghijklmnopqrstuvwxyz", 10)(); + return generateAlphaLowerCaseId(10); }; diff --git a/cypress-tests/cypress/support/visitWebsite.ts b/cypress-tests/cypress/support/visitWebsite.ts new file mode 100644 index 00000000000..e30f2c047fc --- /dev/null +++ b/cypress-tests/cypress/support/visitWebsite.ts @@ -0,0 +1,14 @@ +import "./utils"; + +declare global { + // eslint-disable-next-line @typescript-eslint/no-namespace + namespace Cypress { + interface Chainable { + visitWebsite(url: string): Promise; + } + } +} + +Cypress.Commands.add("visitWebsite", url => { + cy.visit(Cypress.env("WEBSITE_URL") + url); +});