|
|
@@ -36,21 +36,24 @@ func Test_Model_Update_quit_on_keymsg(t *testing.T) {
|
|
|
|
|
|
func Test_Model_Update_scroll_on_k(t *testing.T) {
|
|
|
ic, _ := IssueCollection.NewFromPath(IssueCollection{}, "tests/bugs/")
|
|
|
- testModel := Model{collection: ic}
|
|
|
+ testModel := Model{widget: ic}
|
|
|
testKey := tea.Key{Type: tea.KeyRunes, Runes: []rune{'k'}}
|
|
|
testMsg := tea.KeyMsg(testKey)
|
|
|
|
|
|
model, cmd := testModel.Update(testMsg)
|
|
|
- assert.Equal(t, testModel.selection+1, model.(Model).selection)
|
|
|
+ widget, _ := model.(Model).widget.(IssueCollection)
|
|
|
+ assert.Equal(t, ic.selection+1, widget.selection)
|
|
|
|
|
|
if cmd == nil {
|
|
|
assert.Fail(t, "should return tea.Cmd")
|
|
|
}
|
|
|
|
|
|
// test select wraparound
|
|
|
- testModel.selection = len(testModel.collection) - 1
|
|
|
+ ic.selection = len(ic.Collection) - 1
|
|
|
+ testModel = Model{widget: ic}
|
|
|
model, cmd = testModel.Update(testMsg)
|
|
|
- assert.Equal(t, 0, model.(Model).selection)
|
|
|
+ widget, _ = model.(Model).widget.(IssueCollection)
|
|
|
+ assert.Equal(t, 0, widget.selection)
|
|
|
|
|
|
if cmd == nil {
|
|
|
assert.Fail(t, "should return tea.Cmd")
|
|
|
@@ -59,31 +62,55 @@ func Test_Model_Update_scroll_on_k(t *testing.T) {
|
|
|
|
|
|
func Test_Model_Update_scroll_on_j(t *testing.T) {
|
|
|
ic, _ := IssueCollection.NewFromPath(IssueCollection{}, "tests/bugs/")
|
|
|
- testModel := Model{collection: ic}
|
|
|
+ testModel := Model{widget: ic}
|
|
|
testKey := tea.Key{Type: tea.KeyRunes, Runes: []rune{'j'}}
|
|
|
testMsg := tea.KeyMsg(testKey)
|
|
|
|
|
|
model, cmd := testModel.Update(testMsg)
|
|
|
- assert.Equal(t, len(testModel.collection)-1, model.(Model).selection)
|
|
|
+ widget, _ := model.(Model).widget.(IssueCollection)
|
|
|
+ assert.Equal(t, len(ic.Collection)-1, widget.selection)
|
|
|
|
|
|
if cmd == nil {
|
|
|
assert.Fail(t, "should return tea.Cmd")
|
|
|
}
|
|
|
|
|
|
- model, cmd = model.(Model).Update(testMsg)
|
|
|
- assert.Equal(t, len(testModel.collection)-2, model.(Model).selection)
|
|
|
-
|
|
|
- if cmd == nil {
|
|
|
- assert.Fail(t, "should return tea.Cmd")
|
|
|
- }
|
|
|
+ // test select wraparound
|
|
|
+ ic.selection = len(ic.Collection) - 1
|
|
|
+ testModel = Model{widget: ic}
|
|
|
+ model, _ = testModel.Update(testMsg)
|
|
|
+ widget, _ = model.(Model).widget.(IssueCollection)
|
|
|
+ assert.Equal(t, len(ic.Collection)-2, widget.selection)
|
|
|
+
|
|
|
+ // if cmd == nil {
|
|
|
+ // assert.Fail(t, "should return tea.Cmd")
|
|
|
+ // }
|
|
|
+ // ic, _ := IssueCollection.NewFromPath(IssueCollection{}, "tests/bugs/")
|
|
|
+ // testModel := Model{widget: ic}
|
|
|
+ // testKey := tea.Key{Type: tea.KeyRunes, Runes: []rune{'j'}}
|
|
|
+ // testMsg := tea.KeyMsg(testKey)
|
|
|
+
|
|
|
+ // model, cmd := testModel.Update(testMsg)
|
|
|
+ // widget, _ := testModel.widget.(IssueCollection)
|
|
|
+ // assert.Equal(t, len(ic.Collection)-1, widget.selection)
|
|
|
+
|
|
|
+ // if cmd == nil {
|
|
|
+ // assert.Fail(t, "should return tea.Cmd")
|
|
|
+ // }
|
|
|
+
|
|
|
+ // model, cmd = model.Update(testMsg)
|
|
|
+ // assert.Equal(t, len(ic.Collection)-2, widget.selection)
|
|
|
+
|
|
|
+ // if cmd == nil {
|
|
|
+ // assert.Fail(t, "should return tea.Cmd")
|
|
|
+ // }
|
|
|
}
|
|
|
|
|
|
func Test_Model_Update_load_on_enter(t *testing.T) {
|
|
|
ic, _ := IssueCollection.NewFromPath(IssueCollection{}, "tests/bugs")
|
|
|
- testModel := Model{collection: ic}
|
|
|
+ testModel := Model{widget: ic}
|
|
|
testKey := tea.Key{Type: tea.KeyEnter, Runes: []rune{}}
|
|
|
testMsg := tea.KeyMsg(testKey)
|
|
|
- testPath := testModel.collection[testModel.selection].Path
|
|
|
+ testPath := ic.Collection[ic.selection].Path
|
|
|
|
|
|
model, cmd := testModel.Update(testMsg)
|
|
|
assert.Equal(t, testPath, model.(Model).Path)
|
|
|
@@ -98,12 +125,13 @@ func Test_Model_Update_renderIssue(t *testing.T) {
|
|
|
testModel := Model{}
|
|
|
|
|
|
model, cmd := testModel.Update(tea.Msg(testIssue))
|
|
|
+ widget, _ := model.(Model).widget.(Issue)
|
|
|
if cmd == nil {
|
|
|
assert.Fail(t, "should return cmd")
|
|
|
}
|
|
|
|
|
|
- assert.Equal(t, model.(Model).issue.Title, testIssue.Title)
|
|
|
- assert.Equal(t, Model{issue: testIssue}.renderIssue(), cmd())
|
|
|
+ assert.Equal(t, testIssue.Title, widget.Title)
|
|
|
+ assert.Equal(t, testIssue.view(), cmd())
|
|
|
}
|
|
|
|
|
|
func Test_Model_Update_renderIssueCollection(t *testing.T) {
|
|
|
@@ -111,19 +139,21 @@ func Test_Model_Update_renderIssueCollection(t *testing.T) {
|
|
|
testModel := Model{}
|
|
|
|
|
|
model, cmd := testModel.Update(tea.Msg(testCollection))
|
|
|
+ widget, _ := model.(Model).widget.(IssueCollection)
|
|
|
if cmd == nil {
|
|
|
assert.Fail(t, "should return cmd")
|
|
|
}
|
|
|
|
|
|
- assert.Equal(t, len(testCollection), len(model.(Model).collection))
|
|
|
- assert.Equal(t, Model{collection: testCollection}.renderIssueCollection(), cmd())
|
|
|
+ assert.Equal(t, len(testCollection.Collection), len(widget.Collection))
|
|
|
+ assert.Equal(t, testCollection.view(), cmd())
|
|
|
}
|
|
|
|
|
|
func Test_Model_Update_updates_content(t *testing.T) {
|
|
|
testIssue, _ := Issue{}.NewFromPath("tests/bugs/test-1")
|
|
|
- testModel := Model{issue: testIssue}
|
|
|
+ testModel := Model{widget: testIssue}
|
|
|
+ testWidget := testModel.widget.(Issue)
|
|
|
|
|
|
- testModel.content = testModel.renderIssue().(string)
|
|
|
+ testModel.content = testWidget.view().(string)
|
|
|
|
|
|
model, cmd := testModel.Update(tea.Msg(testModel.content))
|
|
|
if cmd != nil {
|
|
|
@@ -135,7 +165,7 @@ func Test_Model_Update_updates_content(t *testing.T) {
|
|
|
|
|
|
func Test_Model_Update_do_nothing(t *testing.T) {
|
|
|
testIssue, _ := Issue.NewFromPath(Issue{}, "tests/bugs/test-1")
|
|
|
- testModel := Model{issue: testIssue}
|
|
|
+ testModel := Model{widget: testIssue}
|
|
|
var testMsg int
|
|
|
|
|
|
model, cmd := testModel.Update(testMsg)
|
|
|
@@ -146,7 +176,7 @@ func Test_Model_Update_do_nothing(t *testing.T) {
|
|
|
|
|
|
func Test_Model_renderIssue(t *testing.T) {
|
|
|
testIssue, _ := Issue.NewFromPath(Issue{}, "tests/bugs/test-1")
|
|
|
- testRender := Model{issue: testIssue}.renderIssue()
|
|
|
+ testRender := testIssue.view()
|
|
|
|
|
|
renderContent, _ := testRender.(string)
|
|
|
assert.True(t, strings.Contains(renderContent, "test description"))
|
|
|
@@ -160,7 +190,7 @@ func Test_Model_View(t *testing.T) {
|
|
|
assert.Fail(t, "should not return cmd")
|
|
|
}
|
|
|
|
|
|
- assert.Equal(t, Model{issue: testIssue}.renderIssue().(string), model.(Model).View())
|
|
|
+ assert.Equal(t, testIssue.view().(string), model.(Model).View())
|
|
|
|
|
|
render2 := Model{}.View()
|
|
|
assert.Equal(t, "loading...", render2)
|