1
0
Fork 0
mirror of synced 2024-06-18 18:35:37 +12:00
budibase/packages/builder/cypress/support/commands.js

250 lines
7.3 KiB
JavaScript
Raw Normal View History

2020-06-09 23:52:00 +12:00
// ***********************************************
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
2021-10-11 23:33:54 +13:00
Cypress.on("uncaught:exception", () => {
return false
})
2021-04-16 00:23:42 +12:00
Cypress.Commands.add("login", () => {
2022-01-20 04:19:02 +13:00
cy.visit(`localhost:${Cypress.env("PORT")}/builder`)
cy.wait(2000)
2021-05-26 00:25:42 +12:00
cy.url().then(url => {
if (url.includes("builder/admin")) {
// create admin user
cy.get("input").first().type("test@test.com")
cy.get('input[type="password"]').first().type("test")
cy.get('input[type="password"]').eq(1).type("test")
cy.contains("Create super admin user").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()
cy.wait(1000)
})
}
2021-04-16 05:29:11 +12:00
})
})
2021-05-04 22:32:22 +12:00
Cypress.Commands.add("createApp", name => {
2022-01-20 04:19:02 +13:00
cy.visit(`localhost:${Cypress.env("PORT")}/builder`)
cy.wait(500)
2022-01-21 00:51:41 +13:00
cy.request(`${Cypress.config().baseUrl}api/applications?status=all`)
.its("body")
.then(body => {
if (body.length > 0) {
cy.get(".spectrum-Button").contains("Create app").click({ force: true })
}
})
cy.get(".spectrum-Modal").within(() => {
cy.get("input").eq(0).type(name).should("have.value", name).blur()
cy.get(".spectrum-ButtonGroup").contains("Create app").click()
2022-01-20 04:19:02 +13:00
cy.wait(7000)
})
})
2022-01-20 04:19:02 +13:00
Cypress.Commands.add("deleteApp", appName => {
cy.visit(`localhost:${Cypress.env("PORT")}/builder`)
cy.wait(1000)
cy.request(`localhost:${Cypress.env("PORT")}/api/applications?status=all`)
.its("body")
.then(val => {
if (val.length > 0) {
2022-01-20 04:19:02 +13:00
cy.get(
".appTable > :nth-child(5) > :nth-child(2) > .spectrum-Icon"
).click()
cy.contains("Delete").click()
cy.get(".spectrum-Modal").within(() => {
cy.get("input").type(appName)
cy.get(".spectrum-Button--warning").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")
})
2022-01-20 04:19:02 +13:00
Cypress.Commands.add("createTable", tableName => {
cy.contains("Budibase DB").click()
cy.contains("Create new table").click()
cy.get(".spectrum-Modal").within(() => {
cy.wait(1000)
2021-05-03 19:31:09 +12:00
cy.get("input").first().type(tableName).blur()
cy.get(".spectrum-ButtonGroup").contains("Create").click()
2020-10-08 23:36:16 +13:00
})
2020-08-11 02:34:37 +12:00
cy.contains(tableName).should("be.visible")
})
2020-06-12 04:14:28 +12:00
2021-10-08 22:56:44 +13:00
Cypress.Commands.add(
"addColumn",
(tableName, columnName, type, multiOptions = null) => {
// Select Table
cy.selectTable(tableName)
cy.contains(".nav-item", tableName).click()
cy.contains("Create column").click()
// Configure column
cy.get(".spectrum-Modal").within(() => {
cy.get("input").first().type(columnName).blur()
// Unset table display column
cy.contains("display column").click({ force: true })
cy.get(".spectrum-Picker-label").click()
cy.contains(type).click()
// Add options for Multi-select Type
if (multiOptions !== null) {
cy.get(".spectrum-Textfield-input").eq(1).type(multiOptions)
}
2021-10-08 22:56:44 +13:00
cy.contains("Save Column").click()
})
}
)
2021-05-04 22:32:22 +12: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 19:31:09 +12:00
cy.get("input").eq(i).type(values[i]).blur()
}
2021-05-03 19:31:09 +12:00
cy.get(".spectrum-ButtonGroup").contains("Create").click()
})
})
Cypress.Commands.add("addRowMultiValue", values => {
cy.contains("Create row").click()
2021-10-08 22:56:44 +13:00
cy.get(".spectrum-Form-itemField")
.click()
.then(() => {
cy.get(".spectrum-Popover").within(() => {
for (let i = 0; i < values.length; i++) {
cy.get(".spectrum-Menu-item").eq(i).click()
}
})
cy.get(".spectrum-Dialog-grid").click("top")
cy.get(".spectrum-ButtonGroup").contains("Create").click()
})
})
Cypress.Commands.add("createUser", email => {
// quick hacky recorded way to create a user
cy.contains("Users").click()
cy.get(".spectrum-Button--primary").click()
cy.get(".spectrum-Picker-label").click()
cy.get(".spectrum-Menu-item:nth-child(2) > .spectrum-Menu-itemLabel").click()
2021-06-03 05:28:05 +12:00
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("addComponent", (category, component) => {
if (category) {
cy.get(`[data-cy="category-${category}"]`).click()
}
2021-10-08 22:56:44 +13:00
if (component) {
cy.get(`[data-cy="component-${component}"]`).click()
}
2021-04-01 22:08:58 +13:00
cy.wait(1000)
2021-05-04 22:32:22 +12: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 22:32:22 +12: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-id=${componentId}]`)
2020-06-12 04:14:28 +12:00
})
2020-06-25 03:16:06 +12:00
2020-06-25 03:20:58 +12:00
Cypress.Commands.add("navigateToFrontend", () => {
// Clicks on Design tab and then the Home nav item
2021-06-03 05:28:05 +12:00
cy.wait(1000)
2021-05-26 03:52:35 +12:00
cy.contains("Design").click()
cy.get(".spectrum-Search").type("/")
2022-01-20 04:19:02 +13:00
cy.createScreen("home", "home")
cy.addComponent("Elements", "Headline")
cy.get(".nav-item").contains("home").click()
2020-06-25 03:16:06 +12:00
})
Cypress.Commands.add("createScreen", (screenName, route) => {
2021-05-26 03:52:35 +12:00
cy.get("[aria-label=AddCircle]").click()
cy.get(".spectrum-Modal").within(() => {
2022-01-20 04:19:02 +13:00
cy.get(".item").first().click()
cy.get(".spectrum-Button--cta").click()
})
cy.get(".spectrum-Modal").within(() => {
2022-01-20 04:19:02 +13:00
cy.get("input").first().clear().type(screenName)
cy.get("input").eq(1).clear().type(route)
cy.get(".spectrum-Button--cta").click()
cy.wait(2000)
2020-06-25 03:20:58 +12:00
})
})
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 => {
2021-10-08 22:56:44 +13:00
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 })
})
})
Cypress.Commands.add("searchForApplication", appName => {
2022-01-20 04:19:02 +13:00
cy.get(".spectrum-Textfield").within(() => {
cy.get("input").eq(0).type(appName)
})
})