Skip to content

Commit

Permalink
Add tests for models
Browse files Browse the repository at this point in the history
Such tests make use of the refactored login commands, which means
that only the first tests needs to log in via the GUI, while others
benefit from the session to be restored from the cache.

In this test suite, I've also create a custom command to cleanup
all existing models on the beforeEach hook so that tests always
start in a fresh state.
  • Loading branch information
wlsf82 committed Nov 15, 2021
1 parent d90cdb3 commit c7d21f0
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"apiUrl": "http://localhost:3000",
"experimentalSessionSupport": true,
"baseUrl": "http://localhost:9000",
"fixturesFolder": false,
Expand Down
56 changes: 56 additions & 0 deletions cypress/integration/models.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
describe('Models', () => {
beforeEach(() => {
cy.intercept('get', '/models?userId=*').as('getUserModels')
cy.login()
cy.visit('/#!/main')
cy.cleanUpUserModels()
cy.contains('a', 'Nova Modelagem').click()
cy.get('create-model-modal').should('be.visible')
})

it('opens and closes the "New Model" modal', () => {
cy.contains('button', 'Cancelar').click()
cy.get('create-model-modal').should('not.exist')
})

it('alerts when clicking SAVE without filling the title', () => {
cy.contains('button', 'Salvar').click()
cy.get('#name').should('have.class', 'error')
})

context('Model creation', () => {
const modelTitle = 'User'

beforeEach(() => cy.get('#name').type(modelTitle))

it('creates a conceptual model', () => {
cy.contains('button', 'Salvar').click()

cy.contains('h2', `Modelo conceitual de: ${modelTitle}`)
.should('be.visible')
})

it('creates a logical model', () => {
cy.get('.modelselect').click()
cy.contains('li span', 'Lógico').click()
cy.contains('button', 'Salvar').click()

cy.contains('h2', `Modelo lógico de: ${modelTitle}`)
.should('be.visible')
})
})
})

Cypress.Commands.add('cleanUpUserModels', () => {
cy.wait('@getUserModels').then(userModels => {
cy.request('GET', userModels.response.url).then(userModelsResponse => {
userModelsResponse.body.forEach(model => {
cy.request(
'DELETE',
`${Cypress.config('apiUrl')}/models/:modelId?modelId=${model._id}`
)
})
})
})
cy.reload()
})

0 comments on commit c7d21f0

Please sign in to comment.