// Ignore uncaught exceptions from the Vue app during E2E tests.
// Vue components may throw on API errors, missing data, etc.
// These are tracked separately; E2E tests focus on user-visible behavior.
Cypress.on('uncaught:exception', () => false)

// 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()
})
