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

126 lines
3.3 KiB
JavaScript
Raw Normal View History

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) => { ... })
Cypress.Commands.add("createApp", (name, description) => {
2020-06-11 18:14:28 +02:00
cy.get(".banner-button")
.click()
.get('input[name="name"]')
.type(name)
.should("have.value", name)
2020-06-11 18:14:28 +02:00
cy.get('textarea[name="description"]')
.type(description)
.should("have.value", description)
2020-06-11 18:14:28 +02:00
cy.contains("Save").click()
})
Cypress.Commands.add("createModel", (modelName, firstField, secondField) => {
2020-06-11 18:14:28 +02:00
// Enter model name
cy.get("[data-cy=Name]")
.click()
.type(modelName)
// Add 'name' field
cy.get("[data-cy=add-new-model-field]").click()
cy.get("[data-cy=Name]")
.click()
.type(firstField)
cy.contains("Save").click()
// Add 'age' field
cy.get("[data-cy=add-new-model-field]").click()
cy.get("[data-cy=Name]")
.click()
.type(secondField)
cy.get("select").select("number")
cy.contains("Save").click()
cy.contains(secondField).should("exist")
// Save model
cy.contains("Save").click()
})
Cypress.Commands.add("addRecord", (firstField, secondField) => {
2020-06-11 18:14:28 +02:00
cy.contains("Create new record").click()
2020-06-11 18:14:28 +02:00
cy.get("[data-cy=name-input]")
.click()
.type(firstField)
cy.get("[data-cy=age-input]")
.click()
.type(secondField)
2020-06-11 18:14:28 +02:00
// Save
cy.contains("Save").click()
})
Cypress.Commands.add("createUser", (username, password, level) => {
2020-06-11 18:14:28 +02:00
// Create User
cy.get(".nav-group-header > .ri-add-line").click()
2020-06-11 18:14:28 +02:00
cy.get("[data-cy=username]").type(username)
cy.get("[data-cy=password]").type(password)
cy.get("[data-cy=accessLevel]").select(level)
2020-06-11 18:14:28 +02:00
// Save
cy.contains("Save").click()
})
2020-06-11 18:14:28 +02:00
Cypress.Commands.add("addHeadlineComponent", text => {
cy.get(".switcher > :nth-child(2)").click()
2020-06-11 18:14:28 +02:00
cy.get("[data-cy=Text]").click()
cy.get("[data-cy=Headline]").click()
cy.get(".tabs > :nth-child(2)").click()
cy.get('input[type="text"]').type(text)
cy.contains("Design").click()
})
2020-06-11 18:14:28 +02:00
Cypress.Commands.add("addButtonComponent", () => {
cy.get(".switcher > :nth-child(2)").click()
2020-06-11 18:14:28 +02:00
cy.get("[data-cy=Button]").click()
})
2020-06-24 17:16:06 +02:00
2020-06-24 17:20:58 +02:00
Cypress.Commands.add("navigateToFrontend", () => {
2020-06-24 17:58:30 +02:00
cy.get(".close", { timeout: 10000 }).click()
2020-06-24 17:20:58 +02:00
cy.contains("frontend").click()
2020-06-24 17:58:30 +02:00
cy.get(".close", { timeout: 10000 }).click()
2020-06-24 17:16:06 +02:00
})
Cypress.Commands.add("createScreen", (screenName, route) => {
2020-06-24 17:20:58 +02:00
cy.get(".newscreen").click()
cy.get(".uk-input:first").type(screenName)
if (route) {
cy.get(".uk-input:last").type(route)
}
cy.get(".uk-modal-footer").within(() => {
cy.contains("Create Screen").click()
})
cy.get(".nav-items-container").within(() => {
cy.contains(screenName).should("exist")
})
})