Now easier to write tests for the app, and most pages are at least touched.
This commit is contained in:
parent
d095bc9ff4
commit
ecc264db8c
14 changed files with 124 additions and 89 deletions
|
@ -2,7 +2,7 @@ package tests
|
|||
|
||||
import (
|
||||
"testing"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
browser "github.com/chromedp/chromedp"
|
||||
"zedshaw.games/webapp/data"
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
|
@ -14,12 +14,12 @@ func deleteTestUser(username string) {
|
|||
}
|
||||
|
||||
func TestLogin(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
deleteTestUser("testerzed")
|
||||
|
||||
ctx, cancel := Setup(5); defer cancel()
|
||||
|
||||
Run(assert, ctx,
|
||||
Run(require, ctx,
|
||||
browser.Navigate(`http://127.0.0.1:5002/register/`),
|
||||
browser.WaitVisible(`body > footer`),
|
||||
browser.WaitVisible(`[data-testid="register-index-page"]`),
|
||||
|
@ -30,7 +30,7 @@ func TestLogin(t *testing.T) {
|
|||
browser.WaitVisible(`body > footer`),
|
||||
browser.WaitVisible(`[data-testid="login-index-page"]`))
|
||||
|
||||
Run(assert, ctx,
|
||||
Run(require, ctx,
|
||||
browser.Navigate(`http://127.0.0.1:5002/login/`),
|
||||
browser.WaitVisible(`body > footer`),
|
||||
browser.WaitVisible(`[data-testid="login-index-page"]`),
|
||||
|
@ -44,29 +44,41 @@ func TestLogin(t *testing.T) {
|
|||
deleteTestUser("testerzed")
|
||||
}
|
||||
|
||||
func TestStreamPage(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
func TestStreamsPage(t *testing.T) {
|
||||
require := require.New(t)
|
||||
|
||||
ctx, cancel := Setup(2);
|
||||
defer cancel();
|
||||
|
||||
var title string
|
||||
GoTo(require, ctx, "/", `#streams`)
|
||||
ClickOn(require, ctx, `#streams`)
|
||||
WaitFor(require, ctx, `[data-testid="stream-index-page"]`)
|
||||
ExpectText(require, ctx, `#page-title`, "Past Streams")
|
||||
}
|
||||
|
||||
err := browser.Run(ctx,
|
||||
browser.Navigate(`http://127.0.0.1:5002`),
|
||||
browser.WaitVisible(`body > footer`),
|
||||
browser.WaitVisible(`#streams`),)
|
||||
assert.NoError(err)
|
||||
func TestLivePage(t *testing.T) {
|
||||
require := require.New(t)
|
||||
|
||||
ClickOn(assert, ctx, `#streams`)
|
||||
ctx, cancel := Setup(2);
|
||||
defer cancel();
|
||||
|
||||
err = browser.Run(ctx, browser.WaitVisible(`#streams-title`))
|
||||
assert.NoError(err)
|
||||
GoTo(require, ctx, "/", `#live`)
|
||||
ClickOn(require, ctx, `#live`)
|
||||
WaitFor(require, ctx, `[data-testid="live-index-page"]`)
|
||||
}
|
||||
|
||||
err = browser.Run(ctx, browser.Text(`#streams-title`, &title))
|
||||
assert.NoError(err)
|
||||
func TestGamePage(t *testing.T) {
|
||||
require := require.New(t)
|
||||
|
||||
assert.Equal(title, "Past Streams")
|
||||
ctx, cancel := Setup(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"]`)
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"log"
|
||||
"time"
|
||||
"runtime"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
browser "github.com/chromedp/chromedp"
|
||||
)
|
||||
|
||||
|
@ -22,16 +22,39 @@ func Setup(timeout time.Duration) (context.Context, context.CancelFunc) {
|
|||
return ctx, cancel
|
||||
}
|
||||
|
||||
func ClickOn(assert *assert.Assertions, ctx context.Context, id string) {
|
||||
err := browser.Run(ctx, browser.WaitVisible(`#streams`),)
|
||||
assert.NoError(err)
|
||||
func ClickOn(require *require.Assertions, ctx context.Context, id string) {
|
||||
err := browser.Run(ctx, browser.WaitVisible(id),)
|
||||
require.NoError(err)
|
||||
|
||||
resp, err := browser.RunResponse(ctx, browser.Click(id, browser.ByID))
|
||||
assert.Equal(resp.Status, int64(200))
|
||||
assert.NoError(err)
|
||||
resp, err := browser.RunResponse(ctx,
|
||||
browser.WaitVisible(id),
|
||||
browser.Click(id))
|
||||
|
||||
require.NoError(err)
|
||||
require.Equal(resp.Status, int64(200))
|
||||
}
|
||||
|
||||
func Run(assert *assert.Assertions, ctx context.Context, actions ...browser.Action) {
|
||||
func GoTo(require *require.Assertions, ctx context.Context, path string, expect string) {
|
||||
err := browser.Run(ctx,
|
||||
browser.Navigate(`http://127.0.0.1:5002`),
|
||||
browser.WaitVisible(`body > footer`),
|
||||
browser.WaitVisible(expect))
|
||||
require.NoError(err)
|
||||
}
|
||||
|
||||
func WaitFor(require *require.Assertions, ctx context.Context, expect string) {
|
||||
err := browser.Run(ctx, browser.WaitVisible(expect))
|
||||
require.NoError(err)
|
||||
}
|
||||
|
||||
func ExpectText(require *require.Assertions, ctx context.Context, target string, expect string) {
|
||||
var extracted string
|
||||
err := browser.Run(ctx, browser.Text(target, &extracted))
|
||||
require.NoError(err)
|
||||
require.Equal(expect, extracted)
|
||||
}
|
||||
|
||||
func Run(require *require.Assertions, ctx context.Context, actions ...browser.Action) {
|
||||
err := browser.Run(ctx, actions...)
|
||||
assert.NoError(err)
|
||||
require.NoError(err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue