import { act, render, screen } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';
import { TransientNotice } from './TransientNotice';

describe('TransientNotice', () => {
  it('renders a non-blocking notice and dismisses it after the timeout', () => {
    vi.useFakeTimers();
    const onDismiss = vi.fn();

    render(
      <TransientNotice
        notice={{ id: 1, message: '操作已完成', tone: 'success' }}
        onDismiss={onDismiss}
        durationMs={1000}
      />,
    );

    expect(screen.getByRole('status')).toHaveTextContent('操作已完成');
    expect(screen.getByRole('status').parentElement).toHaveClass('pointer-events-none');

    act(() => {
      vi.advanceTimersByTime(1000);
    });

    expect(onDismiss).toHaveBeenCalledTimes(1);
    vi.useRealTimers();
  });
});
