From 069de1fdb15fc894dea2261c5443dc0d6e04fba9 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 25 May 2021 15:57:38 +0100 Subject: [PATCH] Updating Automation cypress tests, now functional. --- packages/builder/cypress.json | 4 +- .../integration/createAutomation.spec.js | 25 ++++----- packages/builder/cypress/setup.js | 8 ++- packages/builder/cypress/support/commands.js | 55 +++++++++---------- packages/builder/cypress/support/cookies.js | 3 + packages/builder/cypress/support/index.js | 1 + packages/builder/package.json | 6 +- 7 files changed, 50 insertions(+), 52 deletions(-) create mode 100644 packages/builder/cypress/support/cookies.js diff --git a/packages/builder/cypress.json b/packages/builder/cypress.json index 669ee5af34..0908f2c839 100644 --- a/packages/builder/cypress.json +++ b/packages/builder/cypress.json @@ -1,9 +1,9 @@ { - "baseUrl": "http://localhost:10000/builder/", + "baseUrl": "http://localhost:10001/builder/", "video": true, "projectId": "bmbemn", "env": { - "PORT": "10000", + "PORT": "10001", "JWT_SECRET": "test" } } diff --git a/packages/builder/cypress/integration/createAutomation.spec.js b/packages/builder/cypress/integration/createAutomation.spec.js index b8aab9d52e..75611eff06 100644 --- a/packages/builder/cypress/integration/createAutomation.spec.js +++ b/packages/builder/cypress/integration/createAutomation.spec.js @@ -8,31 +8,27 @@ context("Create a automation", () => { it("should create a automation", () => { cy.createTestTableWithData() - cy.contains("automate").click() - cy.get("[data-cy=new-automation]").click() - cy.get(".modal").within(() => { + cy.contains("Automate").click() + cy.get("[data-cy='new-screen'] > .spectrum-Icon").click() + cy.get(".spectrum-Dialog-grid").within(() => { cy.get("input").type("Add Row") - cy.get(".buttons") - .contains("Create") - .click() + cy.get(".spectrum-Button--cta").click() }) // Add trigger cy.contains("Trigger").click() cy.contains("Row Created").click() cy.get(".setup").within(() => { - cy.get("select") - .first() - .select("dog") + cy.get(".spectrum-Picker-label").click() + cy.contains("dog").click() }) // Create action cy.contains("Action").click() cy.contains("Create Row").click() cy.get(".setup").within(() => { - cy.get("select") - .first() - .select("dog") + cy.get(".spectrum-Picker-label").click() + cy.contains("dog").click() cy.get("input") .first() .type("goodboy") @@ -45,12 +41,11 @@ context("Create a automation", () => { cy.contains("Save Automation").click() // Activate Automation - cy.get("[data-cy=activate-automation]").click() - cy.get(".ri-stop-circle-fill.highlighted").should("be.visible") + cy.get("[aria-label=PlayCircle]").click() }) it("should add row when a new row is added", () => { - cy.contains("data").click() + cy.contains("Data").click() cy.addRow(["Rover", 15]) cy.reload() cy.contains("goodboy").should("have.text", "goodboy") diff --git a/packages/builder/cypress/setup.js b/packages/builder/cypress/setup.js index c0d0dfa110..c55cef2afe 100644 --- a/packages/builder/cypress/setup.js +++ b/packages/builder/cypress/setup.js @@ -3,7 +3,9 @@ const path = require("path") const tmpdir = path.join(require("os").tmpdir(), ".budibase") -const WORKER_PORT = "4002" +// these run on ports we don't normally use so that they can run alongside the +// normal development system +const WORKER_PORT = "10002" const MAIN_PORT = cypressConfig.env.PORT process.env.BUDIBASE_API_KEY = "6BE826CB-6B30-4AEC-8777-2E90464633DE" process.env.NODE_ENV = "cypress" @@ -12,8 +14,8 @@ process.env.PORT = MAIN_PORT process.env.JWT_SECRET = cypressConfig.env.JWT_SECRET process.env.COUCH_URL = `leveldb://${tmpdir}/.data/` process.env.SELF_HOSTED = 1 -process.env.WORKER_URL = "http://localhost:4002/" -process.env.MINIO_URL = "http://localhost:10000/" +process.env.WORKER_URL = "http://localhost:10002/" +process.env.MINIO_URL = `http://localhost:${MAIN_PORT}/` process.env.MINIO_ACCESS_KEY = "budibase" process.env.MINIO_SECRET_KEY = "budibase" process.env.COUCH_DB_USER = "budibase" diff --git a/packages/builder/cypress/support/commands.js b/packages/builder/cypress/support/commands.js index 732f625351..46b9349220 100644 --- a/packages/builder/cypress/support/commands.js +++ b/packages/builder/cypress/support/commands.js @@ -7,7 +7,7 @@ Cypress.Commands.add("login", () => { cy.visit(`localhost:${Cypress.env("PORT")}/builder`) - cy.wait(100) + cy.wait(500) cy.url().then(url => { if (url.includes("builder/admin")) { // create admin user @@ -16,12 +16,14 @@ Cypress.Commands.add("login", () => { cy.get('input[type="password"]').eq(1).type("test") cy.contains("Create super admin user").click() } - // login - cy.contains("Sign in to Budibase").then(() => { - cy.get("input").first().type("test@test.com") - cy.get('input[type="password"]').type("test") - cy.get("button").first().click() - }) + if (url.includes("builder/auth/login") || url.includes("builder/admin")) { + // login + cy.contains("Sign in to Budibase").then(() => { + cy.get("input").first().type("test@test.com") + cy.get('input[type="password"]').type("test") + cy.get("button").first().click() + }) + } }) }) @@ -44,30 +46,23 @@ Cypress.Commands.add("createApp", name => { }) }) -Cypress.Commands.add("deleteApp", name => { - cy.contains("Create your first app").then($first => { - if ($first.length === 1) { - return - } - cy.visit(`localhost:${Cypress.env("PORT")}/builder`) - cy.get(".app").then($app => { - cy.wait(1000) - if ($app.find(`[data-cy="app-${name}"]`).length) { - cy.get(`[data-cy="app-${name}"]`).contains("Open").click() - cy.get("[data-cy=settings-icon]").click() - cy.get(".spectrum-Dialog").within(() => { - cy.contains("Danger Zone").click() - cy.get("input").type("DELETE").blur() - cy.contains("Delete Entire App").click() - }) - } - }) - }) +Cypress.Commands.add("deleteApp", () => { + cy.visit(`localhost:${Cypress.env("PORT")}/builder`) + cy.wait(1000) + + const firstAppHeader = Object.values(Cypress.$("h1")).filter( + $h1 => typeof $h1 === "string" && $h1.includes("Create your first app") + ) + if (firstAppHeader.length === 0) { + cy.get(".hoverable > use").click() + cy.contains("Delete").click() + cy.get(".spectrum-Button--warning").click() + } }) Cypress.Commands.add("createTestApp", () => { const appName = "Cypress Tests" - cy.deleteApp(appName) + cy.deleteApp() cy.createApp(appName, "This app is used for Cypress testing.") }) @@ -98,8 +93,10 @@ Cypress.Commands.add("addColumn", (tableName, columnName, type) => { // Unset table display column cy.contains("display column").click({ force: true }) - cy.get("select").select(type) - cy.contains("Save").click() + cy.get(".spectrum-Picker-label").click() + cy.contains(type).click() + + cy.contains("Save Column").click() }) }) diff --git a/packages/builder/cypress/support/cookies.js b/packages/builder/cypress/support/cookies.js new file mode 100644 index 0000000000..52167cc372 --- /dev/null +++ b/packages/builder/cypress/support/cookies.js @@ -0,0 +1,3 @@ +Cypress.Cookies.defaults({ + preserve: "budibase:auth", +}) \ No newline at end of file diff --git a/packages/builder/cypress/support/index.js b/packages/builder/cypress/support/index.js index 46a916f132..acd53a1592 100644 --- a/packages/builder/cypress/support/index.js +++ b/packages/builder/cypress/support/index.js @@ -15,6 +15,7 @@ // Import commands.js using ES2015 syntax: import "./commands" +import "./cookies" // Alternatively you can use CommonJS syntax: // require('./commands') diff --git a/packages/builder/package.json b/packages/builder/package.json index d931d11db3..29267f50ff 100644 --- a/packages/builder/package.json +++ b/packages/builder/package.json @@ -15,9 +15,9 @@ "cy:run": "cypress run", "cy:open": "cypress open", "cy:run:ci": "cypress run --record --key f308590b-6070-41af-b970-794a3823d451", - "cy:test": "start-server-and-test cy:setup http://localhost:10000/builder cy:run", - "cy:ci": "start-server-and-test cy:setup http://localhost:10000/builder cy:run:ci", - "cy:debug": "start-server-and-test cy:setup http://localhost:10000/builder cy:open" + "cy:test": "start-server-and-test cy:setup http://localhost:10001/builder cy:run", + "cy:ci": "start-server-and-test cy:setup http://localhost:10001/builder cy:run:ci", + "cy:debug": "start-server-and-test cy:setup http://localhost:10001/builder cy:open" }, "jest": { "globals": {