Now easier to write tests for the app, and most pages are at least touched.

main
Zed A. Shaw 5 days ago
parent d095bc9ff4
commit ecc264db8c
  1. 4
      pages/game/index.html
  2. 2
      pages/index.html
  3. 12
      pages/layouts/main.html
  4. 2
      pages/stream/index.html
  5. 12
      public/base.html
  6. 12
      public/error/index.html
  7. 16
      public/game/index.html
  8. 14
      public/index.html
  9. 12
      public/live/index.html
  10. 12
      public/login/index.html
  11. 12
      public/register/index.html
  12. 14
      public/stream/index.html
  13. 48
      tests/base_test.go
  14. 41
      tests/tools.go

@ -3,7 +3,7 @@
</script>
<blockstart>
<block style="--w: 100%; --value: 7">
<h1>Zed's Trash Ass Games</h1>
<h1 id="page-title">Zed's Trash Ass Games</h1>
<p>More fun than a barrel full of monkeys with syphilus.
</p>
@ -12,7 +12,7 @@
<hr/>
<grid x-data="Games" style="--cols: 2">
<template x-for="item in theData">
<shape style="--h: 200px"><a x-text="item.title" x-bind:href="item.url"></a></shape>
<shape style="--h: 200px"><a data-testid="game-link" x-text="item.title" x-bind:href="item.url"></a></shape>
</template>
</grid>

@ -3,7 +3,7 @@
<shape style="--w: 100%; --h: 300px">
<button><a id="streams" href="/stream/">View Past Streams</a></button>
<button><a href="/live/">Watch Today's Livestream</a></button>
<button><a id="live" href="/live/">Watch Today's Livestream</a></button>
</shape>
<block data-testid="clickblock">

@ -13,12 +13,12 @@
<header>
<blockstart style="background-color: var(--value0)">
<block style="--value: 0; --text: 9" class="horizontal">
<a href="/">🏡</a>
<a href="/live/">Live</a>
<a href="/stream/">Streams</a>
<a href="/game/">Games</a>
<a href="/register/">Register</a>
<a href="/login/">Login</a>
<a id="home" href="/">🏡</a>
<a id="live" href="/live/">Live</a>
<a id="stream" href="/stream/">Streams</a>
<a id="game" href="/game/">Games</a>
<a id="register" href="/register/">Register</a>
<a id="login" href="/login/">Login</a>
</block>
</blockstart>
</header>

@ -5,7 +5,7 @@
<blockstart>
<block style="--value: 7">
<h1 id="streams-title">Past Streams</h1>
<h1 id="page-title">Past Streams</h1>
<p>This is where you can checkout information we dropped in a past stream. Did I post a link and you need to remember it? Did someone in chat mention something? Here's where you find it.</p>
</block>

@ -13,12 +13,12 @@
<header>
<blockstart style="background-color: var(--value0)">
<block style="--value: 0; --text: 9" class="horizontal">
<a href="/">🏡</a>
<a href="/live/">Live</a>
<a href="/stream/">Streams</a>
<a href="/game/">Games</a>
<a href="/register/">Register</a>
<a href="/login/">Login</a>
<a id="home" href="/">🏡</a>
<a id="live" href="/live/">Live</a>
<a id="stream" href="/stream/">Streams</a>
<a id="game" href="/game/">Games</a>
<a id="register" href="/register/">Register</a>
<a id="login" href="/login/">Login</a>
</block>
</blockstart>
</header>

@ -13,12 +13,12 @@
<header>
<blockstart style="background-color: var(--value0)">
<block style="--value: 0; --text: 9" class="horizontal">
<a href="/">🏡</a>
<a href="/live/">Live</a>
<a href="/stream/">Streams</a>
<a href="/game/">Games</a>
<a href="/register/">Register</a>
<a href="/login/">Login</a>
<a id="home" href="/">🏡</a>
<a id="live" href="/live/">Live</a>
<a id="stream" href="/stream/">Streams</a>
<a id="game" href="/game/">Games</a>
<a id="register" href="/register/">Register</a>
<a id="login" href="/login/">Login</a>
</block>
</blockstart>
</header>

@ -13,12 +13,12 @@
<header>
<blockstart style="background-color: var(--value0)">
<block style="--value: 0; --text: 9" class="horizontal">
<a href="/">🏡</a>
<a href="/live/">Live</a>
<a href="/stream/">Streams</a>
<a href="/game/">Games</a>
<a href="/register/">Register</a>
<a href="/login/">Login</a>
<a id="home" href="/">🏡</a>
<a id="live" href="/live/">Live</a>
<a id="stream" href="/stream/">Streams</a>
<a id="game" href="/game/">Games</a>
<a id="register" href="/register/">Register</a>
<a id="login" href="/login/">Login</a>
</block>
</blockstart>
</header>
@ -28,7 +28,7 @@
</script>
<blockstart>
<block style="--w: 100%; --value: 7">
<h1>Zed's Trash Ass Games</h1>
<h1 id="page-title">Zed's Trash Ass Games</h1>
<p>More fun than a barrel full of monkeys with syphilus.
</p>
@ -37,7 +37,7 @@
<hr/>
<grid x-data="Games" style="--cols: 2">
<template x-for="item in theData">
<shape style="--h: 200px"><a x-text="item.title" x-bind:href="item.url"></a></shape>
<shape style="--h: 200px"><a data-testid="game-link" x-text="item.title" x-bind:href="item.url"></a></shape>
</template>
</grid>

