tty_test.go 5.7 KB

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