/**
 * Sample unit test to verify Vitest setup
 * This test validates that the testing framework is working correctly
 */

import { beforeEach, describe, expect, it, vi } from 'vitest';

describe('Vitest Setup Validation', () => {
  it('should run basic assertions', () => {
    expect(true).toBe(true);
    expect(1 + 1).toBe(2);
    expect('hello').toContain('ello');
  });

  it('should support async tests', async () => {
    const promise = Promise.resolve(42);
    const result = await promise;
    expect(result).toBe(42);
  });

  it('should support mocking', () => {
    const mockFn = vi.fn().mockReturnValue('mocked');
    const result = mockFn();
    
    expect(mockFn).toHaveBeenCalled();
    expect(result).toBe('mocked');
  });

  it('should have DOM environment available', () => {
    // happy-dom provides DOM APIs
    expect(typeof document).toBe('object');
    expect(typeof window).toBe('object');
    expect(typeof HTMLElement).toBe('function');
  });
});

describe('DOM Manipulation Tests', () => {
  beforeEach(() => {
    // Reset document before each test
    document.body.innerHTML = '';
  });

  it('should create and manipulate DOM elements', () => {
    const div = document.createElement('div');
    div.id = 'test-element';
    div.textContent = 'Test Content';
    document.body.appendChild(div);

    const element = document.getElementById('test-element');
    expect(element).not.toBeNull();
    expect(element.textContent).toBe('Test Content');
  });

  it('should handle event listeners', () => {
    const button = document.createElement('button');
    const clickHandler = vi.fn();
    button.addEventListener('click', clickHandler);
    document.body.appendChild(button);

    button.click();
    expect(clickHandler).toHaveBeenCalledOnce();
  });

  it('should query elements with selectors', () => {
    document.body.innerHTML = `
      <div class="container">
        <span class="item">Item 1</span>
        <span class="item">Item 2</span>
        <span class="item">Item 3</span>
      </div>
    `;

    const items = document.querySelectorAll('.item');
    expect(items.length).toBe(3);
    expect(items[0].textContent).toBe('Item 1');
  });
});
