Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add repository name filtering #32

Merged
merged 2 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions models/orgModel.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,18 @@ func (m OrgModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
_, cmd = m.repoModel.Update(msg)
}
} else {
switch msg.Type {
case tea.KeyDown, tea.KeyUp:
m.repoList, cmd = m.repoList.Update(msg)
m.repoModel.SelectRepo(m.getSelectedRepo(), half(m.width), m.height)
case tea.KeyEnter:
switch msg.String() {
case tea.KeyEnter.String():
m.tabsHaveFocus = true
m.repoModel.SelectRepo(m.getSelectedRepo(), half(m.width), m.height)
case tea.KeyEsc:
case tea.KeyEsc.String():
return MainModel[UserModelName], nil
case "ctrl+c", "q":
if m.repoList.FilterState() == list.Unfiltered {
return m, tea.Quit
}
}
}
switch msg.String() {
case "ctrl+c", "q":
return m, tea.Quit
m.repoList, cmd = m.repoList.Update(msg)
m.repoModel.SelectRepo(m.getSelectedRepo(), half(m.width), m.height)
}
}

Expand Down
21 changes: 10 additions & 11 deletions models/orgModel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,25 @@ import (
tea "github.com/charmbracelet/bubbletea"
)

func TestOrgModel_Update(t *testing.T) {
func TestOrgModel_Update_Quit(t *testing.T) {
defaultOrgModel := NewOrgModel("admcpr", 100, 100)

type args struct {
msg tea.Msg
}
tests := []struct {
name string
m OrgModel
args args
wantModel tea.Model
wantCmd tea.Cmd
name string
m OrgModel
args args
wantCmd tea.Cmd
}{
// TODO: Add more test cases.
{"Quit KeyMsg", OrgModel{}, args{tea.KeyMsg{Type: tea.KeyCtrlC}}, OrgModel{}, tea.Quit},
{"Quit with 'ctrl+c'", defaultOrgModel, args{tea.KeyMsg{Type: tea.KeyCtrlC}}, tea.Quit},
{"Quit with 'q'", defaultOrgModel, args{tea.KeyMsg{Type: tea.KeyCtrlC}}, tea.Quit},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotModel, gotCmd := tt.m.Update(tt.args.msg)
if !reflect.DeepEqual(gotModel, tt.wantModel) {
t.Errorf("OrganisationModel.Update() gotModel = %v, want %v", gotModel, tt.wantModel)
}
_, gotCmd := tt.m.Update(tt.args.msg)
if reflect.ValueOf(gotCmd) != reflect.ValueOf(tt.wantCmd) {
t.Errorf("OrganisationModel.Update() gotCmd = %v, want %v", gotCmd, tt.wantCmd)
}
Expand Down