WIP components (as built)
This commit is contained in:
70 files changed
+2610
-235
No files matched your search
@@ -14,8 +14,8 @@ var mentionSample = []ContextItem{
|
||||
{ID: "f2", Label: "seating.xlsx", Detail: "~/ball", Kind: ContextFile},
|
||||
}
|
||||
|
||||
// mentionTester filters items as an async source would, one frame late.
|
||||
type mentionTester struct {
|
||||
// contextMentionTester supplies filtered results one frame later.
|
||||
type contextMentionTester struct {
|
||||
text string
|
||||
items []ContextItem
|
||||
loading bool
|
||||
@@ -23,7 +23,7 @@ type mentionTester struct {
|
||||
queries []string
|
||||
}
|
||||
|
||||
func (m *mentionTester) view(c *ui.Context) {
|
||||
func (m *contextMentionTester) view(c *ui.Context) {
|
||||
Use(c, Settings{})
|
||||
ui.Column(c).Fill().Justify(ui.End).Padding(16).Children(func() {
|
||||
p := PromptComposer(c, &m.text, PromptComposerOptions{Label: "Prompt"})
|
||||
@@ -44,7 +44,7 @@ func (m *mentionTester) view(c *ui.Context) {
|
||||
}
|
||||
|
||||
func TestContextMentionMenuGroupsAndChooses(t *testing.T) {
|
||||
m := &mentionTester{}
|
||||
m := &contextMentionTester{}
|
||||
tt := ui.NewTester(m.view, 600, 500)
|
||||
_ = tt.Click("Prompt")
|
||||
tt.Type("Read @")
|
||||
@@ -68,7 +68,7 @@ func TestContextMentionMenuGroupsAndChooses(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestContextMentionMenuOnlyAfterSpaceAndLoading(t *testing.T) {
|
||||
m := &mentionTester{loading: true}
|
||||
m := &contextMentionTester{loading: true}
|
||||
tt := ui.NewTester(m.view, 600, 500)
|
||||
_ = tt.Click("Prompt")
|
||||
tt.Type("mail@host")
|
||||
@@ -93,16 +93,46 @@ func TestContextMentionMenuBadItem(t *testing.T) {
|
||||
t.Fatal("no panic for an item without ID")
|
||||
}
|
||||
}()
|
||||
m := &mentionTester{items: []ContextItem{{Label: "x"}}}
|
||||
m := &contextMentionTester{items: []ContextItem{{Label: "x"}}}
|
||||
ui.NewTester(m.view, 300, 300)
|
||||
}
|
||||
|
||||
func TestContextMentionMenuSnapshot(t *testing.T) {
|
||||
snapshotAfter(t, "context_mention_menu", 560, 420, func(c *ui.Context) {
|
||||
(*ui.Local(c.Root(), "m", func() *mentionTester { return &mentionTester{items: mentionSample} })).view(c)
|
||||
(*ui.Local(c.Root(), "m", func() *contextMentionTester { return &contextMentionTester{items: mentionSample} })).view(c)
|
||||
}, func(tt *ui.Tester) {
|
||||
_ = tt.Click("Prompt")
|
||||
tt.Type("Compare @")
|
||||
tt.Frame()
|
||||
})
|
||||
}
|
||||
|
||||
func TestContextMentionMenuAsyncFirstChoiceAndDisabledQuery(t *testing.T) {
|
||||
text, off := "@", false
|
||||
var items []ContextItem
|
||||
picked, queries := "", 0
|
||||
tt := ui.NewTester(func(c *ui.Context) {
|
||||
Use(c, Settings{})
|
||||
p := PromptComposer(c, &text, PromptComposerOptions{Label: "Prompt", Disabled: off})
|
||||
r := ContextMentionMenu(c, p, &text, items, ContextMentionOptions{Loading: items == nil})
|
||||
if r.QueryChanged() {
|
||||
queries++
|
||||
}
|
||||
if it, ok := r.Chosen(); ok {
|
||||
picked = it.ID
|
||||
}
|
||||
}, 400, 300)
|
||||
_ = tt.Click("Prompt")
|
||||
items = []ContextItem{{ID: "first", Label: "First", Kind: ContextDoc}}
|
||||
tt.Frame()
|
||||
tt.Key(0, ui.KeyEnter)
|
||||
if picked != "first" || text != "" {
|
||||
t.Errorf("async first choice: %q text %q", picked, text)
|
||||
}
|
||||
off, text = true, "@other"
|
||||
before := queries
|
||||
tt.Frame()
|
||||
if queries != before {
|
||||
t.Errorf("disabled menu issued %d queries", queries-before)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user