import { renderHook, act } from '@testing-library/react';
import { describe, it, expect } from 'vitest';
import { LayoutProvider, useLayout, useOptionalLayout } from './LayoutContext';
import React from 'react';

describe('LayoutContext', () => {
  it('toggles sidebar', () => {
    const wrapper = ({ children }: { children: React.ReactNode }) => (
      <LayoutProvider>{children}</LayoutProvider>
    );

    const { result } = renderHook(() => useLayout(), { wrapper });

    // Default depends on screen size usually, but check initial
    const initial = result.current.sidebarExpanded;

    act(() => {
      result.current.toggleSidebar();
    });

    expect(result.current.sidebarExpanded).toBe(!initial);
  });

  it('returns null for optional layout outside the provider', () => {
    const { result } = renderHook(() => useOptionalLayout());

    expect(result.current).toBeNull();
  });
});