@ -13,12 +13,12 @@
<header>
<blockstart style="background-color: var(--value0)">
<block style="--value: 0; --text: 9" class="horizontal">
<a href="/">🏡</a>
<a href="/live/">Live</a>
<a href="/stream/">Streams</a>
<a href="/game/">Games</a>
<a href="/register/">Register</a>
<a href="/login/">Login</a>
<a id="home" href="/">🏡</a>
<a id="live" href="/live/">Live</a>
<a id="stream" href="/stream/">Streams</a>
<a id="game" href="/game/">Games</a>
<a id="register" href="/register/">Register</a>
<a id="login" href="/login/">Login</a>
</block>
</blockstart>
</header>
@ -28,7 +28,7 @@
<shape style="--w: 100%; --h: 300px">
<button><a id="streams" href="/stream/">View Past Streams</a></button>
<button><a href="/live/">Watch Today's Livestream</a></button>
<button><a id="live" href="/live/">Watch Today's Livestream</a></button>
</shape>
<block data-testid="clickblock">

@ -13,12 +13,12 @@
<header>
<blockstart style="background-color: var(--value0)">
<block style="--value: 0; --text: 9" class="horizontal">
<a href="/">🏡</a>
<a href="/live/">Live</a>
<a href="/stream/">Streams</a>
<a href="/game/">Games</a>
<a href="/register/">Register</a>
<a href="/login/">Login</a>
<a id="home" href="/">🏡</a>
<a id="live" href="/live/">Live</a>
<a id="stream" href="/stream/">Streams</a>
<a id="game" href="/game/">Games</a>
<a id="register" href="/register/">Register</a>
<a id="login" href="/login/">Login</a>
</block>
</blockstart>
</header>

@ -13,12 +13,12 @@
<header>
<blockstart style="background-color: var(--value0)">
<block style="--value: 0; --text: 9" class="horizontal">
<a href="/">🏡</a>
<a href="/live/">Live</a>
<a href="/stream/">Streams</a>
<a href="/game/">Games</a>
<a href="/register/">Register</a>
<a href="/login/">Login</a>
<a id="home" href="/">🏡</a>
<a id="live" href="/live/">Live</a>
<a id="stream" href="/stream/">Streams</a>
<a id="game" href="/game/">Games</a>
<a id="register" href="/register/">Register</a>
<a id="login" href="/login/">Login</a>
</block>
</blockstart>
</header>

@ -13,12 +13,12 @@
<header>
<blockstart style="background-color: var(--value0)">
<block style="--value: 0; --text: 9" class="horizontal">
<a href="/">🏡</a>
<a href="/live/">Live</a>
<a href="/stream/">Streams</a>
<a href="/game/">Games</a>
<a href="/register/">Register</a>
<a href="/login/">Login</a>
<a id="home" href="/">🏡</a>
<a id="live" href="/live/">Live</a>
<a id="stream" href="/stream/">Streams</a>
<a id="game" href="/game/">Games</a>
<a id="register" href="/register/">Register</a>
<a id="login" href="/login/">Login</a>
</block>
</blockstart>
</header>

@ -13,12 +13,12 @@
<header>
<blockstart style="background-color: var(--value0)">
<block style="--value: 0; --text: 9" class="horizontal">
<a href="/">🏡</a>
<a href="/live/">Live</a>
<a href="/stream/">Streams</a>
<a href="/game/">Games</a>
<a href="/register/">Register</a>
<a href="/login/">Login</a>
<a id="home" href="/">🏡</a>
<a id="live" href="/live/">Live</a>
<a id="stream" href="/stream/">Streams</a>
<a id="game" href="/game/">Games</a>
<a id="register" href="/register/">Register</a>
<a id="login" href="/login/">Login</a>
</block>
</blockstart>
</header>
@ -30,7 +30,7 @@
<blockstart>
<block style="--value: 7">
<h1 id="streams-title">Past Streams</h1>
<h1 id="page-title">Past Streams</h1>
<p>This is where you can checkout information we dropped in a past stream. Did I post a link and you need to remember it? Did someone in chat mention something? Here's where you find it.</p>
</block>

@ -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"]`)
}
func TestGamePage(t *testing.T) {
require := require.New(t)
err = browser.Run(ctx, browser.Text(`#streams-title`, &title))
assert.NoError(err)
ctx, cancel := Setup(2);
defer cancel();
assert.Equal(title, "Past Streams")
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 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(assert *assert.Assertions, ctx context.Context, actions ...browser.Action) {
func Run(require *require.Assertions, ctx context.Context, actions ...browser.Action) {
err := browser.Run(ctx, actions...)
assert.NoError(err)
require.NoError(err)
}

Loading…
Cancel
Save