summaryrefslogtreecommitdiffstats
path: root/pkg/integration/components/prompt_driver.go
blob: 023c2f4389c89d91011bb2eeaa3cdc63ec1bdfa1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package components

type PromptDriver struct {
	t               *TestDriver
	hasCheckedTitle bool
}

func (self *PromptDriver) getViewDriver() *ViewDriver {
	return self.t.Views().Confirmation()
}

// asserts that the popup has the expected title
func (self *PromptDriver) Title(expected *TextMatcher) *PromptDriver {
	self.getViewDriver().Title(expected)

	self.hasCheckedTitle = true

	return self
}

// asserts on the text initially present in the prompt
func (self *PromptDriver) InitialText(expected *TextMatcher) *PromptDriver {
	self.getViewDriver().Content(expected)

	return self
}

func (self *PromptDriver) Type(value string) *PromptDriver {
	self.t.typeContent(value)

	return self
}

func (self *PromptDriver) Clear() *PromptDriver {
	self.t.press(ClearKey)

	return self
}

func (self *PromptDriver) Confirm() {
	self.checkNecessaryChecksCompleted()

	self.getViewDriver().PressEnter()
}

func (self *PromptDriver) Cancel() {
	self.checkNecessaryChecksCompleted()

	self.getViewDriver().PressEscape()
}

func (self *PromptDriver) checkNecessaryChecksCompleted() {
	if !self.hasCheckedTitle {
		self.t.Fail("You must check the title of a prompt popup by calling Title() before calling Confirm()/Cancel().")
	}
}

func (self *PromptDriver) SuggestionLines(matchers ...*TextMatcher) *PromptDriver {
	self.t.Views().Suggestions().Lines(matchers...)

	return self
}

func (self *PromptDriver) SuggestionTopLines(matchers ...*TextMatcher) *PromptDriver {
	self.t.Views().Suggestions().TopLines(matchers...)

	return self
}

func (self *PromptDriver) ConfirmFirstSuggestion() {
	self.t.press(self.t.keys.Universal.TogglePanel)
	self.t.Views().Suggestions().
		IsFocused().
		SelectedLineIdx(0).
		PressEnter()
}

func (self *PromptDriver) ConfirmSuggestion(matcher *TextMatcher) {
	self.t.press(self.t.keys.Universal.TogglePanel)
	self.t.Views().Suggestions().
		IsFocused().
		NavigateToLine(matcher).
		PressEnter()
}