import { cleanup, render, screen } from '@testing-library/react';
import { afterEach, expect, test } from 'vitest';
import { PlatformTime } from './PlatformTime';

afterEach(cleanup);

test('renders a semantic Shanghai timestamp while retaining the source value', () => {
  render(<PlatformTime value="2026-07-18 02:33:00" sourceZone="utc" />);

  const time = screen.getByText('2026-07-18 10:33:00');
  expect(time.tagName).toBe('TIME');
  expect(time).toHaveAttribute('datetime', '2026-07-18 02:33:00');
  expect(time).toHaveAttribute('title', '2026-07-18 02:33:00 · 上海时间');
});

test('keeps empty timestamps compact and non-semantic', () => {
  render(<PlatformTime empty="尚未上报" />);
  expect(screen.getByText('尚未上报').tagName).toBe('SPAN');
});
