From ec3d1a5ebbf7aa6ebd9b3e029d5920d031371cb8 Mon Sep 17 00:00:00 2001 From: Daniel Milde Date: Tue, 13 Feb 2024 01:29:24 +0100 Subject: [PATCH] test: basic test for export --- tui/actions.go | 4 ++++ tui/actions_test.go | 51 +++++++++++++++++++++++++++++++++++++++++++++ tui/tui_test.go | 4 ++-- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/tui/actions.go b/tui/actions.go index 1fd2a4d07..ca13429ba 100644 --- a/tui/actions.go +++ b/tui/actions.go @@ -450,5 +450,9 @@ func (ui *UI) exportAnalysis() { ui.showErrFromGo("Error writting to file", err) return } + + if ui.done != nil { + ui.done <- struct{}{} + } }() } diff --git a/tui/actions_test.go b/tui/actions_test.go index c64212797..388272814 100644 --- a/tui/actions_test.go +++ b/tui/actions_test.go @@ -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() + } +} diff --git a/tui/tui_test.go b/tui/tui_test.go index db2c5ce06..43c89089d 100644 --- a/tui/tui_test.go +++ b/tui/tui_test.go @@ -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 { @@ -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 {