Skip to content

Commit

Permalink
starter-blocks: created starter blocks feature (#3156)
Browse files Browse the repository at this point in the history
  • Loading branch information
geodem127 authored Feb 25, 2025
1 parent 4366eed commit e128180
Show file tree
Hide file tree
Showing 31 changed files with 2,865 additions and 246 deletions.
14 changes: 9 additions & 5 deletions cypress/e2e/blocks/pages/AllBlocksPage.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
const TIMEOUT = {
timeout: 15000,
};

class AllBlocksPage {
visit() {
cy.visit("/blocks");
}

get createBlockButton() {
return cy.getBySelector("create-block-button");
return cy.getBySelector("create-block-button", TIMEOUT);
}

get onboardingDialog() {
Expand All @@ -24,13 +28,13 @@ class AllBlocksPage {
}

clickOnboardingNextButton() {
this.onboardingNextButton.click();
this.onboardingNextButton.click(TIMEOUT);
}

createBlock(name) {
this.createBlockButton.click();
cy.getBySelector("create-model-display-name-input").type(name);
cy.getBySelector("create-model-submit-button").click();
this.createBlockButton.click(TIMEOUT);
cy.getBySelector("create-model-display-name-input", TIMEOUT).type(name);
cy.getBySelector("create-model-submit-button", TIMEOUT).click();
}
}

Expand Down
63 changes: 55 additions & 8 deletions cypress/e2e/blocks/tests/blocks.spec.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import AllBlocksPage from "../pages/AllBlocksPage";
import BlockPage from "../pages/BlockPage";
import SchemaPage from "../../schema/pages/SchemaPage";
import { API_ENDPOINTS } from "../../../support/api";

const CypressTestBlock = "Cypress Test Block";
const CypressTestVariant = "Cypress Test Variant";

const TIMEOUT = {
timeout: 15_000,
};

describe("All Blocks Tests", () => {
before(() => {
deleteTestDataModels();
AllBlocksPage.visit();
});

after(() => {
SchemaPage.visit();
SchemaPage.deleteModel(CypressTestBlock);
// SchemaPage.visit();
// SchemaPage.deleteModel(CypressTestBlock);
deleteTestDataModels();
});

it("should show and traverse onboarding flow", () => {
Expand All @@ -24,9 +31,10 @@ describe("All Blocks Tests", () => {
AllBlocksPage.onboardingDialog.should("not.exist");
});

it("creates new block with default values", () => {
// Skiped since starter blocks are introduced.
it.skip("creates new block with default values", () => {
AllBlocksPage.createBlock(CypressTestBlock);
cy.contains(CypressTestBlock).should("exist");
cy.contains(CypressTestBlock, TIMEOUT).should("exist");
SchemaPage.visit();
SchemaPage.addSingleLineTextFieldWithDefaultValue(
CypressTestBlock,
Expand All @@ -36,6 +44,26 @@ describe("All Blocks Tests", () => {
AllBlocksPage.visit();
});

it("creates new block with default values", () => {
AllBlocksPage.visit();
cy.get('[data-cy="create_new_content_item"]').click();
cy.get('[data-cy="starter-block-card"]').first().click();
cy.get('[data-cy="select-block-type-next-button"]').click();
cy.get('[data-cy="starter-block-form-label"] input')
.clear()
.type(CypressTestBlock);
cy.intercept("POST", "/v1/content/models").as("createModel");
cy.get('[data-cy="starter-block-form-submit"]').click();
cy.wait("@createModel").then((interception) => {
const ZUID = interception?.response?.body?.data?.ZUID;
Cypress.env("model_zuid", ZUID);

console.debug("ZUID: ", ZUID);
// expect(res.data.label).to.eq(CypressTestBlock);
});
AllBlocksPage.visit();
});

it("searches for a block", () => {
AllBlocksPage.searchBlocksInput.type(CypressTestBlock);
cy.contains(CypressTestBlock).should("exist");
Expand All @@ -50,16 +78,35 @@ describe("All Blocks Tests", () => {
});

it("navigates to block detail page", () => {
cy.contains(CypressTestBlock).click();
cy.contains("Start Creating Variants Now").should("exist");
AllBlocksPage.visit();
cy.contains(CypressTestBlock, TIMEOUT).click();
cy.contains("Start Creating Variants Now", TIMEOUT).should("exist");
});

it("creates a variant with default values", () => {
cy.contains(CypressTestBlock).click();
AllBlocksPage.visit();
cy.contains(CypressTestBlock).click(TIMEOUT);
BlockPage.createVariant(CypressTestVariant);
cy.contains(
new RegExp(`${CypressTestBlock}:\\s*${CypressTestVariant}`)
).should("exist");
cy.get('input[name="foo"]').should("have.value", "Default Foo");
// cy.get('input[name="foo"]').should("have.value", "Default Foo");
});
});

function deleteTestDataModels() {
cy.apiRequest({
url: `${API_ENDPOINTS.devInstance}/content/models`,
}).then((response) => {
response?.data
?.filter((resData) =>
[CypressTestBlock, CypressTestVariant].includes(resData?.label)
)
.forEach((forDelete) => {
cy.apiRequest({
url: `${API_ENDPOINTS.devInstance}/content/models/${forDelete.ZUID}`,
method: "DELETE",
});
});
});
}
Loading

0 comments on commit e128180

Please sign in to comment.