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

164 lines
4.1 KiB
JavaScript
Raw Normal View History

2020-06-09 23:52:00 +12: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) => { ... })
Cypress.Commands.add("createApp", name => {
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
cy.get("input[name=apiKey]")
.type(name)
.should("have.value", name)
cy.contains("Next").click()
}
})
.then(() => {
cy.get("input[name=applicationName]")
.type(name)
.should("have.value", name)
cy.contains("Next").click()
cy.get("input[name=username]")
.click()
.type("test")
cy.get("input[name=password]")
.click()
.type("test")
cy.contains("Submit").click()
cy.contains("Create New Table", {
2020-09-05 11:03:08 +12:00
timeout: 20000,
}).should("be.visible")
})
})
Cypress.Commands.add("createTestTableWithData", () => {
cy.createTable("dog")
cy.addColumn("dog", "name", "Text")
cy.addColumn("dog", "age", "Number")
})
2020-08-11 02:34:37 +12:00
Cypress.Commands.add("createTable", tableName => {
2020-06-12 04:14:28 +12:00
// Enter model name
cy.contains("Create New Table").click()
cy.get(".menu-container")
.get("input")
2020-10-07 23:23:47 +13:00
.first()
.type(tableName)
2020-06-12 04:14:28 +12:00
2020-08-11 02:34:37 +12:00
cy.contains("Save").click()
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
cy.contains(tableName).click()
2020-08-11 04:51:30 +12:00
cy.contains("Create New Column").click()
2020-06-12 04:14:28 +12:00
// Configure column
cy.get(".menu-container").within(() => {
cy.get("input")
.first()
.type(columnName)
cy.get("select").select(type)
cy.contains("Save").click()
})
})
2020-08-11 04:51:30 +12:00
Cypress.Commands.add("addRecord", values => {
cy.contains("Create New Row").click()
cy.get(".modal").within(() => {
for (let i = 0; i < values.length; i++) {
cy.get("input")
.eq(i)
.type(values[i])
}
// Save
cy.get(".buttons")
.contains("Create")
.click()
})
})
Cypress.Commands.add("createUser", (username, password, accessLevel) => {
2020-06-12 04:14:28 +12:00
// Create User
cy.get(".toprightnav > .settings").click()
cy.contains("Users").click()
cy.get("[name=Name]")
.first()
.type(username)
cy.get("[name=Password]")
.first()
.type(password)
cy.get("select")
.first()
.select(accessLevel)
2020-06-12 04:14:28 +12:00
// Save
cy.get(".inputs")
.contains("Create")
.click()
})
2020-06-12 04:14:28 +12:00
Cypress.Commands.add("addHeadlineComponent", text => {
cy.get(".switcher > :nth-child(2)").click()
2020-06-12 04:14:28 +12:00
cy.get("[data-cy=Text]").click()
cy.get("[data-cy=Headline]").click()
cy.get(".tabs > :nth-child(2)").click()
cy.contains("Settings").click()
cy.get('input[name="text"]').type(text)
2020-06-12 04:14:28 +12:00
cy.contains("Design").click()
})
2020-06-12 04:14:28 +12:00
Cypress.Commands.add("addButtonComponent", () => {
cy.get(".switcher > :nth-child(2)").click()
2020-06-12 04:14:28 +12:00
cy.get("[data-cy=Button]").click()
})
2020-06-25 03:16:06 +12:00
2020-06-25 03:20:58 +12:00
Cypress.Commands.add("navigateToFrontend", () => {
cy.contains("frontend").click()
2020-06-25 03:16:06 +12:00
})
Cypress.Commands.add("createScreen", (screenName, route) => {
2020-10-06 00:37:03 +13:00
cy.contains("Create New Screen").click()
cy.get(".modal").within(() => {
cy.get("input:first").type(screenName)
if (route) {
cy.get("input:last").type(route)
}
2020-06-25 03:20:58 +12:00
cy.contains("Create Screen").click()
})
cy.get(".nav-items-container").within(() => {
cy.contains(screenName).should("exist")
})
})