From babbd22bf6791bc0fcf2aa075daf6ad98af390a9 Mon Sep 17 00:00:00 2001 From: Mitch-Budibase Date: Wed, 1 Jun 2022 18:54:14 +0100 Subject: [PATCH] Organising Commands file Rearranged the commands file into categories - Commands are organisation by relative category (users, tables etc.) --- packages/builder/cypress/support/commands.js | 405 +++++++++---------- 1 file changed, 197 insertions(+), 208 deletions(-) diff --git a/packages/builder/cypress/support/commands.js b/packages/builder/cypress/support/commands.js index 26337600f0..804b22f0fc 100644 --- a/packages/builder/cypress/support/commands.js +++ b/packages/builder/cypress/support/commands.js @@ -1,14 +1,8 @@ -// *********************************************** -// For more comprehensive examples of custom -// commands please read more here: -// https://on.cypress.io/custom-commands -// *********************************************** -// - Cypress.on("uncaught:exception", () => { return false }) +// ACCOUNTS & USERS Cypress.Commands.add("login", () => { cy.visit(`${Cypress.config().baseUrl}/builder`) cy.wait(2000) @@ -41,43 +35,20 @@ Cypress.Commands.add("logOut", () => { cy.wait(2000) }) -Cypress.Commands.add("closeModal", () => { - cy.get(".spectrum-Modal").within(() => { - cy.get(".close-icon").click() - cy.wait(1000) // Wait for modal to close - }) -}) +Cypress.Commands.add("createUser", email => { + // quick hacky recorded way to create a user + cy.contains("Users").click() + cy.get(`[data-cy="add-user"]`).click() + cy.get(".spectrum-Picker-label").click() + cy.get(".spectrum-Menu-item:nth-child(2) > .spectrum-Menu-itemLabel").click() -Cypress.Commands.add("importApp", (exportFilePath, name) => { - cy.visit(`${Cypress.config().baseUrl}/builder`) - - cy.request(`${Cypress.config().baseUrl}/api/applications?status=all`) - .its("body") - .then(val => { - if (val.length > 0) { - cy.get(`[data-cy="create-app-btn"]`).click({ force: true }) - cy.wait(500) - } - cy.get(`[data-cy="import-app-btn"]`).click({ force: true }) - }) - - cy.get(".spectrum-Modal").within(() => { - cy.get("input").eq(1).should("have.focus") - - cy.get(".spectrum-Dropzone").selectFile(exportFilePath, { - action: "drag-drop", - }) - - cy.get(".gallery .filename").contains("exported-app.txt") - - if (name && name != "") { - cy.get("input").eq(0).type(name).should("have.value", name).blur() - } - cy.get(".confirm-wrap button") - .should("not.be.disabled") - .click({ force: true }) - cy.wait(5000) - }) + //Onboarding type selector + cy.get( + ":nth-child(2) > .spectrum-Form-itemField > .spectrum-Textfield > .spectrum-Textfield-input" + ) + .first() + .type(email, { force: true }) + cy.get(".spectrum-Button--cta").click({ force: true }) }) Cypress.Commands.add("updateUserInformation", (firstName, lastName) => { @@ -113,6 +84,13 @@ Cypress.Commands.add("updateUserInformation", (firstName, lastName) => { }) }) +// APPLICATIONS +Cypress.Commands.add("createTestApp", () => { + const appName = "Cypress Tests" + cy.deleteApp(appName) + cy.createApp(appName, "This app is used for Cypress testing.") +}) + Cypress.Commands.add("createApp", (name, addDefaultTable) => { const shouldCreateDefaultTable = typeof addDefaultTable != "boolean" ? true : addDefaultTable @@ -218,36 +196,6 @@ Cypress.Commands.add("deleteAllApps", () => { }) }) -Cypress.Commands.add("alterAppVersion", (appId, version) => { - return cy - .request("put", `${Cypress.config().baseUrl}/api/applications/${appId}`, { - version: version || "0.0.1-alpha.0", - }) - .then(resp => { - expect(resp.status).to.eq(200) - }) -}) - -Cypress.Commands.add("updateAppName", (changedName, noName) => { - cy.get(".spectrum-Modal").within(() => { - if (noName == true) { - cy.get("input").clear() - cy.get(".spectrum-Dialog-grid") - .click() - .contains("App name must be letters, numbers and spaces only") - return cy - } - cy.get("input").clear() - cy.get("input") - .eq(0) - .type(changedName) - .should("have.value", changedName) - .blur() - cy.get(".spectrum-ButtonGroup").contains("Save").click({ force: true }) - cy.wait(500) - }) -}) - Cypress.Commands.add("unlockApp", unlock_config => { let config = { ...unlock_config } @@ -277,6 +225,26 @@ Cypress.Commands.add("unlockApp", unlock_config => { }) }) +Cypress.Commands.add("updateAppName", (changedName, noName) => { + cy.get(".spectrum-Modal").within(() => { + if (noName == true) { + cy.get("input").clear() + cy.get(".spectrum-Dialog-grid") + .click() + .contains("App name must be letters, numbers and spaces only") + return cy + } + cy.get("input").clear() + cy.get("input") + .eq(0) + .type(changedName) + .should("have.value", changedName) + .blur() + cy.get(".spectrum-ButtonGroup").contains("Save").click({ force: true }) + cy.wait(500) + }) +}) + Cypress.Commands.add("publishApp", resolvedAppPath => { //Assumes you have navigated to an application first cy.get(".toprightnav button.spectrum-Button") @@ -300,19 +268,96 @@ Cypress.Commands.add("publishApp", resolvedAppPath => { }) }) -Cypress.Commands.add("createTestApp", () => { - const appName = "Cypress Tests" - cy.deleteApp(appName) - cy.createApp(appName, "This app is used for Cypress testing.") - //cy.createScreen("home") +Cypress.Commands.add("alterAppVersion", (appId, version) => { + return cy + .request("put", `${Cypress.config().baseUrl}/api/applications/${appId}`, { + version: version || "0.0.1-alpha.0", + }) + .then(resp => { + expect(resp.status).to.eq(200) + }) }) -Cypress.Commands.add("createTestTableWithData", () => { - cy.createTable("dog") - cy.addColumn("dog", "name", "Text") - cy.addColumn("dog", "age", "Number") +Cypress.Commands.add("importApp", (exportFilePath, name) => { + cy.visit(`${Cypress.config().baseUrl}/builder`) + + cy.request(`${Cypress.config().baseUrl}/api/applications?status=all`) + .its("body") + .then(val => { + if (val.length > 0) { + cy.get(`[data-cy="create-app-btn"]`).click({ force: true }) + cy.wait(500) + } + cy.get(`[data-cy="import-app-btn"]`).click({ force: true }) + }) + + cy.get(".spectrum-Modal").within(() => { + cy.get("input").eq(1).should("have.focus") + + cy.get(".spectrum-Dropzone").selectFile(exportFilePath, { + action: "drag-drop", + }) + + cy.get(".gallery .filename").contains("exported-app.txt") + + if (name && name != "") { + cy.get("input").eq(0).type(name).should("have.value", name).blur() + } + cy.get(".confirm-wrap button") + .should("not.be.disabled") + .click({ force: true }) + cy.wait(5000) + }) }) +// Filters visible with 1 or more +Cypress.Commands.add("searchForApplication", appName => { + cy.visit(`${Cypress.config().baseUrl}/builder`) + cy.wait(2000) + + // No app filter functionality if only 1 app exists + cy.request(`${Cypress.config().baseUrl}/api/applications?status=all`) + .its("body") + .then(val => { + if (val.length < 2) { + return + } else { + // Searches for the app + cy.get(".filter").then(() => { + cy.get(".spectrum-Textfield").within(() => { + cy.get("input").eq(0).clear() + cy.get("input").eq(0).type(appName) + }) + }) + } + }) +}) + +// Assumes there are no others +Cypress.Commands.add("applicationInAppTable", appName => { + cy.get(".appTable").within(() => { + cy.get(".title").contains(appName).should("exist") + }) +}) + +Cypress.Commands.add("createAppFromScratch", appName => { + cy.get(`[data-cy="create-app-btn"]`) + .contains("Start from scratch") + .click({ force: true }) + cy.get(".spectrum-Modal").within(() => { + cy.get("input") + .eq(0) + .clear() + .type(appName) + .should("have.value", appName) + .blur() + cy.get(".spectrum-ButtonGroup").contains("Create app").click() + cy.wait(10000) + }) + cy.createTable("Cypress Tests", true) +}) + +// TABLES Cypress.Commands.add("createTable", (tableName, initialTable) => { if (!initialTable) { cy.navigateToDataSection() @@ -333,6 +378,12 @@ Cypress.Commands.add("createTable", (tableName, initialTable) => { cy.contains(tableName).should("be.visible") }) +Cypress.Commands.add("createTestTableWithData", () => { + cy.createTable("dog") + cy.addColumn("dog", "name", "Text") + cy.addColumn("dog", "age", "Number") +}) + Cypress.Commands.add( "addColumn", (tableName, columnName, type, multiOptions = null) => { @@ -387,22 +438,33 @@ Cypress.Commands.add("addRowMultiValue", values => { }) }) -Cypress.Commands.add("createUser", email => { - // quick hacky recorded way to create a user - cy.contains("Users").click() - cy.get(`[data-cy="add-user"]`).click() - cy.get(".spectrum-Picker-label").click() - cy.get(".spectrum-Menu-item:nth-child(2) > .spectrum-Menu-itemLabel").click() - - //Onboarding type selector - cy.get( - ":nth-child(2) > .spectrum-Form-itemField > .spectrum-Textfield > .spectrum-Textfield-input" - ) - .first() - .type(email, { force: true }) - cy.get(".spectrum-Button--cta").click({ force: true }) +Cypress.Commands.add("selectTable", tableName => { + cy.expandBudibaseConnection() + cy.contains(".nav-item", tableName).click() }) +Cypress.Commands.add("addCustomSourceOptions", totalOptions => { + cy.get(".spectrum-ActionButton") + .contains("Define Options") + .click() + .then(() => { + for (let i = 0; i < totalOptions; i++) { + // Add radio button options + cy.get(".spectrum-Button") + .contains("Add Option") + .click({ force: true }) + .then(() => { + cy.wait(500) + cy.get("[placeholder='Label']").eq(i).type(i) + cy.get("[placeholder='Value']").eq(i).type(i) + }) + } + // Save options + cy.get(".spectrum-Button").contains("Save").click({ force: true }) + }) +}) + +// DESIGN AREA Cypress.Commands.add("addComponent", (category, component) => { if (category) { cy.get(`[data-cy="category-${category}"]`).click({ force: true }) @@ -430,22 +492,8 @@ Cypress.Commands.add("getComponent", componentId => { .find(`[data-id=${componentId}]`) }) -Cypress.Commands.add("navigateToFrontend", () => { - // Clicks on Design tab and then the Home nav item - cy.wait(1000) - cy.contains("Design").click() - cy.get(".spectrum-Search").type("/") - cy.get(".nav-item").contains("home").click() -}) - -Cypress.Commands.add("navigateToDataSection", () => { - // Clicks on the Data tab - cy.wait(500) - cy.contains("Data").click() -}) - -//Blank Cypress.Commands.add("createScreen", (route, accessLevelLabel) => { + // Blank Screen cy.contains("Design").click() cy.get("[aria-label=AddCircle]").click() cy.get(".spectrum-Modal").within(() => { @@ -505,17 +553,6 @@ Cypress.Commands.add( } ) -Cypress.Commands.add("navigateToAutogeneratedModal", () => { - // Screen name must already exist within data source - cy.contains("Design").click() - cy.get("[aria-label=AddCircle]").click() - cy.get(".spectrum-Modal").within(() => { - cy.get(".item").contains("Autogenerated screens").click() - cy.get(".spectrum-Button").contains("Continue").click({ force: true }) - cy.wait(500) - }) -}) - Cypress.Commands.add( "createAutogeneratedScreens", (screenNames, accessLevelLabel) => { @@ -537,96 +574,33 @@ Cypress.Commands.add( } ) -Cypress.Commands.add("addRow", values => { - cy.contains("Create row").click() +// NAVIGATION +Cypress.Commands.add("navigateToFrontend", () => { + // Clicks on Design tab and then the Home nav item + cy.wait(1000) + cy.contains("Design").click() + cy.get(".spectrum-Search").type("/") + cy.get(".nav-item").contains("home").click() +}) + +Cypress.Commands.add("navigateToDataSection", () => { + // Clicks on the Data tab + cy.wait(500) + cy.contains("Data").click() +}) + +Cypress.Commands.add("navigateToAutogeneratedModal", () => { + // Screen name must already exist within data source + cy.contains("Design").click() + cy.get("[aria-label=AddCircle]").click() cy.get(".spectrum-Modal").within(() => { - for (let i = 0; i < values.length; i++) { - cy.get("input").eq(i).type(values[i]).blur() - } - cy.get(".spectrum-ButtonGroup").contains("Create").click() + cy.get(".item").contains("Autogenerated screens").click() + cy.get(".spectrum-Button").contains("Continue").click({ force: true }) + cy.wait(500) }) }) -Cypress.Commands.add("expandBudibaseConnection", () => { - if (Cypress.$(".nav-item > .content > .opened").length === 0) { - // expand the Budibase DB connection string - cy.get(".icon.arrow").eq(0).click() - } -}) - -Cypress.Commands.add("selectTable", tableName => { - cy.expandBudibaseConnection() - cy.contains(".nav-item", tableName).click() -}) - -Cypress.Commands.add("addCustomSourceOptions", totalOptions => { - cy.get(".spectrum-ActionButton") - .contains("Define Options") - .click() - .then(() => { - for (let i = 0; i < totalOptions; i++) { - // Add radio button options - cy.get(".spectrum-Button") - .contains("Add Option") - .click({ force: true }) - .then(() => { - cy.wait(500) - cy.get("[placeholder='Label']").eq(i).type(i) - cy.get("[placeholder='Value']").eq(i).type(i) - }) - } - // Save options - cy.get(".spectrum-Button").contains("Save").click({ force: true }) - }) -}) - -//Filters visible with 1 or more -Cypress.Commands.add("searchForApplication", appName => { - cy.visit(`${Cypress.config().baseUrl}/builder`) - cy.wait(2000) - - // No app filter functionality if only 1 app exists - cy.request(`${Cypress.config().baseUrl}/api/applications?status=all`) - .its("body") - .then(val => { - if (val.length < 2) { - return - } else { - // Searches for the app - cy.get(".filter").then(() => { - cy.get(".spectrum-Textfield").within(() => { - cy.get("input").eq(0).clear() - cy.get("input").eq(0).type(appName) - }) - }) - } - }) -}) - -//Assumes there are no others -Cypress.Commands.add("applicationInAppTable", appName => { - cy.get(".appTable").within(() => { - cy.get(".title").contains(appName).should("exist") - }) -}) - -Cypress.Commands.add("createAppFromScratch", appName => { - cy.get(`[data-cy="create-app-btn"]`) - .contains("Start from scratch") - .click({ force: true }) - cy.get(".spectrum-Modal").within(() => { - cy.get("input") - .eq(0) - .clear() - .type(appName) - .should("have.value", appName) - .blur() - cy.get(".spectrum-ButtonGroup").contains("Create app").click() - cy.wait(10000) - }) - cy.createTable("Cypress Tests", true) -}) - +// DATASOURCES Cypress.Commands.add("selectExternalDatasource", datasourceName => { // Navigates to Data Section cy.navigateToDataSection() @@ -762,3 +736,18 @@ Cypress.Commands.add("createRestQuery", (method, restUrl, queryPrettyName) => { .should("contain", method) .and("contain", queryPrettyName) }) + +// MISC +Cypress.Commands.add("closeModal", () => { + cy.get(".spectrum-Modal").within(() => { + cy.get(".close-icon").click() + cy.wait(1000) // Wait for modal to close + }) +}) + +Cypress.Commands.add("expandBudibaseConnection", () => { + if (Cypress.$(".nav-item > .content > .opened").length === 0) { + // expand the Budibase DB connection string + cy.get(".icon.arrow").eq(0).click() + } +})