Skip to content

Commit

Permalink
test: basic test for export
Browse files Browse the repository at this point in the history
  • Loading branch information
dundee committed Feb 13, 2024
1 parent 2f11912 commit ec3d1a5
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
4 changes: 4 additions & 0 deletions tui/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,5 +450,9 @@ func (ui *UI) exportAnalysis() {
ui.showErrFromGo("Error writting to file", err)
return
}

if ui.done != nil {
ui.done <- struct{}{}
}
}()

Check warning on line 457 in tui/actions.go

View check run for this annotation

Codecov / codecov/patch

tui/actions.go#L455-L457

Added lines #L455 - L457 were not covered by tests
}
51 changes: 51 additions & 0 deletions tui/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,3 +492,54 @@ func TestExitViewFile(t *testing.T) {

assert.False(t, ui.pages.HasPage("file"))
}

func TestExportAnalysis(t *testing.T) {
parentDir := &analyze.Dir{
File: &analyze.File{
Name: "parent",
},
Files: make([]fs.Item, 0, 1),
}
currentDir := &analyze.Dir{
File: &analyze.File{
Name: "sub",
Parent: parentDir,
},
}

simScreen := testapp.CreateSimScreen()
defer simScreen.Fini()

app := testapp.CreateMockedApp(true)
ui := CreateUI(app, simScreen, &bytes.Buffer{}, false, true, false, false, false)
ui.done = make(chan struct{})
ui.Analyzer = &testanalyze.MockedAnalyzer{}
ui.currentDir = currentDir
ui.topDir = parentDir

assert.Equal(t, "sub", ui.currentDir.GetName())

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

assert.True(t, ui.pages.HasPage("export"))

ui.keyPressed(tcell.NewEventKey(tcell.KeyEnter, 0, 0))

assert.True(t, ui.pages.HasPage("export"))

// we cannot send Enter to the form from here

ui.exportAnalysis()

assert.True(t, ui.pages.HasPage("exporting"))

<-ui.done

assert.FileExists(t, "export.json")
err := os.Remove("export.json")
assert.NoError(t, err)

for _, f := range ui.app.(*testapp.MockedApp).GetUpdateDraws() {
f()
}
}
4 changes: 2 additions & 2 deletions tui/tui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestHelp(t *testing.T) {

b, _, _ := simScreen.GetContents()

cells := b[406 : 406+9]
cells := b[456 : 456+9]

text := []byte("directory")
for i, r := range cells {
Expand All @@ -114,7 +114,7 @@ func TestHelpBw(t *testing.T) {

b, _, _ := simScreen.GetContents()

cells := b[406 : 406+9]
cells := b[456 : 456+9]

text := []byte("directory")
for i, r := range cells {
Expand Down

0 comments on commit ec3d1a5

Please sign in to comment.