WIP fixing tests

This commit is contained in:
vilmibm 2023-01-31 12:06:32 -08:00
parent 3ab72f44d3
commit 37eee30411
2 changed files with 30 additions and 8 deletions

View file

@ -8,6 +8,7 @@ import (
"net/http"
"os"
"strings"
"sync"
"time"
"github.com/MakeNowJust/heredoc"
@ -86,11 +87,12 @@ func (e extEntry) Description() string {
}
type extList struct {
ui uiRegistry
extEntries []extEntry
app *tview.Application
filter string
opts ExtBrowseOpts
ui uiRegistry
extEntries []extEntry
app *tview.Application
filter string
opts ExtBrowseOpts
QueueUpdateDraw func(func())
}
func newExtList(opts ExtBrowseOpts, ui uiRegistry, extEntries []extEntry) *extList {
@ -108,6 +110,9 @@ func newExtList(opts ExtBrowseOpts, ui uiRegistry, extEntries []extEntry) *extLi
extEntries: extEntries,
app: ui.App,
opts: opts,
QueueUpdateDraw: func(f func()) {
ui.App.QueueUpdateDraw(f)
},
}
el.Reset()
@ -143,11 +148,15 @@ func (el *extList) InstallSelected() {
modal.SetText(fmt.Sprintf("Installing %s...", ee.FullName))
el.ui.CmdFlex.Clear()
el.ui.CmdFlex.AddItem(modal, 0, 1, true)
wg := sync.WaitGroup{}
wg.Add(1)
go func() {
el.app.QueueUpdateDraw(func() {
el.QueueUpdateDraw(func() {
el.ui.Pages.SwitchToPage("command")
wg.Add(1)
wg.Done()
go func() {
el.app.QueueUpdateDraw(func() {
el.QueueUpdateDraw(func() {
err = el.opts.Em.Install(repo, "")
if err != nil {
modal.SetText(fmt.Sprintf("Failed to install %s: %s", ee.FullName, err.Error()))
@ -155,12 +164,17 @@ func (el *extList) InstallSelected() {
modal.SetText(fmt.Sprintf("Installed %s!", ee.FullName))
modal.AddButtons([]string{"ok"})
el.app.SetFocus(modal)
el.toggleInstalled(ix)
}
wg.Done()
})
}()
})
}()
wg.Wait()
if err == nil {
el.toggleInstalled(ix)
}
}
func (el *extList) RemoveSelected() {

View file

@ -277,10 +277,12 @@ func Test_extList(t *testing.T) {
cmdFlex := tview.NewFlex()
app := tview.NewApplication()
list := tview.NewList()
pages := tview.NewPages()
ui := uiRegistry{
List: list,
App: app,
CmdFlex: cmdFlex,
Pages: pages,
}
extEntries := []extEntry{
{
@ -315,6 +317,10 @@ func Test_extList(t *testing.T) {
extList := newExtList(opts, ui, extEntries)
extList.QueueUpdateDraw = func(f func()) {
f()
}
extList.Filter("cool")
assert.Equal(t, 1, extList.ui.List.GetItemCount())
@ -324,6 +330,8 @@ func Test_extList(t *testing.T) {
extList.InstallSelected()
assert.True(t, extList.extEntries[0].Installed)
// so I think the goroutines are causing a later failure because the toggleInstalled isn't seen.
extList.Refresh()
assert.Equal(t, 1, extList.ui.List.GetItemCount())