Skip to content

Commit

Permalink
First set of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dkyanakiev authored and Dimitar Yanakiev committed Nov 28, 2023
1 parent f217fb5 commit 2882424
Show file tree
Hide file tree
Showing 17 changed files with 2,489 additions and 25 deletions.
50 changes: 50 additions & 0 deletions component/commands_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package component_test

import (
"errors"
"testing"

"github.com/dkyanakiev/vaulty/component"
"github.com/dkyanakiev/vaulty/component/componentfakes"
"github.com/rivo/tview"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestCommands_Update(t *testing.T) {
commands := component.NewCommands()

newCommands := []string{"new command 1", "new command 2"}
commands.Update(newCommands)

assert.Equal(t, newCommands, commands.Props.ViewCommands)
}

func TestCommands_OK(t *testing.T) {
r := require.New(t)
textView := &componentfakes.FakeTextView{}
cmds := component.NewCommands()
cmds.TextView = textView

cmds.Props.MainCommands = []string{"command1", "command2"}
cmds.Props.ViewCommands = []string{"subCmd1", "subCmd2"}

cmds.Bind(tview.NewFlex())
err := cmds.Render()
r.NoError(err)

text := textView.SetTextArgsForCall(0)
r.Equal(text, "command1\ncommand2\nsubCmd1\nsubCmd2")
}

func TestCommands_Fail(t *testing.T) {
r := require.New(t)
textView := &componentfakes.FakeTextView{}
cmds := component.NewCommands()
cmds.TextView = textView
err := cmds.Render()
r.Error(err)

r.True(errors.Is(err, component.ErrComponentNotBound))
r.EqualError(err, "component not bound")
}
77 changes: 77 additions & 0 deletions component/componentfakes/fake_done_modal_func.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

227 changes: 227 additions & 0 deletions component/componentfakes/fake_drop_down.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2882424

Please sign in to comment.