import { mount } from '@vue/test-utils';
import { nextTick } from 'vue';

import { describe, expect, it, vi } from 'vitest';

import ChatTimeMarkdown from '../ChatTimeMarkdown.vue';

vi.mock('@easyflow-core/preferences', () => ({
  usePreferences: () => ({
    isDark: false,
  }),
}));

describe('chatTimeMarkdown', () => {
  it('renders a single source line break as a visible line break', async () => {
    const wrapper = mount(ChatTimeMarkdown, {
      props: {
        content: '问题：你是谁\n答案：你好',
      },
    });

    await nextTick();

    expect(wrapper.text()).toContain('问题：你是谁');
    expect(wrapper.text()).toContain('答案：你好');
    expect(wrapper.find('br').exists()).toBe(true);
  });

  it('renders mermaid code fences with the shared mermaid block', async () => {
    const wrapper = mount(ChatTimeMarkdown, {
      props: {
        content: [
          '```mermaid',
          'flowchart TD',
          'A[开始] --> B[结束]',
          '```',
        ].join('\n'),
      },
    });

    await nextTick();

    expect(wrapper.find('.incremark-mermaid').exists()).toBe(true);
    expect(wrapper.find('.mermaid-header').text().toLowerCase()).toContain(
      'mermaid',
    );
    expect(wrapper.find('.mermaid-source-code').text()).toContain(
      'flowchart TD',
    );
  });
});
