tty_test.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. package test
  2. import (
  3. "testing"
  4. "github.com/gdamore/tcell"
  5. . "github.com/onsi/ginkgo"
  6. . "github.com/onsi/gomega"
  7. )
  8. func TestIntegration(t *testing.T) {
  9. RegisterFailHandler(Fail)
  10. RunSpecs(t, "Integration tests")
  11. }
  12. var _ = Describe("Showing a basic webpage", func() {
  13. BeforeEach(func() {
  14. GotoURL(testSiteURL + "/smorgasbord/")
  15. })
  16. Describe("Browser UI", func() {
  17. It("should have the page title and current URL", func() {
  18. Expect("Smörgåsbord").To(BeInFrameAt(0, 0))
  19. URL := testSiteURL + "/smorgasbord/"
  20. Expect(URL).To(BeInFrameAt(0, 1))
  21. })
  22. Describe("Interaction", func() {
  23. It("should navigate to a new page by using the URL bar", func() {
  24. SpecialKey(tcell.KeyCtrlL)
  25. Keyboard(testSiteURL + "/smorgasbord/another.html")
  26. SpecialKey(tcell.KeyEnter)
  27. Expect("Another").To(BeInFrameAt(0, 0))
  28. })
  29. It("should navigate to a new page by clicking a link", func() {
  30. Expect("Another▄page").To(BeInFrameAt(12, 18))
  31. mouseClick(12, 18)
  32. Expect("Another").To(BeInFrameAt(0, 0))
  33. })
  34. It("should scroll the page by one line using the mouse", func() {
  35. SpecialMouse(tcell.WheelDown)
  36. SpecialMouse(tcell.WheelDown)
  37. Expect("meal,▄originating▄in▄").To(BeInFrameAt(12, 11))
  38. })
  39. It("should scroll the page by one line", func() {
  40. SpecialKey(tcell.KeyDown)
  41. Expect("meal,▄originating▄in▄").To(BeInFrameAt(12, 11))
  42. })
  43. It("should scroll the page by one page", func() {
  44. SpecialKey(tcell.KeyPgDn)
  45. Expect("continuing▄with▄a▄variety▄of▄fish").To(BeInFrameAt(12, 13))
  46. })
  47. Describe("Text Input", func() {
  48. Describe("Single line", func() {
  49. BeforeEach(func() {
  50. SpecialKey(tcell.KeyDown)
  51. SpecialKey(tcell.KeyDown)
  52. simScreen.InjectMouse(12, 16, tcell.Button1, tcell.ModNone)
  53. })
  54. It("should have basic cursor movement", func() {
  55. Keyboard("|||")
  56. SpecialKey(tcell.KeyLeft)
  57. Keyboard("2")
  58. SpecialKey(tcell.KeyLeft)
  59. SpecialKey(tcell.KeyLeft)
  60. Keyboard("1")
  61. Expect("|1|2|").To(BeInFrameAt(12, 16))
  62. })
  63. It("should scroll single line boxes on overflow", func() {
  64. Keyboard("12345678901234567890")
  65. Expect("5678901234567890 ").To(BeInFrameAt(12, 16))
  66. })
  67. It("should scroll overflowed boxes to the left and right", func() {
  68. Keyboard("12345678901234567890")
  69. for i := 0; i < 19; i++ {
  70. SpecialKey(tcell.KeyLeft)
  71. }
  72. Expect("23456789012345678").To(BeInFrameAt(12, 16))
  73. for i := 0; i < 19; i++ {
  74. SpecialKey(tcell.KeyRight)
  75. }
  76. Expect("5678901234567890 ").To(BeInFrameAt(12, 16))
  77. })
  78. It("should submit text into an input box", func() {
  79. Expect("Unsubmitted").To(BeInFrameAt(12, 19))
  80. Keyboard("Reverse Me!")
  81. SpecialKey(tcell.KeyEnter)
  82. Skip("'Unsubmitted' remains. Is form submission broken?")
  83. Expect("!eM▄esreveR").To(BeInFrameAt(12, 19))
  84. })
  85. })
  86. Describe("Multi line", func() {
  87. BeforeEach(func() {
  88. GotoURL(testSiteURL + "/smorgasbord/textarea.html")
  89. mouseClick(2, 3)
  90. })
  91. It("should enter multiple lines of text", func() {
  92. Keyboard(`So here is a lot of text that will hopefully split across lines`)
  93. Expect("So here is a lot of").To(BeInFrameAt(1, 3))
  94. Expect("text that will").To(BeInFrameAt(1, 4))
  95. Expect("hopefully split across").To(BeInFrameAt(1, 5))
  96. Expect("lines").To(BeInFrameAt(1, 6))
  97. })
  98. It("should scroll multiple lines of text", func() {
  99. Skip("Maybe the ENTER key just isn't working?")
  100. Keyboard(`So here is a lot of text that will hopefully split across lines`)
  101. SpecialKey(tcell.KeyEnter)
  102. Keyboard(`And here is even more filler, it's endless!`)
  103. Expect("filler, it's endless!").To(BeInFrameAt(1, 6))
  104. for i := 1; i <= 6; i++ {
  105. SpecialKey(tcell.KeyUp)
  106. }
  107. Expect("lines").To(BeInFrameAt(1, 6))
  108. })
  109. })
  110. })
  111. Describe("Tabs", func() {
  112. BeforeEach(func() {
  113. SpecialKey(tcell.KeyCtrlT)
  114. })
  115. AfterEach(func() {
  116. ensureOnlyOneTab()
  117. })
  118. It("should create a new tab", func() {
  119. Expect("New Tab").To(BeInFrameAt(21, 0))
  120. // HACK to prevent URL bar being focussed at the start of the next test.
  121. // TODO: Find a more consistent and abstracted way to ensure that the URL
  122. // bar is not focussed at the beginning of new tests.
  123. SpecialKey(tcell.KeyCtrlL)
  124. })
  125. It("should be able to goto a new URL", func() {
  126. Keyboard(testSiteURL + "/smorgasbord/another.html")
  127. SpecialKey(tcell.KeyEnter)
  128. Expect("Another").To(BeInFrameAt(21, 0))
  129. })
  130. It("should cycle to the next tab", func() {
  131. Expect(" ").To(BeInFrameAt(0, 1))
  132. SpecialKey(tcell.KeyCtrlL)
  133. GotoURL(testSiteURL + "/smorgasbord/another.html")
  134. triggerUserKeyFor("tty.keys.next-tab")
  135. URL := testSiteURL + "/smorgasbord/ "
  136. Expect(URL).To(BeInFrameAt(0, 1))
  137. })
  138. })
  139. })
  140. })
  141. Describe("Rendering", func() {
  142. It("should reset page scroll to zero on page load", func() {
  143. SpecialKey(tcell.KeyPgDn)
  144. Expect("continuing▄with▄a▄variety▄of▄fish").To(BeInFrameAt(12, 13))
  145. GotoURL(testSiteURL + "/smorgasbord/another.html")
  146. Expect("Another▄webpage").To(BeInFrameAt(1, 3))
  147. })
  148. It("should render dynamic content", func() {
  149. var greens, pinks int
  150. var colours [10][3]int32
  151. for i := 0; i < 10; i++ {
  152. colours[i] = GetFgColour(39, 3)
  153. waitForNextFrame()
  154. }
  155. for i := 0; i < 10; i++ {
  156. if colours[i] == [3]int32{0, 255, 255} {
  157. greens++
  158. }
  159. if colours[i] == [3]int32{255, 0, 255} {
  160. pinks++
  161. }
  162. }
  163. Expect(greens).To(BeNumerically(">=", 1))
  164. Expect(pinks).To(BeNumerically(">=", 1))
  165. })
  166. It("should switch to monochrome mode", func() {
  167. simScreen.InjectKey(tcell.KeyRune, 'm', tcell.ModAlt)
  168. waitForNextFrame()
  169. Expect([3]int32{0, 0, 0}).To(Equal(GetBgColour(0, 2)))
  170. Expect([3]int32{255, 255, 255}).To(Equal(GetFgColour(12, 11)))
  171. })
  172. Describe("Text positioning", func() {
  173. It("should position the left/right-aligned coloumns", func() {
  174. Expect("Smörgåsbord▄(Swedish:").To(BeInFrameAt(12, 10))
  175. Expect("The▄Swedish▄word").To(BeInFrameAt(42, 10))
  176. })
  177. })
  178. })
  179. })