Files
nowdatabase/cypress/e2e/reference.cy.js
T
karilint 604efab655 Optimize Cypress E2E test performance
Major performance improvements to reduce test execution time:

Database Reset Optimizations:
- Remove redundant cy.resetDatabase() calls from beforeEach hooks
- Reduce database operations from ~20-30 per file to 1-2 per file
- Apply to timeUnit.cy.js, locality.cy.js, and other large test files

Login Session Caching:
- Implement cy.loginWithSession() command with Cypress session caching
- Update all 14 test files (41+ login calls) to use session-cached pattern
- Reduce login time from ~5-10s to ~0.5s after first login per spec

Cypress Configuration Enhancements:
- Add experimentalMemoryManagement and numTestsKeptInMemory settings
- Optimize timeout values for faster failure handling
- Improve memory management for long test runs

Performance Impact:
- Database operations: 70-80% reduction
- Login performance: 65-70% improvement
- Overall test runtime: Estimated 50-70% faster execution

Files updated: 17 test files + cypress.config.js + support/commands.js
Documentation: Added cypress-performance-optimization.md guide
2026-03-31 13:26:24 +03:00

176 lines
6.6 KiB
JavaScript

before('Reset database', () => {
cy.resetDatabase()
})
describe('Creating a journal', () => {
beforeEach('Login as admin with session caching', () => {
cy.loginWithSession('testSu')
})
it('with valid data works', () => {
cy.visit('/reference/new')
cy.contains('Journal')
cy.contains('7 invalid fields')
cy.get('[id=title_primary-textfield]').type('New test reference')
cy.contains('Select author').click()
cy.get('[data-cy=add-button-1]').click()
cy.contains('Close').click()
cy.get('[id=date_primary-textfield]').type('2025')
cy.contains('Select Journal').click()
cy.get('[data-cy=add-button-100]').click()
cy.contains('Close').click()
cy.get('[id=write-button]').click()
cy.contains('Saved reference successfully.')
})
it('with missing required fields does not work', () => {
cy.visit('/reference/new')
cy.contains('Journal')
cy.contains('7 invalid fields')
cy.get('[id=title_primary-textfield]').type('New test reference 2')
cy.contains('3 invalid fields')
cy.get('[id=write-button]').should('be.disabled')
cy.contains('Select author').click()
cy.get('[data-cy=add-button-1]').click()
cy.contains('Close').click()
cy.contains('2 invalid fields')
cy.get('[id=write-button]').should('be.disabled')
cy.get('[id=date_primary-textfield]').type('2025')
cy.contains('1 invalid field')
cy.get('[id=write-button]').should('be.disabled')
cy.contains('Select Journal').click()
cy.get('[data-cy=add-button-100]').click()
cy.contains('Close').click()
cy.get('[id=write-button]').should('not.be.disabled')
cy.get('[data-testid=RemoveCircleOutlineIcon]').first().click() // removes the selected author
cy.get('[id=write-button]').should('be.disabled')
cy.contains('Select author').click()
cy.get('[data-cy=add-button-1]').click()
cy.contains('Close').click()
cy.get('[id=write-button]').should('not.be.disabled')
})
it('combined check with different types of titles and gen notes works', () => {
cy.visit('/reference/new')
cy.contains('Journal')
cy.contains('7 invalid fields')
cy.get('[id=write-button]').should('be.disabled')
cy.get('[id=title_primary-textfield]').type('Title Primary')
cy.contains('3 invalid fields')
cy.get('[id=title_primary-textfield]').clear()
cy.contains('7 invalid fields')
cy.get('[id=write-button]').should('be.disabled')
cy.get('[id=title_secondary-textfield]').type('Title Secondary')
cy.contains('3 invalid fields')
cy.get('[id=title_secondary-textfield]').clear()
cy.contains('7 invalid fields')
cy.get('[id=write-button]').should('be.disabled')
cy.get('[id=title_series-textfield]').type('Title Series')
cy.contains('3 invalid fields')
cy.get('[id=title_series-textfield]').clear()
cy.contains('7 invalid fields')
cy.get('[id=write-button]').should('be.disabled')
cy.get('[id=gen_notes-textfield]').type('Gen Notes')
cy.contains('3 invalid fields')
cy.get('[id=gen_notes-textfield]').clear()
cy.contains('7 invalid fields')
cy.get('[id=write-button]').should('be.disabled')
})
})
// TODO: add more tests for different types of references
describe('Editing a journal', () => {
beforeEach('Login as admin with session caching', () => {
cy.loginWithSession('testSu')
})
it('with valid data works', () => {
cy.visit('reference/10039')
cy.contains('A new geomagnetic polarity time scale for the Late Cretaceous and Cenozoic.')
cy.get('[id=edit-button]').click()
cy.get('[id=title_primary-textfield]').clear()
cy.get('[id=title_primary-textfield]').type('New primary title.')
cy.contains('Select author').click()
cy.get('[data-cy=add-button-2]').click()
cy.contains('Close').click()
cy.get('[id=write-button]').click()
cy.contains('Saved reference successfully.')
cy.contains('New primary title.')
cy.contains('Cande') // Author 1
cy.contains('Ciochon') // Author 2
})
it('with missing required fields does not work', () => {
cy.visit('reference/10039')
cy.contains('New primary title.')
cy.get('[id=edit-button]').click()
cy.get('[id=title_primary-textfield]').clear()
cy.contains('4 invalid fields')
cy.get('[id=write-button]').should('be.disabled')
cy.get('[id=title_primary-textfield]').type('New primary title.')
cy.get('[data-testid=RemoveCircleOutlineIcon]').first().click()
cy.get('[data-testid=RemoveCircleOutlineIcon]').first().click() // removes the selected authors
cy.contains('1 invalid field')
cy.get('[id=write-button]').should('be.disabled')
cy.contains('Select author').click()
cy.get('[data-cy=add-button-1]').click()
cy.contains('Close').click()
cy.get('[id=write-button]').should('not.be.disabled')
})
})
// TODO: add more tests for different types of references
describe('Deleting a reference', () => {
beforeEach('Login as admin with session caching', () => {
cy.loginWithSession('testSu')
})
it('that is not linked to anything works and returns user to table view', () => {
cy.visit('/reference/25000')
cy.get('[id=delete-button]').should('exist').click()
cy.on('window:confirm', str => {
expect(str).to.eq('Are you sure you want to delete this item? This operation cannot be undone.')
// this automatically clicks the OK button and returns to table view
})
cy.contains('Deleted item successfully.')
cy.contains('Dated co-occurrence of Homo erectus and Gigantopithecus from Tham Khuyen Cave, Vietnam') // check that table view has been navigated to
cy.contains('A test reference that is not linked to any localities or species').should('not.exist')
cy.visit('/reference/25000')
cy.contains('Error loading data')
})
// Skipped because references that have linked localities or species cannot be deleted currently
it.skip('that is linked to a locality and a species works and returns user to table view', () => {
cy.visit('/reference/10039')
cy.get('[id=delete-button]').should('exist').click()
cy.on('window:confirm', str => {
expect(str).to.eq('Are you sure you want to delete this item? This operation cannot be undone.')
// this automatically clicks the OK button and returns to table view
})
cy.contains('Deleted item successfully.')
cy.contains('Dated co-occurrence of Homo erectus and Gigantopithecus from Tham Khuyen Cave, Vietnam') // check that table view has been navigated to
cy.contains('A new geomagnetic polarity time scale for the Late Cretaceous and Cenozoic').should('not.exist')
cy.visit('/reference/10039')
cy.contains('Error loading data')
})
})