package viral

import "testing"

func TestPickDefaultSelectedTags(t *testing.T) {
	tags := []SuggestedTag{
		{Tag: "轉職", SearchType: "短詞"},
		{Tag: "面試焦慮", SearchType: "短詞"},
		{Tag: "被裁怎麼辦", SearchType: "情境"},
		{Tag: "30歲轉職真實心得", SearchType: "情境"},
		{Tag: "努力不一定成功", SearchType: "語錄"},
		{Tag: "@powerfulceo", SearchType: "帳號"},
		{Tag: "薪水談判", SearchType: "短詞"},
	}
	out := PickDefaultSelectedTags(tags)
	if len(out) == 0 {
		t.Fatal("expected selected tags")
	}
	if len(out) > DefaultSelectedTagCount {
		t.Fatalf("expected at most %d tags, got %d", DefaultSelectedTagCount, len(out))
	}
	seen := map[string]struct{}{}
	for _, tag := range out {
		if _, ok := seen[tag]; ok {
			t.Fatalf("duplicate tag %q", tag)
		}
		seen[tag] = struct{}{}
	}
}

func TestPickDefaultSelectedTags_prefersIntentPreservingQueries(t *testing.T) {
	tags := []SuggestedTag{
		{Tag: "老公吃什麼", SearchType: "短詞"},
		{Tag: "多閱讀", SearchType: "短詞"},
		{Tag: "備孕男生保健品", SearchType: "查詢"},
		{Tag: "精蟲品質吃什麼", SearchType: "查詢"},
		{Tag: "男性備孕葉酸鋅", SearchType: "情境"},
	}
	out := PickDefaultSelectedTags(tags)
	if len(out) < 2 {
		t.Fatalf("expected selected queries, got %#v", out)
	}
	if out[0] != "備孕男生保健品" || out[1] != "精蟲品質吃什麼" {
		t.Fatalf("expected complete intent queries first, got %#v", out)
	}
}
