package usecase

import (
	"strings"
	"testing"

	"apps/backend/internal/module/search"

	"github.com/stretchr/testify/require"
)

func TestExtractTopicLabels_FromGQStyleTitle(t *testing.T) {
	// 報導標題 → 應抽出「二砂糖」「炎上展」這類短話題，而不是整段新聞標題
	h := search.Hit{
		Title:   "【一週脆報】本週 Threads 紅什麼：為什麼颱風來襲「二砂糖」比泡麵先被掃空？日本超夯「炎上展」登台",
		Snippet: "本週 Threads 完全成了大型苦中作樂現場",
	}
	labels := extractTopicLabels(h)
	require.NotEmpty(t, labels)
	joined := strings.Join(labels, " ")
	require.Contains(t, joined, "二砂糖")
	require.Contains(t, joined, "炎上展")
	for _, l := range labels {
		require.LessOrEqual(t, len([]rune(l)), 18)
		require.NotContains(t, l, "Threads新功能")
	}
}

func TestIsMetaThreadsArticle(t *testing.T) {
	require.True(t, isMetaThreadsArticle(search.Hit{
		Title: "Threads新功能上線！AI整理全台「趨勢話題」",
	}))
	require.False(t, isMetaThreadsArticle(search.Hit{
		Title: "本週 Threads 紅什麼：二砂糖與颱風備貨",
	}))
}
