You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.0 KiB
78 lines
2.0 KiB
package tests
|
|
|
|
import (
|
|
"testing"
|
|
"github.com/stretchr/testify/assert"
|
|
browser "github.com/chromedp/chromedp"
|
|
"zedshaw.games/webapp/data"
|
|
sq "github.com/Masterminds/squirrel"
|
|
)
|
|
|
|
func deleteTestUser(username string) {
|
|
sql, args, err := sq.Delete("user").Where("username=?", username).ToSql()
|
|
data.Exec(err, sql, args...)
|
|
}
|
|
|
|
func TestLogin(t *testing.T) {
|
|
assert := assert.New(t)
|
|
deleteTestUser("testerzed")
|
|
|
|
ctx, cancel := Setup(5); defer cancel()
|
|
|
|
Run(assert, ctx,
|
|
browser.Navigate(`http://127.0.0.1:5002/register/`),
|
|
browser.WaitVisible(`body > footer`),
|
|
browser.WaitVisible(`[data-testid="register-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-page"]`))
|
|
|
|
Run(assert, ctx,
|
|
browser.Navigate(`http://127.0.0.1:5002/login/`),
|
|
browser.WaitVisible(`body > footer`),
|
|
browser.WaitVisible(`[data-testid="login-page"]`),
|
|
browser.SendKeys(`#username`, `testerzed`),
|
|
browser.SendKeys(`#password`, `iamdumb`),
|
|
browser.Click(`#login-submit`, browser.NodeVisible),
|
|
browser.WaitVisible(`body > footer`),
|
|
browser.WaitVisible(`[data-testid="home-page"]`))
|
|
|
|
/// delete the user here
|
|
deleteTestUser("testerzed")
|
|
}
|
|
|
|
func TestStreamPage(t *testing.T) {
|
|
assert := assert.New(t)
|
|
|
|
ctx, cancel := Setup(2);
|
|
defer cancel();
|
|
|
|
var title string
|
|
|
|
err := browser.Run(ctx,
|
|
browser.Navigate(`http://127.0.0.1:5002`),
|
|
browser.WaitVisible(`body > footer`),
|
|
browser.WaitVisible(`#streams`),)
|
|
assert.NoError(err)
|
|
|
|
ClickOn(assert, ctx, `#streams`)
|
|
|
|
err = browser.Run(ctx, browser.WaitVisible(`#streams-title`))
|
|
assert.NoError(err)
|
|
|
|
err = browser.Run(ctx, browser.Text(`#streams-title`, &title))
|
|
assert.NoError(err)
|
|
|
|
assert.Equal(title, "Past Streams")
|
|
}
|
|
|
|
func TestMain(m *testing.M) {
|
|
data.Setup("sqlite3", "./db.sqlite3")
|
|
|
|
m.Run()
|
|
|
|
data.Shutdown()
|
|
}
|
|
|