Test can now attempt a login and the browser is shown rather than headless.
This commit is contained in:
parent
e29c36fb5c
commit
831b5ea762
6 changed files with 156 additions and 19 deletions
19
main.go
19
main.go
|
|
@ -14,6 +14,11 @@ import (
|
||||||
"github.com/gofiber/fiber/v2/middleware/session"
|
"github.com/gofiber/fiber/v2/middleware/session"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Login struct {
|
||||||
|
Username string `db:"username" validate:"required"`
|
||||||
|
Password string `db:"password" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
type Link struct {
|
type Link struct {
|
||||||
Id int `db:"id" json:"id"`
|
Id int `db:"id" json:"id"`
|
||||||
StreamId int `db:"stream_id" json:"stream_id" form:"stream_id" validate:"required,numeric"`
|
StreamId int `db:"stream_id" json:"stream_id" form:"stream_id" validate:"required,numeric"`
|
||||||
|
|
@ -65,6 +70,20 @@ func main() {
|
||||||
return tools.SelectJson[Link](db, c, err, sql, args...)
|
return tools.SelectJson[Link](db, c, err, sql, args...)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
app.Post("/api/login", func (c *fiber.Ctx) error {
|
||||||
|
login, err := tools.ReceivePost[Login](c)
|
||||||
|
|
||||||
|
if(err != nil) {
|
||||||
|
log.Println(err)
|
||||||
|
c.Redirect("/error/")
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("username: %s; password: %s", login.Username, login.Password);
|
||||||
|
|
||||||
|
return c.Redirect("/")
|
||||||
|
})
|
||||||
|
|
||||||
app.Post("/api/link", func (c *fiber.Ctx) error {
|
app.Post("/api/link", func (c *fiber.Ctx) error {
|
||||||
link, err := tools.ReceivePost[Link](c)
|
link, err := tools.ReceivePost[Link](c)
|
||||||
if(err != nil) {
|
if(err != nil) {
|
||||||
|
|
|
||||||
25
public/base.html
Normal file
25
public/base.html
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<link rel="stylesheet" href="/global.css">
|
||||||
|
<link rel="stylesheet" href="/color.css">
|
||||||
|
<link rel="stylesheet" href="/blockstart.css">
|
||||||
|
<title>ZedShaw's Game Thing</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<header>
|
||||||
|
<a href="/">🏡</a> <span>Zed's Game Dev Website Yay</span>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<blockstart>
|
||||||
|
|
||||||
|
</blockstart>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<h1>Footer</h1>
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
26
public/error/index.html
Normal file
26
public/error/index.html
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<link rel="stylesheet" href="/global.css">
|
||||||
|
<link rel="stylesheet" href="/color.css">
|
||||||
|
<link rel="stylesheet" href="/blockstart.css">
|
||||||
|
<title>ZedShaw's Game Thing</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<header>
|
||||||
|
<a href="/">🏡</a> <span>Zed's Game Dev Website Yay</span>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<blockstart>
|
||||||
|
<h1>ERROR</h1>
|
||||||
|
<p>You have an error.</p>
|
||||||
|
</blockstart>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<h1>Footer</h1>
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|
||||||
<body>
|
<body data-testid="home-page">
|
||||||
<header>
|
<header>
|
||||||
<a href="/">🏡</a> <span>Zed's Game Dev Website Yay</span>
|
<a href="/">🏡</a> <span>Zed's Game Dev Website Yay</span>
|
||||||
</header>
|
</header>
|
||||||
|
|
|
||||||
44
public/login/index.html
Normal file
44
public/login/index.html
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<link rel="stylesheet" href="/global.css">
|
||||||
|
<link rel="stylesheet" href="/color.css">
|
||||||
|
<link rel="stylesheet" href="/blockstart.css">
|
||||||
|
<title>ZedShaw's Game Thing</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
|
||||||
|
<body data-testid="login-page">
|
||||||
|
<header>
|
||||||
|
<a href="/">🏡</a> <span>Zed's Game Dev Website Yay</span>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<blockstart style="min-height: 90vw">
|
||||||
|
<h1>Login</h1>
|
||||||
|
<block class="center-self" style="--w: 500px; --h: 500px;">
|
||||||
|
<form action="/api/login" method="POST">
|
||||||
|
<card>
|
||||||
|
<top><h2 style="color: white">Login</h2></top>
|
||||||
|
<middle>
|
||||||
|
<label for="username">Username</label>
|
||||||
|
<input id="username" name="username" placeholder="Username" type="text">
|
||||||
|
<label for="password">Password</label>
|
||||||
|
<input id="password" name="password" placeholder="Password" type="text">
|
||||||
|
</middle>
|
||||||
|
<bottom>
|
||||||
|
<button-group>
|
||||||
|
<button type="button">Cancel</button>
|
||||||
|
<button id="login-submit" type="submit">Login</button>
|
||||||
|
</button-group>
|
||||||
|
</bottom>
|
||||||
|
</card>
|
||||||
|
</form>
|
||||||
|
</block>
|
||||||
|
</blockstart>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<h1>Footer</h1>
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
@ -3,6 +3,7 @@ package tests
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
"context"
|
"context"
|
||||||
|
"log"
|
||||||
"time"
|
"time"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
browser "github.com/chromedp/chromedp"
|
browser "github.com/chromedp/chromedp"
|
||||||
|
|
@ -14,11 +15,33 @@ func Run(assert *assert.Assertions, ctx context.Context, actions ...browser.Acti
|
||||||
}
|
}
|
||||||
|
|
||||||
func Setup(timeout time.Duration) (context.Context, context.CancelFunc) {
|
func Setup(timeout time.Duration) (context.Context, context.CancelFunc) {
|
||||||
ctx, _ := browser.NewContext(context.Background())
|
|
||||||
|
opts := append(browser.DefaultExecAllocatorOptions[:],
|
||||||
|
browser.Flag("headless", false),)
|
||||||
|
|
||||||
|
allocCtx, _ := browser.NewExecAllocator(context.Background(), opts...)
|
||||||
|
|
||||||
|
ctx, _ := browser.NewContext(allocCtx, browser.WithLogf(log.Printf))
|
||||||
|
|
||||||
return context.WithTimeout(ctx, timeout * time.Second)
|
return context.WithTimeout(ctx, timeout * time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLogin(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
ctx, cancel := Setup(5); defer cancel()
|
||||||
|
|
||||||
|
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`, `zedshaw`),
|
||||||
|
browser.SendKeys(`#password`, `1234`),
|
||||||
|
browser.Click(`#login-submit`, browser.NodeVisible),
|
||||||
|
browser.WaitVisible(`body > footer`),
|
||||||
|
browser.WaitVisible(`[data-testid="home-page"]`))
|
||||||
|
}
|
||||||
|
|
||||||
func TestStreamPage(t *testing.T) {
|
func TestStreamPage(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue