/**
 * Plant Registration E2E Tests
 */

describe('Plant Registration', () => {
  beforeEach(() => {
    cy.visit('/plants/register');
    cy.waitForPageLoad();
  });

  it('should load the registration page', () => {
    cy.url().should('include', '/plants/register');
  });

  it('should display registration form', () => {
    cy.get('form').should('be.visible');
  });

  it('should have required form fields', () => {
    // Check for common form fields
    cy.get('input, select, textarea').should('have.length.at.least', 1);
  });

  it('should show validation errors for empty form submission', () => {
    // Try to submit empty form
    cy.get('form').within(() => {
      cy.get('button[type="submit"]').click();
    });
    // Form should not navigate away without valid data
    cy.url().should('include', '/plants/register');
  });

  describe('Form Validation', () => {
    it('should require plant name', () => {
      cy.get('input[name="name"]').should('exist');
    });

    it('should require plant species', () => {
      cy.get('input[name="species"], select[name="species"]').should('exist');
    });
  });

  describe('Anonymous Registration', () => {
    it('should allow anonymous registration', () => {
      cy.visit('/plants/register-anonymous');
      cy.waitForPageLoad();
      cy.url().should('include', '/plants/register-anonymous');
      cy.get('form').should('be.visible');
    });
  });
});
