-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathexample_test.go
47 lines (40 loc) · 1.02 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package fir
import (
"context"
"net/http/httptest"
"os"
"testing"
"github.com/chromedp/chromedp"
"github.com/timshannon/bolthold"
)
func TestSanity(t *testing.T) {
dbfile, err := os.CreateTemp("", "test")
if err != nil {
t.Fatal(err)
}
db, err := bolthold.Open(dbfile.Name(), 0666, nil)
if err != nil {
panic(err)
}
controller := NewController("todos")
ts := httptest.NewServer(controller.RouteFunc(todosRoute(db)))
defer ts.Close()
ctx, cancel := chromedp.NewContext(context.Background())
defer cancel()
sel := `input[name="text"]`
todo := "test"
result := ""
if err := chromedp.Run(ctx,
chromedp.Navigate(ts.URL),
chromedp.WaitVisible(sel, chromedp.ByQuery),
chromedp.SendKeys(sel, todo, chromedp.ByQuery),
chromedp.Submit(sel, chromedp.ByQuery),
chromedp.WaitVisible(`div[id="todo-1"]`, chromedp.ByQuery),
chromedp.TextContent(`div[id="todo-1"]`, &result, chromedp.ByQuery),
); err != nil {
t.Fatal(err)
}
if removeSpace(result) != todo {
t.Fatalf("got %q, want %q", result, todo)
}
}