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
|
|
|
|
// ***********************************************
|
|
|
|
//
|
2020-06-11 22:04:31 +12:00
|
|
|
|
2021-04-16 00:23:42 +12:00
|
|
|
Cypress.Commands.add("login", () => {
|
2021-05-04 22:32:22 +12:00
|
|
|
cy.getCookie("budibase:auth").then(cookie => {
|
2021-04-16 05:34:49 +12:00
|
|
|
// Already logged in
|
2021-04-16 05:29:11 +12:00
|
|
|
if (cookie) return
|
2021-04-16 04:46:47 +12:00
|
|
|
|
2021-04-16 05:29:11 +12:00
|
|
|
cy.visit(`localhost:${Cypress.env("PORT")}/builder`)
|
|
|
|
|
2021-05-25 03:32:42 +12:00
|
|
|
// cy.get("button").then(btn => {
|
|
|
|
// const adminUserButton = "Create super admin user"
|
|
|
|
// console.log(btn.first().first())
|
|
|
|
// if (!btn.first().contains(adminUserButton)) {
|
|
|
|
// // 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(adminUserButton).click()
|
|
|
|
// }
|
2021-04-16 00:23:42 +12:00
|
|
|
|
2021-05-25 03:32:42 +12:00
|
|
|
// login
|
|
|
|
cy.get("input").first().type("test@test.com")
|
|
|
|
cy.get('input[type="password"]').type("test")
|
|
|
|
cy.contains("Login").click()
|
|
|
|
// })
|
2021-04-16 05:29:11 +12:00
|
|
|
})
|
2021-04-15 23:14:50 +12:00
|
|
|
})
|
2020-06-11 22:04:31 +12:00
|
|
|
|
2021-05-04 22:32:22 +12:00
|
|
|
Cypress.Commands.add("createApp", name => {
|
2021-04-01 22:06:22 +13:00
|
|
|
cy.visit(`localhost:${Cypress.env("PORT")}/builder`)
|
2021-04-08 07:19:25 +12:00
|
|
|
// wait for init API calls on visit
|
|
|
|
cy.wait(100)
|
2020-08-06 02:18:28 +12:00
|
|
|
cy.contains("Create New Web App").click()
|
|
|
|
cy.get("body")
|
2021-05-04 22:32:22 +12:00
|
|
|
.then($body => {
|
2020-08-06 02:18:28 +12:00
|
|
|
if ($body.find("input[name=apiKey]").length) {
|
|
|
|
// input was found, do something else here
|
2021-05-03 19:31:09 +12:00
|
|
|
cy.get("input[name=apiKey]").type(name).should("have.value", name)
|
2020-08-06 02:18:28 +12:00
|
|
|
cy.contains("Next").click()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(() => {
|
2021-04-29 01:56:31 +12:00
|
|
|
cy.get(".spectrum-Modal")
|
|
|
|
.within(() => {
|
2021-05-03 19:31:09 +12:00
|
|
|
cy.get("input").eq(0).type(name).should("have.value", name).blur()
|
2021-04-29 01:56:31 +12:00
|
|
|
cy.contains("Next").click()
|
2021-05-03 19:31:09 +12:00
|
|
|
cy.get("input").eq(1).type("test@test.com").blur()
|
|
|
|
cy.get("input").eq(2).type("test").blur()
|
2021-04-29 01:56:31 +12:00
|
|
|
cy.contains("Submit").click()
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
cy.get("[data-cy=new-table]", {
|
|
|
|
timeout: 20000,
|
|
|
|
}).should("be.visible")
|
|
|
|
})
|
2020-08-06 02:18:28 +12:00
|
|
|
})
|
2020-06-11 22:04:31 +12:00
|
|
|
})
|
2020-08-06 02:18:28 +12:00
|
|
|
|
2021-05-04 22:32:22 +12:00
|
|
|
Cypress.Commands.add("deleteApp", name => {
|
2021-04-01 22:06:22 +13:00
|
|
|
cy.visit(`localhost:${Cypress.env("PORT")}/builder`)
|
2021-05-04 22:32:22 +12:00
|
|
|
cy.get(".apps").then($apps => {
|
2021-03-06 02:52:26 +13:00
|
|
|
cy.wait(1000)
|
2021-04-08 02:08:59 +12:00
|
|
|
if ($apps.find(`[data-cy="app-${name}"]`).length) {
|
2021-05-03 19:31:09 +12:00
|
|
|
cy.get(`[data-cy="app-${name}"]`).contains("Open").click()
|
2021-03-06 02:52:26 +13:00
|
|
|
cy.get("[data-cy=settings-icon]").click()
|
2021-04-29 01:56:31 +12:00
|
|
|
cy.get(".spectrum-Dialog").within(() => {
|
2021-03-06 02:52:26 +13:00
|
|
|
cy.contains("Danger Zone").click()
|
2021-05-03 19:31:09 +12:00
|
|
|
cy.get("input").type("DELETE").blur()
|
2021-03-06 02:52:26 +13:00
|
|
|
cy.contains("Delete Entire App").click()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-03-06 03:36:38 +13:00
|
|
|
Cypress.Commands.add("createTestApp", () => {
|
|
|
|
const appName = "Cypress Tests"
|
|
|
|
cy.deleteApp(appName)
|
|
|
|
cy.createApp(appName, "This app is used for Cypress testing.")
|
|
|
|
})
|
|
|
|
|
2020-09-03 23:02:15 +12:00
|
|
|
Cypress.Commands.add("createTestTableWithData", () => {
|
|
|
|
cy.createTable("dog")
|
2020-10-05 23:13:09 +13:00
|
|
|
cy.addColumn("dog", "name", "Text")
|
2020-09-03 23:02:15 +12:00
|
|
|
cy.addColumn("dog", "age", "Number")
|
|
|
|
})
|
|
|
|
|
2021-05-04 22:32:22 +12:00
|
|
|
Cypress.Commands.add("createTable", tableName => {
|
2020-10-10 06:49:23 +13:00
|
|
|
// Enter table name
|
2020-10-28 04:26:07 +13:00
|
|
|
cy.get("[data-cy=new-table]").click()
|
2021-04-29 02:08:43 +12:00
|
|
|
cy.get(".spectrum-Modal").within(() => {
|
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
|
|
|
|
2020-08-11 02:34:37 +12:00
|
|
|
Cypress.Commands.add("addColumn", (tableName, columnName, type) => {
|
|
|
|
// Select Table
|
2020-10-28 04:26:07 +13:00
|
|
|
cy.contains(".nav-item", tableName).click()
|
2021-04-29 02:08:43 +12:00
|
|
|
cy.contains("Create column").click()
|
2020-06-12 04:14:28 +12:00
|
|
|
|
2020-10-05 23:13:09 +13:00
|
|
|
// Configure column
|
2021-04-29 02:08:43 +12:00
|
|
|
cy.get(".spectrum-Modal").within(() => {
|
2021-05-03 19:31:09 +12:00
|
|
|
cy.get("input").first().type(columnName).blur()
|
2021-03-06 02:52:26 +13:00
|
|
|
|
2020-10-15 20:17:26 +13:00
|
|
|
// Unset table display column
|
2021-04-29 02:08:43 +12:00
|
|
|
cy.contains("display column").click({ force: true })
|
2020-10-05 23:13:09 +13:00
|
|
|
cy.get("select").select(type)
|
|
|
|
cy.contains("Save").click()
|
|
|
|
})
|
2020-06-11 22:04:31 +12:00
|
|
|
})
|
2020-08-06 02:18:28 +12:00
|
|
|
|
2021-05-04 22:32:22 +12:00
|
|
|
Cypress.Commands.add("addRow", values => {
|
2021-04-29 02:08:43 +12:00
|
|
|
cy.contains("Create row").click()
|
|
|
|
cy.get(".spectrum-Modal").within(() => {
|
2020-10-05 23:13:09 +13:00
|
|
|
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()
|
2020-10-05 23:13:09 +13:00
|
|
|
}
|
2021-05-03 19:31:09 +12:00
|
|
|
cy.get(".spectrum-ButtonGroup").contains("Create").click()
|
2020-10-05 23:13:09 +13:00
|
|
|
})
|
2020-06-11 22:04:31 +12:00
|
|
|
})
|
|
|
|
|
2020-12-08 07:08:20 +13:00
|
|
|
Cypress.Commands.add("createUser", (email, password, role) => {
|
2020-06-12 04:14:28 +12:00
|
|
|
// Create User
|
2020-08-06 02:18:28 +12:00
|
|
|
cy.contains("Users").click()
|
2021-04-29 02:08:43 +12:00
|
|
|
cy.contains("Create user").click()
|
|
|
|
cy.get(".spectrum-Modal").within(() => {
|
2021-05-03 19:31:09 +12:00
|
|
|
cy.get("input").first().type(email).blur()
|
|
|
|
cy.get("input").eq(1).type(password).blur()
|
|
|
|
cy.get("select").first().select(role)
|
2020-11-28 02:17:31 +13:00
|
|
|
|
|
|
|
// Save
|
2021-05-03 19:31:09 +12:00
|
|
|
cy.get(".spectrum-ButtonGroup").contains("Create User").click()
|
2020-11-28 02:17:31 +13:00
|
|
|
})
|
2020-06-11 22:56:16 +12:00
|
|
|
})
|
|
|
|
|
2021-03-06 02:52:26 +13: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 22:08:58 +13:00
|
|
|
cy.wait(1000)
|
2021-05-04 22:32:22 +12:00
|
|
|
cy.location().then(loc => {
|
2021-03-06 02:52:26 +13:00
|
|
|
const params = loc.pathname.split("/")
|
2021-03-09 00:57:56 +13:00
|
|
|
const componentId = params[params.length - 1]
|
|
|
|
cy.getComponent(componentId).should("exist")
|
|
|
|
return cy.wrap(componentId)
|
2021-03-06 02:52:26 +13:00
|
|
|
})
|
2020-06-12 02:40:07 +12:00
|
|
|
})
|
|
|
|
|
2021-05-04 22:32:22 +12:00
|
|
|
Cypress.Commands.add("getComponent", componentId => {
|
2021-03-06 02:52:26 +13:00
|
|
|
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-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", () => {
|
2020-10-28 04:26:07 +13:00
|
|
|
cy.contains("design").click()
|
2020-06-25 03:16:06 +12:00
|
|
|
})
|
|
|
|
|
|
|
|
Cypress.Commands.add("createScreen", (screenName, route) => {
|
2020-10-28 04:26:07 +13:00
|
|
|
cy.get("[data-cy=new-screen]").click()
|
2021-04-29 02:08:43 +12:00
|
|
|
cy.get(".spectrum-Modal").within(() => {
|
2021-05-03 19:31:09 +12:00
|
|
|
cy.get("input").eq(0).type(screenName).blur()
|
2020-10-06 00:37:03 +13:00
|
|
|
if (route) {
|
2021-05-03 19:31:09 +12:00
|
|
|
cy.get("input").eq(1).type(route).blur()
|
2020-10-06 00:37:03 +13:00
|
|
|
}
|
2020-06-25 03:20:58 +12:00
|
|
|
cy.contains("Create Screen").click()
|
|
|
|
})
|
|
|
|
cy.get(".nav-items-container").within(() => {
|
2020-11-21 00:41:17 +13:00
|
|
|
cy.contains(route).should("exist")
|
2020-06-25 03:20:58 +12:00
|
|
|
})
|
|
|
|
})
|