X Tutup
Skip to content

Commit 90ec108

Browse files
committed
Port pr create tests to the new ask stubber
1 parent ff07257 commit 90ec108

File tree

1 file changed

+26
-36
lines changed

1 file changed

+26
-36
lines changed

pkg/cmd/pr/create/create_test.go

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -285,24 +285,10 @@ func TestPRCreate_recover(t *testing.T) {
285285

286286
as, teardown := prompt.InitAskStubber()
287287
defer teardown()
288-
as.Stub([]*prompt.QuestionStub{
289-
{
290-
Name: "Title",
291-
Default: true,
292-
},
293-
})
294-
as.Stub([]*prompt.QuestionStub{
295-
{
296-
Name: "Body",
297-
Default: true,
298-
},
299-
})
300-
as.Stub([]*prompt.QuestionStub{
301-
{
302-
Name: "confirmation",
303-
Value: 0,
304-
},
305-
})
288+
289+
as.StubPrompt("Title").AnswerDefault()
290+
as.StubPrompt("Body").AnswerDefault()
291+
as.StubPrompt("What's next?").AnswerDefault()
306292

307293
tmpfile, err := ioutil.TempFile(t.TempDir(), "testrecover*")
308294
assert.NoError(t, err)
@@ -395,7 +381,8 @@ func TestPRCreate(t *testing.T) {
395381

396382
ask, cleanupAsk := prompt.InitAskStubber()
397383
defer cleanupAsk()
398-
ask.StubOne(0)
384+
385+
ask.StubPrompt("Where should we push the 'feature' branch?").AnswerDefault()
399386

400387
output, err := runCommand(http, nil, "feature", true, `-t "my title" -b "my body"`)
401388
require.NoError(t, err)
@@ -440,7 +427,8 @@ func TestPRCreate_NoMaintainerModify(t *testing.T) {
440427

441428
ask, cleanupAsk := prompt.InitAskStubber()
442429
defer cleanupAsk()
443-
ask.StubOne(0)
430+
431+
ask.StubPrompt("Where should we push the 'feature' branch?").AnswerDefault()
444432

445433
output, err := runCommand(http, nil, "feature", true, `-t "my title" -b "my body" --no-maintainer-edit`)
446434
require.NoError(t, err)
@@ -490,7 +478,10 @@ func TestPRCreate_createFork(t *testing.T) {
490478

491479
ask, cleanupAsk := prompt.InitAskStubber()
492480
defer cleanupAsk()
493-
ask.StubOne(1)
481+
482+
ask.StubPrompt("Where should we push the 'feature' branch?").
483+
AssertOptions([]string{"OWNER/REPO", "Create a fork of OWNER/REPO", "Skip pushing the branch", "Cancel"}).
484+
AnswerWith("Create a fork of OWNER/REPO")
494485

495486
output, err := runCommand(http, nil, "feature", true, `-t title -b body`)
496487
require.NoError(t, err)
@@ -620,19 +611,14 @@ func TestPRCreate_nonLegacyTemplate(t *testing.T) {
620611

621612
as, teardown := prompt.InitAskStubber()
622613
defer teardown()
623-
as.StubOne(0) // template
624-
as.Stub([]*prompt.QuestionStub{
625-
{
626-
Name: "Body",
627-
Default: true,
628-
},
629-
}) // body
630-
as.Stub([]*prompt.QuestionStub{
631-
{
632-
Name: "confirmation",
633-
Value: 0,
634-
},
635-
}) // confirm
614+
615+
as.StubPrompt("Choose a template").
616+
AssertOptions([]string{"Bug fix", "Open a blank pull request"}).
617+
AnswerWith("Bug fix")
618+
as.StubPrompt("Body").AnswerDefault()
619+
as.StubPrompt("What's next?").
620+
AssertOptions([]string{"Submit", "Continue in browser", "Add metadata", "Cancel"}).
621+
AnswerDefault()
636622

637623
output, err := runCommandWithRootDirOverridden(http, nil, "feature", true, `-t "my title" -H feature`, "./fixtures/repoWithNonLegacyPRTemplates")
638624
require.NoError(t, err)
@@ -773,7 +759,10 @@ func TestPRCreate_web(t *testing.T) {
773759

774760
ask, cleanupAsk := prompt.InitAskStubber()
775761
defer cleanupAsk()
776-
ask.StubOne(0)
762+
763+
ask.StubPrompt("Where should we push the 'feature' branch?").
764+
AssertOptions([]string{"OWNER/REPO", "Skip pushing the branch", "Cancel"}).
765+
AnswerDefault()
777766

778767
output, err := runCommand(http, nil, "feature", true, `--web`)
779768
require.NoError(t, err)
@@ -844,7 +833,8 @@ func TestPRCreate_webProject(t *testing.T) {
844833

845834
ask, cleanupAsk := prompt.InitAskStubber()
846835
defer cleanupAsk()
847-
ask.StubOne(0)
836+
837+
ask.StubPrompt("Where should we push the 'feature' branch?").AnswerDefault()
848838

849839
output, err := runCommand(http, nil, "feature", true, `--web -p Triage`)
850840
require.NoError(t, err)

0 commit comments

Comments
 (0)
X Tutup