Files
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

75 lines
3.1 KiB
JavaScript

before('Reset database', () => {
cy.resetDatabase()
})
describe('Change password form validates passwords correctly and shows errors to the user', () => {
beforeEach('Login as admin', () => {
cy.loginWithSession('testSu')
})
it('Missing fields are not allowed', () => {
cy.visit('/person/user-page/')
cy.contains('Change password')
cy.get('[id=change-password-button]').should('be.disabled')
cy.get('[id=old-password-textfield]').type('test')
cy.get('[id=change-password-button]').should('be.disabled')
cy.get('[id=new-password-textfield]').type('test2')
cy.get('[id=change-password-button]').should('be.disabled')
cy.get('[id=new-password-verification-textfield]').type('test2')
cy.get('[id=change-password-button]').should('be.disabled')
})
it('Incorrect old password', () => {
cy.visit('/person/user-page/')
cy.contains('Change password')
cy.get('[id=old-password-textfield]').type('incorrect')
cy.get('[id=new-password-textfield]').type('Password1!')
cy.get('[id=new-password-verification-textfield]').type('Password1!')
cy.get('[id=change-password-button]').click()
cy.contains('Old password does not match your current password.')
})
it('Invalid new password', () => {
cy.visit('/person/user-page/')
cy.contains('Change password')
cy.get('[id=old-password-textfield]').type('test')
cy.get('[id=new-password-textfield]').type('short')
cy.get('[id=new-password-verification-textfield]').type('short')
cy.get('[id=change-password-button]').should('be.disabled')
cy.contains('Password must be at least 8 characters long')
cy.get('[id=new-password-textfield]').clear()
cy.get('[id=new-password-textfield]').type('€uroisnotallowed')
cy.get('[id=new-password-verification-textfield]').clear()
cy.get('[id=new-password-verification-textfield]').type('€uroisnotallowed')
cy.get('[id=change-password-button]').should('be.disabled')
cy.contains('Password must only contain characters a-z, A-Z, 0-9 and ^?$%&~!')
})
it('New password and verification do not match', () => {
cy.visit('/person/user-page/')
cy.contains('Change password')
cy.get('[id=old-password-textfield]').type('test')
cy.get('[id=new-password-textfield]').type('Password1!')
cy.get('[id=new-password-verification-textfield]').type('Password')
cy.get('[id=change-password-button]').should('be.disabled')
})
it('Changing succeeds with valid password', () => {
cy.visit('/person/user-page/')
cy.contains('Change password')
cy.get('[id=old-password-textfield]').type('test')
cy.get('[id=new-password-textfield]').type('Password1!')
cy.get('[id=new-password-verification-textfield]').type('Password1!')
cy.get('[id=change-password-button]').click()
cy.contains('Password changed successfully.')
// test that password is actually updated
cy.get('[id=old-password-textfield]').type('Password1!')
cy.get('[id=new-password-textfield]').type('Password2!')
cy.get('[id=new-password-verification-textfield]').type('Password2!')
cy.get('[id=change-password-button]').click()
cy.contains('Password changed successfully.')
})
})