From 9fb40759d6976ed4ef24ddfd053493c213fbee8a Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 5 Mar 2021 14:36:38 +0000 Subject: [PATCH] Refactor cypress to use common app creation functionality and stop cypress deleting all apps --- packages/builder/cypress.json | 4 +- .../cypress/integration/createApp.spec.js | 9 +-- .../integration/createAutomation.spec.js | 8 +-- .../cypress/integration/createBinding.spec.js | 2 +- .../integration/createComponents.spec.js | 2 +- .../cypress/integration/createScreen.js | 10 +++ .../cypress/integration/createTable.spec.js | 19 +++-- .../cypress/integration/createUser.spec.js | 23 +++--- .../cypress/integration/createView.spec.js | 71 +++++++++++++------ .../cypress/integration/handlebars.spec.js | 0 .../cypress/integration/screens.spec.js | 13 ---- packages/builder/cypress/setup.js | 3 - packages/builder/cypress/support/commands.js | 7 +- 13 files changed, 92 insertions(+), 79 deletions(-) create mode 100644 packages/builder/cypress/integration/createScreen.js create mode 100644 packages/builder/cypress/integration/handlebars.spec.js delete mode 100644 packages/builder/cypress/integration/screens.spec.js diff --git a/packages/builder/cypress.json b/packages/builder/cypress.json index d76078f509..09b38ae985 100644 --- a/packages/builder/cypress.json +++ b/packages/builder/cypress.json @@ -1,8 +1,8 @@ { - "baseUrl": "http://localhost:4005/_builder/", + "baseUrl": "http://localhost:4001/_builder/", "video": true, "projectId": "bmbemn", "env": { - "PORT": "4005" + "PORT": "4001" } } diff --git a/packages/builder/cypress/integration/createApp.spec.js b/packages/builder/cypress/integration/createApp.spec.js index 7195da24ce..74c9e2999d 100644 --- a/packages/builder/cypress/integration/createApp.spec.js +++ b/packages/builder/cypress/integration/createApp.spec.js @@ -1,12 +1,7 @@ context("Create an Application", () => { - beforeEach(() => { - cy.server() - cy.visit(`localhost:${Cypress.env("PORT")}/_builder`) - }) - it("should create a new application", () => { - cy.createApp("My Cool App", "This is a description") + cy.createTestApp() cy.visit(`localhost:${Cypress.env("PORT")}/_builder`) - cy.contains("My Cool App").should("exist") + cy.contains("Cypress Tests").should("exist") }) }) diff --git a/packages/builder/cypress/integration/createAutomation.spec.js b/packages/builder/cypress/integration/createAutomation.spec.js index 97b67cf15c..36db9797c3 100644 --- a/packages/builder/cypress/integration/createAutomation.spec.js +++ b/packages/builder/cypress/integration/createAutomation.spec.js @@ -1,12 +1,6 @@ context("Create a automation", () => { before(() => { - cy.server() - cy.visit(`localhost:${Cypress.env("PORT")}/_builder`) - - cy.createApp( - "Automation Test App", - "This app is used to test that automations do in fact work!" - ) + cy.createTestApp() }) // https://on.cypress.io/interacting-with-elements diff --git a/packages/builder/cypress/integration/createBinding.spec.js b/packages/builder/cypress/integration/createBinding.spec.js index 0550f4204b..72321f1f8a 100644 --- a/packages/builder/cypress/integration/createBinding.spec.js +++ b/packages/builder/cypress/integration/createBinding.spec.js @@ -1,6 +1,6 @@ context("Create Bindings", () => { before(() => { - cy.createApp("Cypress Tests", "Cypress test app") + cy.createTestApp() cy.navigateToFrontend() }) diff --git a/packages/builder/cypress/integration/createComponents.spec.js b/packages/builder/cypress/integration/createComponents.spec.js index c668734f4b..393cd1895f 100644 --- a/packages/builder/cypress/integration/createComponents.spec.js +++ b/packages/builder/cypress/integration/createComponents.spec.js @@ -2,7 +2,7 @@ context("Create Components", () => { let headlineId before(() => { - cy.createApp("Cypress Tests", "Cypress test app") + cy.createTestApp() cy.createTable("dog") cy.addColumn("dog", "name", "string") cy.addColumn("dog", "age", "number") diff --git a/packages/builder/cypress/integration/createScreen.js b/packages/builder/cypress/integration/createScreen.js new file mode 100644 index 0000000000..c658ab51e1 --- /dev/null +++ b/packages/builder/cypress/integration/createScreen.js @@ -0,0 +1,10 @@ +context("Screen Tests", () => { + before(() => { + cy.createTestApp() + cy.navigateToFrontend() + }) + + it("Should successfully create a screen", () => { + cy.createScreen("Test Screen", "/test") + }) +}) diff --git a/packages/builder/cypress/integration/createTable.spec.js b/packages/builder/cypress/integration/createTable.spec.js index 3a8b466502..bbdb2e67fe 100644 --- a/packages/builder/cypress/integration/createTable.spec.js +++ b/packages/builder/cypress/integration/createTable.spec.js @@ -1,7 +1,6 @@ context("Create a Table", () => { before(() => { - cy.visit(`localhost:${Cypress.env("PORT")}/_builder`) - cy.createApp("Table App", "Table App Description") + cy.createTestApp() }) it("should create a new Table", () => { @@ -26,7 +25,9 @@ context("Create a Table", () => { .trigger("mouseover") .find(".ri-pencil-line") .click({ force: true }) - cy.get(".actions input").first().type("updated") + cy.get(".actions input") + .first() + .type("updated") // Unset table display column cy.contains("display column").click() cy.contains("Save Column").click() @@ -44,7 +45,9 @@ context("Create a Table", () => { it("deletes a row", () => { cy.get(".ag-checkbox-input").check({ force: true }) cy.contains("Delete 1 row(s)").click() - cy.get(".modal").contains("Delete").click() + cy.get(".modal") + .contains("Delete") + .click() cy.contains("RoverUpdated").should("not.exist") }) @@ -55,12 +58,16 @@ context("Create a Table", () => { .click({ force: true }) cy.contains("Delete").click() cy.wait(50) - cy.get(".buttons").contains("Delete").click() + cy.get(".buttons") + .contains("Delete") + .click() cy.contains("nameupdated").should("not.exist") }) it("deletes a table", () => { - cy.get(".ri-more-line").first().click({ force: true }) + cy.get(".ri-more-line") + .first() + .click({ force: true }) cy.get("[data-cy=delete-table]").click() cy.contains("Delete Table").click() cy.contains("dog").should("not.exist") diff --git a/packages/builder/cypress/integration/createUser.spec.js b/packages/builder/cypress/integration/createUser.spec.js index 45a1ffcc68..0beaf5b80f 100644 --- a/packages/builder/cypress/integration/createUser.spec.js +++ b/packages/builder/cypress/integration/createUser.spec.js @@ -1,17 +1,10 @@ -context('Create a User', () => { +context("Create a User", () => { + before(() => { + cy.createTestApp() + }) - before(() => { - cy.server() - cy.visit(`localhost:${Cypress.env("PORT")}/_builder`) - // https://on.cypress.io/type - cy.createApp('User App', 'This app is used to test user creation') - }) - - // https://on.cypress.io/interacting-with-elements - it('should create a user', () => { - cy.createUser("bbuser@test.com", "test", "ADMIN") - - // // Check to make sure user was created! - cy.contains("bbuser").should('be.visible') - }) + it("should create a user", () => { + cy.createUser("bbuser@test.com", "test", "ADMIN") + cy.contains("bbuser").should("be.visible") + }) }) diff --git a/packages/builder/cypress/integration/createView.spec.js b/packages/builder/cypress/integration/createView.spec.js index 6f321ab16f..4d8e2a8134 100644 --- a/packages/builder/cypress/integration/createView.spec.js +++ b/packages/builder/cypress/integration/createView.spec.js @@ -1,15 +1,6 @@ -function removeSpacing(headers) { - let newHeaders = [] - for (let header of headers) { - newHeaders.push(header.replace(/\s\s+/g, " ")) - } - return newHeaders -} - context("Create a View", () => { before(() => { - cy.visit(`localhost:${Cypress.env("PORT")}/_builder`) - cy.createApp("View App", "View App Description") + cy.createTestApp() cy.createTable("data") cy.addColumn("data", "group", "Text") cy.addColumn("data", "age", "Number") @@ -36,16 +27,28 @@ context("Create a View", () => { const headers = Array.from($headers).map(header => header.textContent.trim() ) - expect(removeSpacing(headers)).to.deep.eq([ "rating Number", "age Number", "group Text" ]) + expect(removeSpacing(headers)).to.deep.eq([ + "rating Number", + "age Number", + "group Text", + ]) }) }) it("filters the view by age over 10", () => { cy.contains("Filter").click() cy.contains("Add Filter").click() - cy.get(".menu-container").find("select").first().select("age") - cy.get(".menu-container").find("select").eq(1).select("More Than") - cy.get(".menu-container").find("input").type(18) + cy.get(".menu-container") + .find("select") + .first() + .select("age") + cy.get(".menu-container") + .find("select") + .eq(1) + .select("More Than") + cy.get(".menu-container") + .find("input") + .type(18) cy.contains("Save").click() cy.get("[role=rowgroup] .ag-row").get($values => { expect($values).to.have.length(5) @@ -57,9 +60,15 @@ context("Create a View", () => { cy.viewport("macbook-15") cy.contains("Calculate").click() - cy.get(".menu-container").find("select").eq(0).select("Statistics") + cy.get(".menu-container") + .find("select") + .eq(0) + .select("Statistics") cy.wait(50) - cy.get(".menu-container").find("select").eq(1).select("age") + cy.get(".menu-container") + .find("select") + .eq(1) + .select("age") cy.contains("Save").click() cy.wait(100) cy.get(".ag-center-cols-viewport").scrollTo("100%") @@ -68,19 +77,19 @@ context("Create a View", () => { const headers = Array.from($headers).map(header => header.textContent.trim() ) - expect(removeSpacing(headers)).to.deep.eq([ "avg Number", + expect(removeSpacing(headers)).to.deep.eq([ + "avg Number", "sumsqr Number", "count Number", "max Number", "min Number", "sum Number", - "field Text" ]) + "field Text", + ]) }) cy.get(".ag-cell").then($values => { - let values = Array.from($values).map(header => - header.textContent.trim() - ) - expect(values).to.deep.eq([ "31", "5347", "5", "49", "20", "155", "age" ]) + let values = Array.from($values).map(header => header.textContent.trim()) + expect(values).to.deep.eq(["31", "5347", "5", "49", "20", "155", "age"]) }) }) @@ -99,7 +108,15 @@ context("Create a View", () => { .find(".ag-cell") .then($values => { const values = Array.from($values).map(value => value.textContent) - expect(values).to.deep.eq([ "Students", "23.333333333333332", "1650", "3", "25", "20", "70" ]) + expect(values).to.deep.eq([ + "Students", + "23.333333333333332", + "1650", + "3", + "25", + "20", + "70", + ]) }) }) @@ -124,3 +141,11 @@ context("Create a View", () => { cy.contains("TestView Updated").should("not.be.visible") }) }) + +function removeSpacing(headers) { + let newHeaders = [] + for (let header of headers) { + newHeaders.push(header.replace(/\s\s+/g, " ")) + } + return newHeaders +} diff --git a/packages/builder/cypress/integration/handlebars.spec.js b/packages/builder/cypress/integration/handlebars.spec.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/builder/cypress/integration/screens.spec.js b/packages/builder/cypress/integration/screens.spec.js deleted file mode 100644 index d219e7daa7..0000000000 --- a/packages/builder/cypress/integration/screens.spec.js +++ /dev/null @@ -1,13 +0,0 @@ - -context('Screen Tests', () => { - before(() => { - cy.server() - cy.visit(`localhost:${Cypress.env("PORT")}/_builder`) - cy.createApp('Conor Cy App', 'Table App Description') - cy.navigateToFrontend() - }) - - it('Should successfully create a screen', () => { - cy.createScreen("test Screen", "/test") - }) -}) \ No newline at end of file diff --git a/packages/builder/cypress/setup.js b/packages/builder/cypress/setup.js index d6b60d194e..6848d38cba 100644 --- a/packages/builder/cypress/setup.js +++ b/packages/builder/cypress/setup.js @@ -3,15 +3,12 @@ // 2. Initialises using `.budibase` // 3. Runs the server using said folder -const rimraf = require("rimraf") const { join, resolve } = require("path") const initialiseBudibase = require("../../server/src/utilities/initialiseBudibase") const cypressConfig = require("../cypress.json") const homedir = join(require("os").homedir(), ".budibase") -rimraf.sync(homedir) - process.env.BUDIBASE_API_KEY = "6BE826CB-6B30-4AEC-8777-2E90464633DE" process.env.NODE_ENV = "cypress" process.env.ENABLE_ANALYTICS = "false" diff --git a/packages/builder/cypress/support/commands.js b/packages/builder/cypress/support/commands.js index b961181241..2e418a0629 100644 --- a/packages/builder/cypress/support/commands.js +++ b/packages/builder/cypress/support/commands.js @@ -25,7 +25,6 @@ // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) Cypress.Commands.add("createApp", name => { - cy.deleteApp(name) cy.visit(`localhost:${Cypress.env("PORT")}/_builder`) cy.contains("Create New Web App").click() cy.get("body") @@ -72,6 +71,12 @@ Cypress.Commands.add("deleteApp", name => { }) }) +Cypress.Commands.add("createTestApp", () => { + const appName = "Cypress Tests" + cy.deleteApp(appName) + cy.createApp(appName, "This app is used for Cypress testing.") +}) + Cypress.Commands.add("createTestTableWithData", () => { cy.createTable("dog") cy.addColumn("dog", "name", "Text")