2020-06-09 13:52:00 +02:00
|
|
|
// ***********************************************
|
|
|
|
// This example commands.js shows you how to
|
|
|
|
// create various custom commands and overwrite
|
|
|
|
// existing commands.
|
|
|
|
//
|
|
|
|
// For more comprehensive examples of custom
|
|
|
|
// commands please read more here:
|
|
|
|
// https://on.cypress.io/custom-commands
|
|
|
|
// ***********************************************
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// -- This is a parent command --
|
|
|
|
// Cypress.Commands.add("login", (email, password) => { ... })
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// -- This is a child command --
|
|
|
|
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// -- This is a dual command --
|
|
|
|
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// -- This will overwrite an existing command --
|
|
|
|
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
|
2020-06-11 12:04:31 +02:00
|
|
|
|
2021-04-15 14:23:42 +02:00
|
|
|
Cypress.Commands.add("login", () => {
|
2021-04-15 19:29:11 +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()
|
|
|
|
cy.get("input")
|
|
|
|
.first()
|
|
|
|
.type("test@test.com")
|
|
|
|
|
|
|
|
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-04-15 13:14:50 +02:00
|
|
|
})
|
|
|
|
|
2020-08-05 16:18:28 +02:00
|
|
|
Cypress.Commands.add("createApp", name => {
|
2021-04-01 11:06:22 +02:00
|
|
|
cy.visit(`localhost:${Cypress.env("PORT")}/builder`)
|
2021-04-07 21:19:25 +02:00
|
|
|
// wait for init API calls on visit
|
|
|
|
cy.wait(100)
|
2020-08-05 16:18:28 +02:00
|
|
|
cy.contains("Create New Web App").click()
|
|
|
|
cy.get("body")
|
|
|
|
.then($body => {
|
|
|
|
if ($body.find("input[name=apiKey]").length) {
|
|
|
|
// input was found, do something else here
|
2020-10-28 18:40:14 +01:00
|
|
|
cy.get("input[name=apiKey]")
|
|
|
|
.type(name)
|
|
|
|
.should("have.value", name)
|
2020-08-05 16:18:28 +02:00
|
|
|
cy.contains("Next").click()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
cy.get("input[name=applicationName]")
|
|
|
|
.type(name)
|
|
|
|
.should("have.value", name)
|
|
|
|
cy.contains("Next").click()
|
|
|
|
cy.contains("Submit").click()
|
2020-10-27 16:26:07 +01:00
|
|
|
cy.get("[data-cy=new-table]", {
|
2020-09-05 01:03:08 +02:00
|
|
|
timeout: 20000,
|
2020-08-05 16:18:28 +02:00
|
|
|
}).should("be.visible")
|
|
|
|
})
|
2020-06-11 12:04:31 +02:00
|
|
|
})
|
2020-08-05 16:18:28 +02:00
|
|
|
|
2021-03-05 14:52:26 +01:00
|
|
|
Cypress.Commands.add("deleteApp", name => {
|
2021-04-01 11:06:22 +02:00
|
|
|
cy.visit(`localhost:${Cypress.env("PORT")}/builder`)
|
2021-04-07 16:08:59 +02:00
|
|
|
cy.get(".apps").then($apps => {
|
2021-03-05 14:52:26 +01:00
|
|
|
cy.wait(1000)
|
2021-04-07 16:08:59 +02:00
|
|
|
if ($apps.find(`[data-cy="app-${name}"]`).length) {
|
2021-03-05 14:52:26 +01:00
|
|
|
cy.get(`[data-cy="app-${name}"] a`).click()
|
|
|
|
cy.get("[data-cy=settings-icon]").click()
|
|
|
|
cy.get(".modal-content").within(() => {
|
|
|
|
cy.contains("Danger Zone").click()
|
|
|
|
cy.get("input").type("DELETE")
|
|
|
|
cy.contains("Delete Entire App").click()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-03-05 15:36:38 +01: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 13:02:15 +02:00
|
|
|
Cypress.Commands.add("createTestTableWithData", () => {
|
|
|
|
cy.createTable("dog")
|
2020-10-05 12:13:09 +02:00
|
|
|
cy.addColumn("dog", "name", "Text")
|
2020-09-03 13:02:15 +02:00
|
|
|
cy.addColumn("dog", "age", "Number")
|
|
|
|
})
|
|
|
|
|
2020-08-10 16:34:37 +02:00
|
|
|
Cypress.Commands.add("createTable", tableName => {
|
2020-10-09 19:49:23 +02:00
|
|
|
// Enter table name
|
2020-10-27 16:26:07 +01:00
|
|
|
cy.get("[data-cy=new-table]").click()
|
2020-10-08 12:36:16 +02:00
|
|
|
cy.get(".modal").within(() => {
|
2020-10-28 18:40:14 +01:00
|
|
|
cy.get("input")
|
|
|
|
.first()
|
|
|
|
.type(tableName)
|
|
|
|
cy.get(".buttons")
|
|
|
|
.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()
|
2020-08-10 18:51:30 +02:00
|
|
|
cy.contains("Create New Column").click()
|
2020-06-11 18:14:28 +02:00
|
|
|
|
2020-10-05 12:13:09 +02:00
|
|
|
// Configure column
|
2020-10-26 22:43:04 +01:00
|
|
|
cy.get(".actions").within(() => {
|
2020-10-28 18:40:14 +01:00
|
|
|
cy.get("input")
|
|
|
|
.first()
|
|
|
|
.type(columnName)
|
2021-03-05 14:52:26 +01:00
|
|
|
|
2020-10-15 09:17:26 +02:00
|
|
|
// Unset table display column
|
|
|
|
cy.contains("display column").click()
|
2020-10-05 12:13:09 +02:00
|
|
|
cy.get("select").select(type)
|
|
|
|
cy.contains("Save").click()
|
|
|
|
})
|
2020-06-11 12:04:31 +02:00
|
|
|
})
|
2020-08-05 16:18:28 +02:00
|
|
|
|
2020-10-09 20:10:28 +02:00
|
|
|
Cypress.Commands.add("addRow", values => {
|
2020-08-10 18:51:30 +02:00
|
|
|
cy.contains("Create New Row").click()
|
2020-10-05 12:13:09 +02:00
|
|
|
cy.get(".modal").within(() => {
|
|
|
|
for (let i = 0; i < values.length; i++) {
|
2020-10-28 18:40:14 +01:00
|
|
|
cy.get("input")
|
|
|
|
.eq(i)
|
|
|
|
.type(values[i])
|
2020-10-05 12:13:09 +02:00
|
|
|
}
|
2020-10-28 18:40:14 +01:00
|
|
|
cy.get(".buttons")
|
|
|
|
.contains("Create")
|
|
|
|
.click()
|
2020-10-05 12:13:09 +02:00
|
|
|
})
|
2020-06-11 12:04:31 +02:00
|
|
|
})
|
|
|
|
|
2020-12-07 19:08:20 +01:00
|
|
|
Cypress.Commands.add("createUser", (email, password, role) => {
|
2020-06-11 18:14:28 +02:00
|
|
|
// Create User
|
2020-08-05 16:18:28 +02:00
|
|
|
cy.contains("Users").click()
|
2020-12-14 14:33:34 +01:00
|
|
|
cy.contains("Create New User").click()
|
2020-11-27 14:17:31 +01:00
|
|
|
cy.get(".modal").within(() => {
|
|
|
|
cy.get("input")
|
|
|
|
.first()
|
2020-12-08 14:16:53 +01:00
|
|
|
.type(email)
|
2020-11-27 14:17:31 +01:00
|
|
|
cy.get("input")
|
|
|
|
.eq(1)
|
2020-12-08 14:16:53 +01:00
|
|
|
.type(password)
|
2020-11-27 14:17:31 +01:00
|
|
|
cy.get("select")
|
|
|
|
.first()
|
2020-12-02 14:20:56 +01:00
|
|
|
.select(role)
|
2020-11-27 14:17:31 +01:00
|
|
|
|
|
|
|
// Save
|
|
|
|
cy.get(".buttons")
|
2020-12-08 14:16:53 +01:00
|
|
|
.contains("Create User")
|
2020-11-27 14:17:31 +01:00
|
|
|
.click()
|
|
|
|
})
|
2020-06-11 12:56:16 +02:00
|
|
|
})
|
|
|
|
|
2021-03-05 14:52:26 +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-03-05 14:52:26 +01:00
|
|
|
cy.location().then(loc => {
|
|
|
|
const params = loc.pathname.split("/")
|
2021-03-08 12:57:56 +01:00
|
|
|
const componentId = params[params.length - 1]
|
|
|
|
cy.getComponent(componentId).should("exist")
|
|
|
|
return cy.wrap(componentId)
|
2021-03-05 14:52:26 +01:00
|
|
|
})
|
2020-06-11 16:40:07 +02:00
|
|
|
})
|
|
|
|
|
2021-03-05 14:52:26 +01: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()
|
2020-10-05 13:37:03 +02:00
|
|
|
cy.get(".modal").within(() => {
|
2020-10-28 18:40:14 +01:00
|
|
|
cy.get("input")
|
|
|
|
.eq(0)
|
|
|
|
.type(screenName)
|
2020-10-05 13:37:03 +02:00
|
|
|
if (route) {
|
2020-10-28 18:40:14 +01:00
|
|
|
cy.get("input")
|
|
|
|
.eq(1)
|
|
|
|
.type(route)
|
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
|
|
|
})
|
|
|
|
})
|