From 3ee5111d6f28db4600c3a00988f083389bfc80d5 Mon Sep 17 00:00:00 2001 From: kevmodrome Date: Thu, 11 Jun 2020 12:04:31 +0200 Subject: [PATCH] rework tests to use commands for DRYness --- .../cypress/integration/createApp.spec.js | 12 +--- .../cypress/integration/createModel.spec.js | 65 +++---------------- .../cypress/integration/createUser.spec.js | 19 ++++++ packages/builder/cypress/support/commands.js | 59 +++++++++++++++++ 4 files changed, 88 insertions(+), 67 deletions(-) create mode 100644 packages/builder/cypress/integration/createUser.spec.js diff --git a/packages/builder/cypress/integration/createApp.spec.js b/packages/builder/cypress/integration/createApp.spec.js index a6e488baf6..cbfbed06bb 100644 --- a/packages/builder/cypress/integration/createApp.spec.js +++ b/packages/builder/cypress/integration/createApp.spec.js @@ -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') }) }) diff --git a/packages/builder/cypress/integration/createModel.spec.js b/packages/builder/cypress/integration/createModel.spec.js index 50e523c598..ec447f07f9 100644 --- a/packages/builder/cypress/integration/createModel.spec.js +++ b/packages/builder/cypress/integration/createModel.spec.js @@ -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') }) diff --git a/packages/builder/cypress/integration/createUser.spec.js b/packages/builder/cypress/integration/createUser.spec.js new file mode 100644 index 0000000000..5d46ec780b --- /dev/null +++ b/packages/builder/cypress/integration/createUser.spec.js @@ -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') + }) +}) diff --git a/packages/builder/cypress/support/commands.js b/packages/builder/cypress/support/commands.js index ca4d256f3e..29a2e00673 100644 --- a/packages/builder/cypress/support/commands.js +++ b/packages/builder/cypress/support/commands.js @@ -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() +}) \ No newline at end of file