function loginAsAdmin(): void {
  cy.visit('/login')

  cy.get('[data-cy="login-email"]').type('admin@rabbigerzi.test')
  cy.get('[data-cy="login-password"]').type('password123!@#')
  cy.get('[data-cy="login-submit"]').click()

  cy.url().should('eq', Cypress.config().baseUrl + '/')
  cy.getCookie('auth_token').should('exist')
}

describe('cypress database reset', () => {
  it('can dirty element seed data', () => {
    loginAsAdmin()

    cy.visit('/admin/element/1')
    cy.get('[data-cy="admin-element-title"]')
      .clear()
      .type('Dirty Cypress Element')
    cy.get('[data-cy="admin-element-description"]')
      .clear()
      .type('Dirty Cypress description')
    cy.get('[data-cy="admin-element-rich-text"]')
      .click()
      .type('{selectAll}{backspace}Dirty Cypress rich text')
    cy.get('[data-cy="admin-element-save"]').click()

    cy.get('[data-cy="admin-element-status"]')
      .should('be.visible')
      .and('contain.text', 'Saved')
  })

  it('starts the next test from seeded element data', () => {
    cy.visit('/element/1')

    cy.contains('h1', 'Baderech HaAvodah').should('be.visible')
    cy.get('[data-cy="element-rich-text"]').should('not.exist')
  })
})
