import { render } from '@testing-library/vue';
import { describe, expect, test, beforeEach, afterEach, vi } from 'vitest';
import UiSidebarProvider from '../UiSidebarProvider.vue';
import {
  createSidebarShell,
  mockMatchMediaDesktop,
} from './sidebar-test-helpers';

beforeEach(() => mockMatchMediaDesktop());
afterEach(() => vi.restoreAllMocks());

describe('UiSidebarProvider', () => {
  test('renders slot and core sidebar wrapper', () => {
    const { getByText, container } = render(UiSidebarProvider, {
      props: { defaultOpen: true },
      slots: { default: 'App' },
    });
    expect(getByText('App')).toBeInTheDocument();
    expect(
      container.querySelector('[data-slot="sidebar-wrapper"]'),
    ).toBeTruthy();
  });

  test('provides sidebar context when nested in shell', () => {
    const { container } = render(
      createSidebarShell('<span data-testid="inner">ok</span>'),
    );
    expect(container.querySelector('[data-slot="sidebar"]')).toBeTruthy();
    expect(container.querySelector('[data-testid="inner"]')).toBeTruthy();
  });
});
