Files
oil-formula-calculator/frontend/cypress/support/e2e.js
Hera Zhao 8443f1a564
All checks were successful
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 5s
Test / build-check (push) Successful in 3s
PR Preview / test (pull_request) Successful in 4s
PR Preview / deploy-preview (pull_request) Successful in 10s
Test / e2e-test (push) Successful in 4m24s
Fix 5 wrong API endpoints + stop swallowing JS errors in E2E
Endpoint fixes:
- AuditLog: /api/audit-logs → /api/audit-log
- BugTracker: /api/bugs → /api/bug-reports, create → /api/bug-report
- BugTracker: fix create body (content+priority, not title/description)
- MyDiary: /api/brand-settings → /api/brand
- MyDiary: /api/me/display-name → PUT /api/me
- RecipeSearch: /api/category-modules → /api/categories

Test improvements:
- Remove blanket uncaught:exception swallow (only ignore ResizeObserver)
- Add endpoint-parity.cy.js: intercept-based test that verifies correct
  API endpoints are called and wrong ones are NOT called

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-06 21:30:54 +00:00

40 lines
1.1 KiB
JavaScript

// Log uncaught exceptions but don't swallow them blindly.
// Only ignore known non-critical errors (e.g. ResizeObserver).
Cypress.on('uncaught:exception', (err) => {
// ResizeObserver loop errors are harmless
if (err.message.includes('ResizeObserver')) return false
// Let all other errors fail the test
return true
})
// Custom commands for the oil calculator app
// Login as admin via token injection
Cypress.Commands.add('loginAsAdmin', () => {
cy.request('GET', '/api/users').then((res) => {
const admin = res.body.find(u => u.role === 'admin')
if (admin) {
cy.window().then(win => {
win.localStorage.setItem('oil_auth_token', admin.token)
})
}
})
})
// Login with a specific token
Cypress.Commands.add('loginWithToken', (token) => {
cy.window().then(win => {
win.localStorage.setItem('oil_auth_token', token)
})
})
// Verify toast message appears
Cypress.Commands.add('expectToast', (text) => {
cy.get('.toast').should('contain', text)
})
// Navigate via nav tabs
Cypress.Commands.add('goToSection', (label) => {
cy.get('.nav-tab').contains(label).click()
})