2018-04-06 15:16:15 +00:00
|
|
|
package test
|
2018-04-01 08:31:25 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/gdamore/tcell"
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestIntegration(t *testing.T) {
|
|
|
|
RegisterFailHandler(Fail)
|
|
|
|
RunSpecs(t, "Integration tests")
|
|
|
|
}
|
|
|
|
|
2018-04-06 15:16:15 +00:00
|
|
|
var _ = Describe("Showing a basic webpage", func() {
|
2018-04-01 08:31:25 +00:00
|
|
|
BeforeEach(func() {
|
2018-04-06 15:16:15 +00:00
|
|
|
GotoURL(testSiteURL + "/smorgasbord/")
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("Browser UI", func() {
|
|
|
|
It("should have the page title, buttons and the current URL", func() {
|
|
|
|
Expect("Smörgåsbord").To(BeInFrameAt(0, 0))
|
|
|
|
Expect(" ← |").To(BeInFrameAt(0, 1))
|
|
|
|
Expect(" x |").To(BeInFrameAt(4, 1))
|
|
|
|
URL := testSiteURL + "/smorgasbord/"
|
|
|
|
Expect(URL).To(BeInFrameAt(9, 1))
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("Interaction", func() {
|
|
|
|
It("should navigate to a new page by using the URL bar", func() {
|
|
|
|
SpecialKey(tcell.KeyCtrlL)
|
2018-05-20 13:17:33 +00:00
|
|
|
BackspaceRemoveURL()
|
2018-04-06 15:16:15 +00:00
|
|
|
Keyboard(testSiteURL + "/smorgasbord/another.html")
|
|
|
|
SpecialKey(tcell.KeyEnter)
|
|
|
|
Expect("Another").To(BeInFrameAt(0, 0))
|
|
|
|
})
|
2018-04-01 08:31:25 +00:00
|
|
|
|
2018-04-06 15:16:15 +00:00
|
|
|
It("should navigate to a new page by clicking a link", func() {
|
2018-04-18 13:11:04 +00:00
|
|
|
Expect("Another▄page").To(BeInFrameAt(12, 19))
|
|
|
|
simScreen.InjectMouse(12, 19, tcell.Button1, tcell.ModNone)
|
2018-04-06 15:16:15 +00:00
|
|
|
Expect("Another").To(BeInFrameAt(0, 0))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should scroll the page by one line", func() {
|
|
|
|
SpecialKey(tcell.KeyDown)
|
2018-04-18 13:11:04 +00:00
|
|
|
Expect("meal,▄originating▄in▄").To(BeInFrameAt(12, 11))
|
2018-04-06 15:16:15 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should scroll the page by one page", func() {
|
|
|
|
SpecialKey(tcell.KeyPgDn)
|
2018-04-18 13:11:04 +00:00
|
|
|
Expect("continuing▄with▄a▄variety▄of▄fish").To(BeInFrameAt(12, 12))
|
2018-04-06 15:16:15 +00:00
|
|
|
})
|
2018-05-20 13:17:33 +00:00
|
|
|
|
|
|
|
Describe("Text Input", func() {
|
|
|
|
BeforeEach(func() {
|
|
|
|
SpecialKey(tcell.KeyDown)
|
|
|
|
SpecialKey(tcell.KeyDown)
|
|
|
|
simScreen.InjectMouse(12, 17, tcell.Button1, tcell.ModNone)
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should have basic cursor movement", func() {
|
|
|
|
Keyboard("|||")
|
|
|
|
SpecialKey(tcell.KeyLeft)
|
|
|
|
Keyboard("2")
|
|
|
|
SpecialKey(tcell.KeyLeft)
|
|
|
|
SpecialKey(tcell.KeyLeft)
|
|
|
|
Keyboard("1")
|
|
|
|
Expect("|1|2|").To(BeInFrameAt(12, 17))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should submit text into an input box", func() {
|
|
|
|
Expect("Unsubmitted").To(BeInFrameAt(12, 21))
|
|
|
|
Keyboard("Reverse Me!")
|
|
|
|
SpecialKey(tcell.KeyEnter)
|
|
|
|
Expect("!eM▄esreveR").To(BeInFrameAt(12, 21))
|
|
|
|
})
|
|
|
|
})
|
2018-04-06 15:16:15 +00:00
|
|
|
})
|
2018-04-01 08:31:25 +00:00
|
|
|
})
|
|
|
|
|
2018-04-06 15:16:15 +00:00
|
|
|
Describe("Rendering", func() {
|
2018-04-18 13:11:04 +00:00
|
|
|
It("should reset page scroll to zero on page load", func() {
|
|
|
|
SpecialKey(tcell.KeyPgDn)
|
|
|
|
Expect("continuing▄with▄a▄variety▄of▄fish").To(BeInFrameAt(12, 12))
|
|
|
|
GotoURL(testSiteURL + "/smorgasbord/another.html")
|
|
|
|
Expect("Another▄webpage").To(BeInFrameAt(1, 3))
|
|
|
|
})
|
|
|
|
|
2018-04-06 15:16:15 +00:00
|
|
|
It("should render dynamic content", func() {
|
2018-04-28 11:02:40 +00:00
|
|
|
var greens, pinks int
|
|
|
|
var colours [10][3]int32
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
colours[i] = GetFgColour(39, 3)
|
|
|
|
waitForNextFrame()
|
|
|
|
}
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
if colours[i] == [3]int32{0, 255, 255} { greens++ }
|
|
|
|
if colours[i] == [3]int32{255, 0, 255} { pinks++ }
|
|
|
|
}
|
|
|
|
Expect(greens).To(BeNumerically(">=", 1))
|
|
|
|
Expect(pinks).To(BeNumerically(">=", 1))
|
2018-04-06 15:16:15 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should switch to monochrome mode", func() {
|
2018-04-28 11:02:40 +00:00
|
|
|
simScreen.InjectKey(tcell.KeyRune, 'm', tcell.ModAlt)
|
2018-04-06 15:16:15 +00:00
|
|
|
waitForNextFrame()
|
|
|
|
Expect([3]int32{0, 0, 0}).To(Equal(GetBgColour(0, 2)))
|
|
|
|
Expect([3]int32{255, 255, 255}).To(Equal(GetFgColour(12, 11)))
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("Text positioning", func() {
|
|
|
|
It("should position the left/right-aligned coloumns", func() {
|
2018-04-18 13:11:04 +00:00
|
|
|
Expect("Smörgåsbord▄(Swedish:").To(BeInFrameAt(12, 10))
|
|
|
|
Expect("The▄Swedish▄word").To(BeInFrameAt(42, 10))
|
2018-04-06 15:16:15 +00:00
|
|
|
})
|
2018-04-01 08:31:25 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|