Skip to content

Commit

Permalink
fix: set ui.currentDir at last
Browse files Browse the repository at this point in the history
  • Loading branch information
dundee committed Aug 27, 2021
1 parent 48703df commit fb01cc1
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 56 deletions.
11 changes: 6 additions & 5 deletions tui/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,23 @@ func (ui *UI) AnalyzePath(path string, parentDir *analyze.Dir) error {
go ui.updateProgress()

go func() {
ui.currentDir = ui.Analyzer.AnalyzeDir(path, ui.CreateIgnoreFunc())
currentDir := ui.Analyzer.AnalyzeDir(path, ui.CreateIgnoreFunc())
runtime.GC()

if parentDir != nil {
ui.currentDir.Parent = parentDir
parentDir.Files = parentDir.Files.RemoveByName(ui.currentDir.Name)
parentDir.Files.Append(ui.currentDir)
currentDir.Parent = parentDir
parentDir.Files = parentDir.Files.RemoveByName(currentDir.Name)
parentDir.Files.Append(currentDir)

links := make(analyze.AlreadyCountedHardlinks, 10)
ui.topDir.UpdateStats(links)
} else {
ui.topDirPath = path
ui.topDir = ui.currentDir
ui.topDir = currentDir
}

ui.app.QueueUpdateDraw(func() {
ui.currentDir = currentDir
ui.showDir()
ui.pages.RemovePage("progress")
})
Expand Down
38 changes: 19 additions & 19 deletions tui/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ func TestDeviceSelected(t *testing.T) {

<-ui.done // wait for analyzer

assert.Equal(t, "test_dir", ui.currentDir.Name)

for _, f := range ui.app.(*testapp.MockedApp).UpdateDraws {
f()
}

assert.Equal(t, "test_dir", ui.currentDir.Name)

assert.Equal(t, 5, ui.table.GetRowCount())
assert.Contains(t, ui.table.GetCell(0, 0).Text, "/..")
assert.Contains(t, ui.table.GetCell(1, 0).Text, "aaa")
Expand Down Expand Up @@ -117,13 +117,13 @@ func TestAnalyzePathWithParentDir(t *testing.T) {

<-ui.done // wait for analyzer

assert.Equal(t, "test_dir", ui.currentDir.Name)
assert.Equal(t, parentDir, ui.currentDir.Parent)

for _, f := range ui.app.(*testapp.MockedApp).UpdateDraws {
f()
}

assert.Equal(t, "test_dir", ui.currentDir.Name)
assert.Equal(t, parentDir, ui.currentDir.Parent)

assert.Equal(t, 5, ui.table.GetRowCount())
assert.Contains(t, ui.table.GetCell(0, 0).Text, "/..")
assert.Contains(t, ui.table.GetCell(1, 0).Text, "aaa")
Expand All @@ -145,11 +145,11 @@ func TestReadAnalysis(t *testing.T) {

<-ui.done // wait for reading

assert.Equal(t, "gdu", ui.currentDir.Name)

for _, f := range ui.app.(*testapp.MockedApp).UpdateDraws {
f()
}

assert.Equal(t, "gdu", ui.currentDir.Name)
}

func TestReadAnalysisWithWrongFile(t *testing.T) {
Expand Down Expand Up @@ -188,12 +188,12 @@ func TestViewDirContents(t *testing.T) {

<-ui.done // wait for analyzer

assert.Equal(t, "test_dir", ui.currentDir.Name)

for _, f := range ui.app.(*testapp.MockedApp).UpdateDraws {
f()
}

assert.Equal(t, "test_dir", ui.currentDir.Name)

res := ui.showFile() // selected item is dir, do nothing
assert.Nil(t, res)
}
Expand Down Expand Up @@ -224,12 +224,12 @@ func TestViewContentsOfNotExistingFile(t *testing.T) {

<-ui.done // wait for analyzer

assert.Equal(t, "test_dir", ui.currentDir.Name)

for _, f := range ui.app.(*testapp.MockedApp).UpdateDraws {
f()
}

assert.Equal(t, "test_dir", ui.currentDir.Name)

ui.table.Select(3, 0)

selectedFile := ui.table.GetCell(3, 0).GetReference().(analyze.Item)
Expand All @@ -253,12 +253,12 @@ func TestViewFile(t *testing.T) {

<-ui.done // wait for analyzer

assert.Equal(t, "test_dir", ui.currentDir.Name)

for _, f := range ui.app.(*testapp.MockedApp).UpdateDraws {
f()
}

assert.Equal(t, "test_dir", ui.currentDir.Name)

ui.table.Select(0, 0)
ui.keyPressed(tcell.NewEventKey(tcell.KeyRight, 'l', 0))
ui.table.Select(2, 0)
Expand All @@ -284,12 +284,12 @@ func TestShowInfo(t *testing.T) {

<-ui.done // wait for analyzer

assert.Equal(t, "test_dir", ui.currentDir.Name)

for _, f := range ui.app.(*testapp.MockedApp).UpdateDraws {
f()
}

assert.Equal(t, "test_dir", ui.currentDir.Name)

ui.keyPressed(tcell.NewEventKey(tcell.KeyRight, 'l', 0))
ui.keyPressed(tcell.NewEventKey(tcell.KeyRune, 'i', 0))
ui.table.Select(2, 0)
Expand All @@ -316,12 +316,12 @@ func TestShowInfoBW(t *testing.T) {

<-ui.done // wait for analyzer

assert.Equal(t, "test_dir", ui.currentDir.Name)

for _, f := range ui.app.(*testapp.MockedApp).UpdateDraws {
f()
}

assert.Equal(t, "test_dir", ui.currentDir.Name)

ui.keyPressed(tcell.NewEventKey(tcell.KeyRight, 'l', 0))
ui.keyPressed(tcell.NewEventKey(tcell.KeyRune, 'i', 0))
ui.table.Select(2, 0)
Expand Down Expand Up @@ -359,12 +359,12 @@ func TestExitViewFile(t *testing.T) {

<-ui.done // wait for analyzer

assert.Equal(t, "test_dir", ui.currentDir.Name)

for _, f := range ui.app.(*testapp.MockedApp).UpdateDraws {
f()
}

assert.Equal(t, "test_dir", ui.currentDir.Name)

ui.table.Select(0, 0)
ui.keyPressed(tcell.NewEventKey(tcell.KeyRight, 'l', 0))
ui.table.Select(2, 0)
Expand Down
57 changes: 30 additions & 27 deletions tui/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ func TestMoveRightOnDevice(t *testing.T) {

<-ui.done // wait for analyzer

for _, f := range ui.app.(*testapp.MockedApp).UpdateDraws {
f()
}

assert.Equal(t, "test_dir", ui.currentDir.Name)
}

Expand Down Expand Up @@ -292,12 +296,12 @@ func TestShowConfirm(t *testing.T) {

<-ui.done // wait for analyzer

assert.Equal(t, "test_dir", ui.currentDir.Name)

for _, f := range ui.app.(*testapp.MockedApp).UpdateDraws {
f()
}

assert.Equal(t, "test_dir", ui.currentDir.Name)

ui.table.Select(1, 0)

ui.keyPressed(tcell.NewEventKey(tcell.KeyRune, 'd', 0))
Expand Down Expand Up @@ -332,12 +336,12 @@ func TestDelete(t *testing.T) {

<-ui.done // wait for analyzer

assert.Equal(t, "test_dir", ui.currentDir.Name)

for _, f := range ui.app.(*testapp.MockedApp).UpdateDraws {
f()
}

assert.Equal(t, "test_dir", ui.currentDir.Name)

assert.Equal(t, 1, ui.table.GetRowCount())

ui.table.Select(0, 0)
Expand Down Expand Up @@ -368,12 +372,11 @@ func TestDeleteParent(t *testing.T) {

<-ui.done // wait for analyzer

assert.Equal(t, "test_dir", ui.currentDir.Name)

for _, f := range ui.app.(*testapp.MockedApp).UpdateDraws {
f()
}

assert.Equal(t, "test_dir", ui.currentDir.Name)
assert.Equal(t, 1, ui.table.GetRowCount())

ui.table.Select(0, 0)
Expand All @@ -399,12 +402,12 @@ func TestEmptyDir(t *testing.T) {

<-ui.done // wait for analyzer

assert.Equal(t, "test_dir", ui.currentDir.Name)

for _, f := range ui.app.(*testapp.MockedApp).UpdateDraws {
f()
}

assert.Equal(t, "test_dir", ui.currentDir.Name)

assert.Equal(t, 1, ui.table.GetRowCount())

ui.table.Select(0, 0)
Expand Down Expand Up @@ -436,12 +439,12 @@ func TestEmptyFile(t *testing.T) {

<-ui.done // wait for analyzer

assert.Equal(t, "test_dir", ui.currentDir.Name)

for _, f := range ui.app.(*testapp.MockedApp).UpdateDraws {
f()
}

assert.Equal(t, "test_dir", ui.currentDir.Name)

assert.Equal(t, 1, ui.table.GetRowCount())

ui.table.Select(0, 0)
Expand Down Expand Up @@ -475,12 +478,12 @@ func TestSortByApparentSize(t *testing.T) {

<-ui.done // wait for analyzer

assert.Equal(t, "test_dir", ui.currentDir.Name)

for _, f := range ui.app.(*testapp.MockedApp).UpdateDraws {
f()
}

assert.Equal(t, "test_dir", ui.currentDir.Name)

ui.keyPressed(tcell.NewEventKey(tcell.KeyRune, 'a', 0))

assert.True(t, ui.ShowApparentSize)
Expand All @@ -499,12 +502,12 @@ func TestShowFileCount(t *testing.T) {

<-ui.done // wait for analyzer

assert.Equal(t, "test_dir", ui.currentDir.Name)

for _, f := range ui.app.(*testapp.MockedApp).UpdateDraws {
f()
}

assert.Equal(t, "test_dir", ui.currentDir.Name)

ui.keyPressed(tcell.NewEventKey(tcell.KeyRune, 'c', 0))

assert.True(t, ui.showItemCount)
Expand All @@ -523,12 +526,12 @@ func TestShowFileCountBW(t *testing.T) {

<-ui.done // wait for analyzer

assert.Equal(t, "test_dir", ui.currentDir.Name)

for _, f := range ui.app.(*testapp.MockedApp).UpdateDraws {
f()
}

assert.Equal(t, "test_dir", ui.currentDir.Name)

ui.keyPressed(tcell.NewEventKey(tcell.KeyRune, 'c', 0))

assert.True(t, ui.showItemCount)
Expand All @@ -547,12 +550,12 @@ func TestShowMtime(t *testing.T) {

<-ui.done // wait for analyzer

assert.Equal(t, "test_dir", ui.currentDir.Name)

for _, f := range ui.app.(*testapp.MockedApp).UpdateDraws {
f()
}

assert.Equal(t, "test_dir", ui.currentDir.Name)

ui.keyPressed(tcell.NewEventKey(tcell.KeyRune, 'm', 0))

assert.True(t, ui.showMtime)
Expand All @@ -571,12 +574,12 @@ func TestShowMtimeBW(t *testing.T) {

<-ui.done // wait for analyzer

assert.Equal(t, "test_dir", ui.currentDir.Name)

for _, f := range ui.app.(*testapp.MockedApp).UpdateDraws {
f()
}

assert.Equal(t, "test_dir", ui.currentDir.Name)

ui.keyPressed(tcell.NewEventKey(tcell.KeyRune, 'm', 0))

assert.True(t, ui.showMtime)
Expand Down Expand Up @@ -610,13 +613,13 @@ func TestRescan(t *testing.T) {

<-ui.done // wait for analyzer

assert.Equal(t, "test_dir", ui.currentDir.Name)
assert.Equal(t, parentDir, ui.currentDir.Parent)

for _, f := range ui.app.(*testapp.MockedApp).UpdateDraws {
f()
}

assert.Equal(t, "test_dir", ui.currentDir.Name)
assert.Equal(t, parentDir, ui.currentDir.Parent)

assert.Equal(t, 5, ui.table.GetRowCount())
assert.Contains(t, ui.table.GetCell(0, 0).Text, "/..")
assert.Contains(t, ui.table.GetCell(1, 0).Text, "aaa")
Expand All @@ -635,12 +638,12 @@ func TestSorting(t *testing.T) {

<-ui.done // wait for analyzer

assert.Equal(t, "test_dir", ui.currentDir.Name)

for _, f := range ui.app.(*testapp.MockedApp).UpdateDraws {
f()
}

assert.Equal(t, "test_dir", ui.currentDir.Name)

ui.keyPressed(tcell.NewEventKey(tcell.KeyRune, 's', 0))
assert.Equal(t, "size", ui.sortBy)
ui.keyPressed(tcell.NewEventKey(tcell.KeyRune, 'C', 0))
Expand All @@ -665,12 +668,12 @@ func TestShowFile(t *testing.T) {

<-ui.done // wait for analyzer

assert.Equal(t, "test_dir", ui.currentDir.Name)

for _, f := range ui.app.(*testapp.MockedApp).UpdateDraws {
f()
}

assert.Equal(t, "test_dir", ui.currentDir.Name)

ui.table.Select(0, 0)
ui.keyPressed(tcell.NewEventKey(tcell.KeyRight, 'l', 0))
ui.table.Select(2, 0)
Expand Down
Loading

0 comments on commit fb01cc1

Please sign in to comment.