78 lines
2.7 KiB
Go
78 lines
2.7 KiB
Go
// Copyright (c) 2026 Storm Dragon
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
package emoji
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.stormux.org/storm/cthulhu/internal/interaction"
|
|
)
|
|
|
|
func TestCatalogUniquenessAndSequences(t *testing.T) {
|
|
seen := map[string]bool{}
|
|
strip := strings.NewReplacer("\ufe0e", "", "\ufe0f", "")
|
|
for _, category := range categories {
|
|
for _, item := range category.choices {
|
|
id := strip.Replace(item.ID)
|
|
if seen[id] {
|
|
t.Fatalf("duplicate presentation: %q", item.ID)
|
|
}
|
|
seen[id] = true
|
|
}
|
|
}
|
|
if len(seen) != 500 || !seen["🧑🚀"] || !seen["🐐"] {
|
|
t.Fatalf("catalog missing entries: %d", len(seen))
|
|
}
|
|
}
|
|
func TestPickerSearchSelectionAndIndependentCategories(t *testing.T) {
|
|
session, err := NewSession(true)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := session.Opening().Speech; got != "Emoji Menu. All tab" {
|
|
t.Fatal(got)
|
|
}
|
|
session.Handle(interaction.Event{Key: interaction.Tab})
|
|
session.Handle(interaction.Event{Text: "astronaut"})
|
|
if got := session.Values()["grid"].Selected; got != "🧑🚀" {
|
|
t.Fatalf("sequence changed: %q", got)
|
|
}
|
|
// Empty results must not activate or retain a previous selection.
|
|
session.Handle(interaction.Event{Text: "zz"})
|
|
if session.Values()["grid"].Selected != "" || session.Handle(interaction.Event{Key: interaction.Enter}).Activated != "" {
|
|
t.Fatal("stale selection after empty search")
|
|
}
|
|
session.Handle(interaction.Event{Key: interaction.Backspace, Control: true})
|
|
session.Handle(interaction.Event{Text: "goat"})
|
|
if session.Values()["grid"].Selected != "🐐" {
|
|
t.Fatal("search not reset")
|
|
}
|
|
// Forward and reverse Tab include the checkbox and category strip.
|
|
session.Handle(interaction.Event{Key: interaction.Tab})
|
|
session.Handle(interaction.Event{Text: " "})
|
|
if session.Values()["copy"].Checked {
|
|
t.Fatal("checkbox did not toggle")
|
|
}
|
|
session.Handle(interaction.Event{Key: interaction.Tab})
|
|
session.Handle(interaction.Event{Key: interaction.Right})
|
|
session.Handle(interaction.Event{Key: interaction.Tab})
|
|
if strings.Contains(session.Presentation().Speech, "Goat") {
|
|
t.Fatal("category search leaked")
|
|
}
|
|
session.Handle(interaction.Event{Key: interaction.Tab, Shift: true})
|
|
session.Handle(interaction.Event{Key: interaction.Left})
|
|
session.Handle(interaction.Event{Key: interaction.Tab})
|
|
if session.Values()["grid"].Selected != "🐐" {
|
|
t.Fatal("category search not retained")
|
|
}
|
|
if got := session.Handle(interaction.Event{Key: interaction.Enter}).Activated; got != "select-grid-item" {
|
|
t.Fatal(got)
|
|
}
|
|
other, _ := NewSession(true)
|
|
other.Handle(interaction.Event{Key: interaction.Tab})
|
|
if other.Values()["grid"].Selected == "🐐" {
|
|
t.Fatal("new picker inherited search")
|
|
}
|
|
}
|