1
0
Fork 0
mirror of synced 2024-06-18 18:35:37 +12:00

rework tests to use commands for DRYness

This commit is contained in:
kevmodrome 2020-06-11 12:04:31 +02:00
parent 989b042993
commit 202abaa13e
4 changed files with 88 additions and 67 deletions

View file

@ -8,18 +8,10 @@ context('Create Application', () => {
it('should create a new application', () => {
// https://on.cypress.io/type
cy.get('.banner-button')
.click()
.get('input[name="name"]')
.type('My Cool Application').should('have.value', 'My Cool Application')
cy.get('textarea[name="description"]')
.type('This is a description').should('have.value', 'This is a description')
cy.contains('Save').click()
cy.createApp('My Cool App', 'This is a description')
cy.visit('localhost:4001/_builder')
cy.contains('My Cool Application').should('exist')
cy.contains('My Cool App').should('exist')
})
})

View file

@ -1,73 +1,24 @@
context('Create Model', () => {
beforeEach(() => {
before(() => {
cy.visit('localhost:4001/_builder')
// https://on.cypress.io/type
cy.createApp('Model App', 'Model App Description')
})
// https://on.cypress.io/interacting-with-elements
it('should create a new model', () => {
// https://on.cypress.io/type
cy.get('.banner-button')
.click()
.get('input[name="name"]')
.type('My Cool Application').should('have.value', 'My Cool Application')
cy.get('textarea[name="description"]')
.type('This is a description').should('have.value', 'This is a description')
cy.contains('Save').click()
// Enter model name
cy.get('.budibase__input')
.type('dog')
// Add new field
cy.get('.new-field')
.click()
// Enter field name
cy.get('.budibase__input').first()
.type('name')
// Save
cy.contains('Save').click()
// Add new field
cy.get('.new-field')
.click()
// Enter field name
cy.get('.budibase__input').first()
.type('age')
cy.get('select').select('number')
// Save
cy.contains('Save').click()
cy.contains('age').should('exist')
// Save
cy.contains('Save').click()
cy.createModel('dog', 'name', 'age')
// Check if model exists
cy.get('.title').should('have.text', 'dog')
})
it('should add a record', () => {
// Page needs to be reloaded for some reason, cookie might be remove between tests?
cy.reload()
// Open just created app
cy.get(':nth-child(1) > .card-footer > .app-button')
.click()
// Open add record modal
cy.get('.button')
.click()
cy.get(':nth-child(1) > .uk-input').type('bob').get(':nth-child(2) > .uk-input').type('15')
// Save
cy.contains('Save').click()
cy.addRecord('bob', '15')
cy.contains('bob').should('have.text', 'bob')
})

View file

@ -0,0 +1,19 @@
context('Create Model', () => {
before(() => {
cy.visit('localhost:4001/_builder')
// https://on.cypress.io/type
cy.createApp('User App', 'This app is used to test user creation')
})
// https://on.cypress.io/interacting-with-elements
it('should create a user', () => {
// Close Model modal that shows up after creating an app
cy.get('.close').click()
cy.createUser('bbuser', 'test', 'ADMIN')
// Check to make sure user was created!
cy.contains('bbuser').should('have.text', 'bbuser')
})
})

View file

@ -23,3 +23,62 @@
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
Cypress.Commands.add("createApp", (name, description) => {
cy.get('.banner-button')
.click()
.get('input[name="name"]')
.type(name).should('have.value', name)
cy.get('textarea[name="description"]')
.type(description).should('have.value', description)
cy.contains('Save').click()
})
Cypress.Commands.add("createModel", (modelName, firstField, secondField) => {
// Enter model name
cy.get('.budibase__input')
.type(modelName)
// Add 'name' field
cy.get('.new-field')
.click()
cy.get('.budibase__input').first()
.type(firstField)
cy.contains('Save').click()
// Add 'age' field
cy.get('.new-field')
.click()
cy.get('.budibase__input').first()
.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) => {
cy.contains('Create new record')
.click()
cy.get(':nth-child(1) > .uk-input').type(firstField).get(':nth-child(2) > .uk-input').type(secondField)
// Save
cy.contains('Save').click()
})
Cypress.Commands.add("createUser", (username, password, level) => {
// Create User
cy.get('.nav-group-header > .ri-add-line')
.click()
cy.get(':nth-child(2) > .uk-input').type(username)
cy.get(':nth-child(3) > .uk-input').type(password)
cy.get('.uk-select').select(level)
// Save
cy.contains('Save').click()
})