rework tests to use commands for DRYness

This commit is contained in:
kevmodrome 2020-06-11 12:04:31 +02:00
parent f1d968ae88
commit 3ee5111d6f
4 changed files with 88 additions and 67 deletions

View File

@ -8,18 +8,10 @@ context('Create Application', () => {
it('should create a new application', () => { it('should create a new application', () => {
// https://on.cypress.io/type // https://on.cypress.io/type
cy.get('.banner-button') cy.createApp('My Cool App', 'This is a description')
.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.visit('localhost:4001/_builder') 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', () => { context('Create Model', () => {
beforeEach(() => { before(() => {
cy.visit('localhost:4001/_builder') cy.visit('localhost:4001/_builder')
// https://on.cypress.io/type
cy.createApp('Model App', 'Model App Description')
}) })
// https://on.cypress.io/interacting-with-elements // https://on.cypress.io/interacting-with-elements
it('should create a new model', () => { 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"]') cy.createModel('dog', 'name', 'age')
.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()
// Check if model exists
cy.get('.title').should('have.text', 'dog') cy.get('.title').should('have.text', 'dog')
}) })
it('should add a record', () => { 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.addRecord('bob', '15')
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.contains('bob').should('have.text', 'bob') 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 -- // -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) // 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()
})