budibase/packages/builder/cypress/support/commands.js

173 lines
5.0 KiB
JavaScript
Raw Normal View History

2020-06-09 13:52:00 +02:00
// ***********************************************
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
2021-04-15 14:23:42 +02:00
Cypress.Commands.add("login", () => {
2021-05-04 12:32:22 +02:00
cy.getCookie("budibase:auth").then(cookie => {
2021-04-15 19:34:49 +02:00
// Already logged in
2021-04-15 19:29:11 +02:00
if (cookie) return
2021-04-15 18:46:47 +02:00
2021-04-15 19:29:11 +02:00
cy.visit(`localhost:${Cypress.env("PORT")}/builder`)
cy.contains("Create Test User").click()
2021-05-03 09:31:09 +02:00
cy.get("input").first().type("test@test.com")
2021-04-15 19:29:11 +02:00
cy.get('input[type="password"]').type("test")
2021-04-15 14:23:42 +02:00
2021-04-15 19:29:11 +02:00
cy.contains("Login").click()
})
})
2021-05-04 12:32:22 +02:00
Cypress.Commands.add("createApp", name => {
cy.visit(`localhost:${Cypress.env("PORT")}/builder`)
// wait for init API calls on visit
cy.wait(100)
cy.contains("Create New Web App").click()
cy.get("body")
2021-05-04 12:32:22 +02:00
.then($body => {
if ($body.find("input[name=apiKey]").length) {
// input was found, do something else here
2021-05-03 09:31:09 +02:00
cy.get("input[name=apiKey]").type(name).should("have.value", name)
cy.contains("Next").click()
}
})
.then(() => {
cy.get(".spectrum-Modal")
.within(() => {
2021-05-03 09:31:09 +02:00
cy.get("input").eq(0).type(name).should("have.value", name).blur()
cy.contains("Next").click()
2021-05-03 09:31:09 +02:00
cy.get("input").eq(1).type("test@test.com").blur()
cy.get("input").eq(2).type("test").blur()
cy.contains("Submit").click()
})
.then(() => {
cy.get("[data-cy=new-table]", {
timeout: 20000,
}).should("be.visible")
})
})
})
2021-05-04 12:32:22 +02:00
Cypress.Commands.add("deleteApp", name => {
cy.visit(`localhost:${Cypress.env("PORT")}/builder`)
2021-05-04 12:32:22 +02:00
cy.get(".apps").then($apps => {
cy.wait(1000)
if ($apps.find(`[data-cy="app-${name}"]`).length) {
2021-05-03 09:31:09 +02:00
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()
2021-05-03 09:31:09 +02:00
cy.get("input").type("DELETE").blur()
cy.contains("Delete Entire App").click()
})
}
})
})
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")
cy.addColumn("dog", "age", "Number")
})
2021-05-04 12:32:22 +02:00
Cypress.Commands.add("createTable", tableName => {
// Enter table name
2020-10-27 16:26:07 +01:00
cy.get("[data-cy=new-table]").click()
cy.get(".spectrum-Modal").within(() => {
2021-05-03 09:31:09 +02:00
cy.get("input").first().type(tableName).blur()
cy.get(".spectrum-ButtonGroup").contains("Create").click()
2020-10-08 12:36:16 +02:00
})
2020-08-10 16:34:37 +02:00
cy.contains(tableName).should("be.visible")
})
2020-06-11 18:14:28 +02:00
2020-08-10 16:34:37 +02:00
Cypress.Commands.add("addColumn", (tableName, columnName, type) => {
// Select Table
2020-10-27 16:26:07 +01:00
cy.contains(".nav-item", tableName).click()
cy.contains("Create column").click()
2020-06-11 18:14:28 +02:00
// Configure column
cy.get(".spectrum-Modal").within(() => {
2021-05-03 09:31:09 +02:00
cy.get("input").first().type(columnName).blur()
2020-10-15 09:17:26 +02:00
// Unset table display column
cy.contains("display column").click({ force: true })
cy.get("select").select(type)
cy.contains("Save").click()
})
})
2021-05-04 12:32:22 +02:00
Cypress.Commands.add("addRow", values => {
cy.contains("Create row").click()
cy.get(".spectrum-Modal").within(() => {
for (let i = 0; i < values.length; i++) {
2021-05-03 09:31:09 +02:00
cy.get("input").eq(i).type(values[i]).blur()
}
2021-05-03 09:31:09 +02:00
cy.get(".spectrum-ButtonGroup").contains("Create").click()
})
})
Cypress.Commands.add("createUser", (email, password, role) => {
2020-06-11 18:14:28 +02:00
// Create User
cy.contains("Users").click()
cy.contains("Create user").click()
cy.get(".spectrum-Modal").within(() => {
2021-05-03 09:31:09 +02:00
cy.get("input").first().type(email).blur()
cy.get("input").eq(1).type(password).blur()
cy.get("select").first().select(role)
2020-11-27 14:17:31 +01:00
// Save
2021-05-03 09:31:09 +02:00
cy.get(".spectrum-ButtonGroup").contains("Create User").click()
2020-11-27 14:17:31 +01:00
})
})
Cypress.Commands.add("addComponent", (category, component) => {
if (category) {
cy.get(`[data-cy="category-${category}"]`).click()
}
cy.get(`[data-cy="component-${component}"]`).click()
2021-04-01 11:08:58 +02:00
cy.wait(1000)
2021-05-04 12:32:22 +02:00
cy.location().then(loc => {
const params = loc.pathname.split("/")
const componentId = params[params.length - 1]
cy.getComponent(componentId).should("exist")
return cy.wrap(componentId)
})
})
2021-05-04 12:32:22 +02:00
Cypress.Commands.add("getComponent", componentId => {
return cy
.get("iframe")
.its("0.contentDocument")
.should("exist")
.its("body")
.should("not.be.null")
.then(cy.wrap)
.find(`[data-component-id=${componentId}]`)
2020-06-11 18:14:28 +02:00
})
2020-06-24 17:16:06 +02:00
2020-06-24 17:20:58 +02:00
Cypress.Commands.add("navigateToFrontend", () => {
2020-10-27 16:26:07 +01:00
cy.contains("design").click()
2020-06-24 17:16:06 +02:00
})
Cypress.Commands.add("createScreen", (screenName, route) => {
2020-10-27 16:26:07 +01:00
cy.get("[data-cy=new-screen]").click()
cy.get(".spectrum-Modal").within(() => {
2021-05-03 09:31:09 +02:00
cy.get("input").eq(0).type(screenName).blur()
2020-10-05 13:37:03 +02:00
if (route) {
2021-05-03 09:31:09 +02:00
cy.get("input").eq(1).type(route).blur()
2020-10-05 13:37:03 +02:00
}
2020-06-24 17:20:58 +02:00
cy.contains("Create Screen").click()
})
cy.get(".nav-items-container").within(() => {
2020-11-20 12:41:17 +01:00
cy.contains(route).should("exist")
2020-06-24 17:20:58 +02:00
})
})