Nicer testing setup with my own interface and methods that abstract away the weird browser API.
This commit is contained in:
parent
77e4c3fa5b
commit
736095a5aa
4 changed files with 96 additions and 95 deletions
|
|
@ -2,8 +2,7 @@ package tests
|
|||
|
||||
import (
|
||||
"testing"
|
||||
"github.com/stretchr/testify/require"
|
||||
browser "github.com/chromedp/chromedp"
|
||||
// "github.com/stretchr/testify/require"
|
||||
"zedshaw.games/webapp/data"
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
)
|
||||
|
|
@ -14,71 +13,58 @@ func deleteTestUser(username string) {
|
|||
}
|
||||
|
||||
func TestLogin(t *testing.T) {
|
||||
require := require.New(t)
|
||||
deleteTestUser("testerzed")
|
||||
z, cancel := Setup(t, 5)
|
||||
defer cancel()
|
||||
|
||||
ctx, cancel := Setup(5); defer cancel()
|
||||
z.GoTo("/register/", `[data-testid="register-index-page"]`)
|
||||
z.TypeIn(`#username`, `testerzed`)
|
||||
z.TypeIn(`#email`, `zed@test.com`)
|
||||
z.TypeIn(`#password`, `iamdumbass`)
|
||||
z.ClickOn(`#register-submit`)
|
||||
z.WaitFor(`[data-testid="login-index-page"]`)
|
||||
|
||||
Run(require, ctx,
|
||||
browser.Navigate(`http://127.0.0.1:5002/register/`),
|
||||
browser.WaitVisible(`body > footer`),
|
||||
browser.WaitVisible(`[data-testid="register-index-page"]`),
|
||||
browser.SendKeys(`#username`, `testerzed`),
|
||||
browser.SendKeys(`#email`, `zed@test.com`),
|
||||
browser.SendKeys(`#password`, `iamdumb`),
|
||||
browser.Click(`#register-submit`, browser.NodeVisible),
|
||||
browser.WaitVisible(`body > footer`),
|
||||
browser.WaitVisible(`[data-testid="login-index-page"]`))
|
||||
|
||||
Run(require, ctx,
|
||||
browser.Navigate(`http://127.0.0.1:5002/login/`),
|
||||
browser.WaitVisible(`body > footer`),
|
||||
browser.WaitVisible(`[data-testid="login-index-page"]`),
|
||||
browser.SendKeys(`#username`, `testerzed`),
|
||||
browser.SendKeys(`#password`, `iamdumb`),
|
||||
browser.Click(`#login-submit`, browser.NodeVisible),
|
||||
browser.WaitVisible(`body > footer`),
|
||||
browser.WaitVisible(`[data-testid="index-page"]`))
|
||||
z.GoTo("/login/", `[data-testid="login-index-page"]`)
|
||||
z.TypeIn(`#username`, `testerzed`)
|
||||
z.TypeIn(`#password`, `iamdumbass`)
|
||||
z.ClickOn(`#login-submit`)
|
||||
z.WaitFor(`[data-testid="index-page"]`)
|
||||
|
||||
/// delete the user here
|
||||
deleteTestUser("testerzed")
|
||||
}
|
||||
|
||||
|
||||
func TestStreamsPage(t *testing.T) {
|
||||
require := require.New(t)
|
||||
z, cancel := Setup(t, 2)
|
||||
defer cancel()
|
||||
|
||||
ctx, cancel := Setup(2);
|
||||
defer cancel();
|
||||
|
||||
GoTo(require, ctx, "/", `#streams`)
|
||||
ClickOn(require, ctx, `#streams`)
|
||||
WaitFor(require, ctx, `[data-testid="stream-index-page"]`)
|
||||
ExpectText(require, ctx, `#page-title`, "Past Streams")
|
||||
z.GoTo("/", `#streams`)
|
||||
z.ClickOn(`#streams`)
|
||||
z.WaitFor(`[data-testid="stream-index-page"]`)
|
||||
z.ExpectText(`#page-title`, "Past Streams")
|
||||
}
|
||||
|
||||
func TestLivePage(t *testing.T) {
|
||||
require := require.New(t)
|
||||
|
||||
ctx, cancel := Setup(2);
|
||||
z, cancel := Setup(t, 2);
|
||||
defer cancel();
|
||||
|
||||
GoTo(require, ctx, "/", `#live`)
|
||||
ClickOn(require, ctx, `#live`)
|
||||
WaitFor(require, ctx, `[data-testid="live-index-page"]`)
|
||||
z.GoTo("/", `#live`)
|
||||
z.ClickOn(`#live`)
|
||||
z.WaitFor(`[data-testid="live-index-page"]`)
|
||||
z.TypeIn("#url", "https://test.com/")
|
||||
z.TypeIn("#description", "A test URL.")
|
||||
z.ClickOn(`#submit`)
|
||||
}
|
||||
|
||||
func TestGamePage(t *testing.T) {
|
||||
require := require.New(t)
|
||||
|
||||
ctx, cancel := Setup(2);
|
||||
z, cancel := Setup(t, 2);
|
||||
defer cancel();
|
||||
|
||||
GoTo(require, ctx, "/", `#game`)
|
||||
ClickOn(require, ctx, `#game`)
|
||||
WaitFor(require, ctx, `[data-testid="game-index-page"]`)
|
||||
ExpectText(require, ctx, `#page-title`, "Zed's Trash Ass Games")
|
||||
ClickOn(require, ctx, `[data-testid="game-link"]`)
|
||||
z.GoTo("/", `#game`)
|
||||
z.ClickOn(`#game`)
|
||||
z.WaitFor(`[data-testid="game-index-page"]`)
|
||||
z.ExpectText(`#page-title`, "Zed's Trash Ass Games")
|
||||
z.ClickOn(`[data-testid="game-link"]`)
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue