package com.ruoyi.web.modules.diagnosis.support;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

@DisplayName("ConsultMessagePreview")
class ConsultMessagePreviewTest
{
    @Test
    @DisplayName("文本截断与媒体文案")
    void preview()
    {
        assertEquals(ConsultSessionRules.PREVIEW_IMAGE,
                ConsultMessagePreview.build(ConsultSessionRules.MSG_TYPE_IMAGE, "http://x/a.jpg"));
        assertEquals(ConsultSessionRules.PREVIEW_VIDEO,
                ConsultMessagePreview.build(ConsultSessionRules.MSG_TYPE_VIDEO, "http://x/a.mp4"));
        assertEquals(ConsultSessionRules.PREVIEW_VOICE,
                ConsultMessagePreview.build(ConsultSessionRules.MSG_TYPE_VOICE, "http://x/a.mp3"));
        String longText = repeat('中', 60);
        assertEquals(50, ConsultMessagePreview.build(ConsultSessionRules.MSG_TYPE_TEXT, longText).length());
    }

    private static String repeat(char c, int n)
    {
        char[] arr = new char[n];
        java.util.Arrays.fill(arr, c);
        return new String(arr);
    }
}
