import { fireEvent, render, screen } from '@testing-library/react';
import { describe, expect, test, vi } from 'vitest';
import { MobileFilterToggle } from './MobileFilterToggle';

describe('MobileFilterToggle', () => {
  test('exposes the current filter summary and expanded state through a Semi button', () => {
    const onToggle = vi.fn();
    const { rerender } = render(<MobileFilterToggle summary="全部车辆 · 7 天" expanded={false} controls="vehicle-filter-dialog" onToggle={onToggle} collapsedLabel="修改" />);

    const collapsed = screen.getByRole('button', { name: '修改筛选条件：全部车辆 · 7 天' });
    expect(collapsed).toHaveClass('semi-button');
    expect(collapsed).toHaveAttribute('aria-expanded', 'false');
    expect(collapsed).toHaveAttribute('aria-controls', 'vehicle-filter-dialog');
    fireEvent.click(collapsed);
    expect(onToggle).toHaveBeenCalledTimes(1);

    rerender(<MobileFilterToggle summary="已选 2 辆 · 7 天" expanded controls="vehicle-filter-dialog" onToggle={onToggle} collapsedLabel="修改" />);
    expect(screen.getByRole('button', { name: '收起筛选条件：已选 2 辆 · 7 天' })).toHaveAttribute('aria-expanded', 'true');
  });
});
