From 504d93a9918b9d1a5e3a1522c1bd7fdadec62739 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 22 Mar 2023 17:52:30 +0100 Subject: [PATCH 1/2] Pass all messages to repoList --- models/orgModel.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/models/orgModel.go b/models/orgModel.go index 4acf507..013060b 100644 --- a/models/orgModel.go +++ b/models/orgModel.go @@ -93,13 +93,12 @@ func (m OrgModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { _, cmd = m.repoModel.Update(msg) } } else { + m.repoList, cmd = m.repoList.Update(msg) + m.repoModel.SelectRepo(m.getSelectedRepo(), half(m.width), m.height) + 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: m.tabsHaveFocus = true - m.repoModel.SelectRepo(m.getSelectedRepo(), half(m.width), m.height) case tea.KeyEsc: return MainModel[UserModelName], nil } From 86078a0bdd55a4fe0477f546cfbff88b9c96253d Mon Sep 17 00:00:00 2001 From: Adam Cooper Date: Tue, 28 Mar 2023 20:25:59 +0200 Subject: [PATCH 2/2] Fix test --- models/orgModel.go | 19 +++++++++---------- models/orgModel_test.go | 21 ++++++++++----------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/models/orgModel.go b/models/orgModel.go index 013060b..1d502a0 100644 --- a/models/orgModel.go +++ b/models/orgModel.go @@ -93,19 +93,18 @@ func (m OrgModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { _, cmd = m.repoModel.Update(msg) } } else { - m.repoList, cmd = m.repoList.Update(msg) - m.repoModel.SelectRepo(m.getSelectedRepo(), half(m.width), m.height) - - switch msg.Type { - case tea.KeyEnter: + switch msg.String() { + case tea.KeyEnter.String(): m.tabsHaveFocus = true - 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) } } diff --git a/models/orgModel_test.go b/models/orgModel_test.go index 7459ec0..8bd7dc3 100644 --- a/models/orgModel_test.go +++ b/models/orgModel_test.go @@ -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) }