diff --git a/packages/builder/cypress/integration/createScreen.spec.js b/packages/builder/cypress/integration/createScreen.spec.js index 94a827f26f..a516e279f4 100644 --- a/packages/builder/cypress/integration/createScreen.spec.js +++ b/packages/builder/cypress/integration/createScreen.spec.js @@ -1,4 +1,5 @@ import filterTests from "../support/filterTests" +const interact = require('../support/interact') filterTests(["smoke", "all"], () => { context("Screen Tests", () => { @@ -10,32 +11,44 @@ filterTests(["smoke", "all"], () => { it("Should successfully create a screen", () => { cy.createScreen("test") - cy.get(".nav-items-container").within(() => { + cy.get(interact.BODY).within(() => { cy.contains("/test").should("exist") }) }) it("Should update the url", () => { cy.createScreen("test with spaces") - cy.get(".nav-items-container").within(() => { + cy.get(interact.BODY).within(() => { cy.contains("/test-with-spaces").should("exist") }) }) - it("Should create a blank screen with the selected access level", () => { - cy.createScreen("admin only", "Admin") + it("should delete all screens then create first screen via button", () => { + cy.deleteAllScreens() + + cy.contains("Create first screen").click() + cy.get(interact.BODY, { timeout: 2000 }).should('contain', '/home') + }) - cy.get(".nav-items-container").within(() => { - cy.contains("/admin-only").should("exist") - }) + it("Should create and filter screens by access level", () => { + const accessLevels = ["Basic", "Admin", "Public", "Power"] - cy.createScreen("open to all", "Public") + for (const access of accessLevels){ + // Create screen with specified access level + cy.createScreen(access, access) + // Filter by access level and confirm screen visible + cy.filterScreensAccessLevel(access) + cy.get(interact.BODY).within(() => { + cy.get(interact.NAV_ITEM).should('contain', access.toLowerCase()) + }) + } - cy.get(".nav-items-container").within(() => { - cy.contains("/open-to-all").should("exist") - //The access level should now be set to admin. Previous screens should be filtered. - cy.get(".nav-item").contains("/test-screen").should("not.exist") - }) + // Filter by All screens - Confirm all screens visible + cy.filterScreensAccessLevel("All screens") + cy.get(interact.BODY).should('contain', accessLevels[0]) + .and('contain', accessLevels[1]) + .and('contain', accessLevels[2]) + .and('contain', accessLevels[3]) }) }) }) diff --git a/packages/builder/cypress/support/commands.js b/packages/builder/cypress/support/commands.js index 914faba461..309d051483 100644 --- a/packages/builder/cypress/support/commands.js +++ b/packages/builder/cypress/support/commands.js @@ -638,6 +638,43 @@ Cypress.Commands.add("filterScreensAccessLevel", accessLevel => { }) }) +Cypress.Commands.add("deleteScreen", screen => { + // Navigates to Design section and deletes specified screen + cy.contains("Design").click() + cy.get(".body").within(() => { + cy.contains(screen) + .siblings(".actions") + .within(() => { + cy.get(".spectrum-Icon").click({ force: true }) + }) + }) + cy.get(".spectrum-Menu > .spectrum-Menu-item > .spectrum-Menu-itemLabel") + .contains("Delete") + .click() + + cy.get( + ".spectrum-Dialog-grid > .spectrum-ButtonGroup > .confirm-wrap > .spectrum-Button" + ).click({ force: true }) + cy.get(".spectrum-Dialog-grid", { timeout: 10000 }).should("not.exist") +}) + +Cypress.Commands.add("deleteAllScreens", () => { + // Deletes all screens + cy.get(".body") + .find(".nav-item") + .its("length") + .then(len => { + for (let i = 0; i < len; i++) { + cy.get(".body > .nav-item") + .eq(0) + .invoke("text") + .then(text => { + cy.deleteScreen(text.trim()) + }) + } + }) +}) + // NAVIGATION Cypress.Commands.add("navigateToFrontend", () => { // Clicks on Design tab and then the Home nav item