diff options
author | Daniel Milde <daniel@milde.cz> | 2024-02-13 01:29:24 +0100 |
---|---|---|
committer | Daniel Milde <daniel@milde.cz> | 2024-02-13 23:32:27 +0100 |
commit | 346d94ca98c140a14c4d32faf0c877fb48280b74 (patch) | |
tree | af630485b69894eb63498f6b2e1c79b557ef5cad | |
parent | 9d10101b8ea19bc6a26c61d1bc596bdcfc3a5c9d (diff) |
test: basic test for export
-rw-r--r-- | tui/actions.go | 4 | ||||
-rw-r--r-- | tui/actions_test.go | 51 | ||||
-rw-r--r-- | tui/tui_test.go | 4 |
3 files changed, 57 insertions, 2 deletions
diff --git a/tui/actions.go b/tui/actions.go index ab20acb..c12c987 100644 --- a/tui/actions.go +++ b/tui/actions.go @@ -469,5 +469,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 c642127..3882728 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 24b522d..274385e 100644 --- a/tui/tui_test.go +++ b/tui/tui_test.go @@ -94,7 +94,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 { @@ -115,7 +115,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 { |