Add task capture, work reports, daily digests and private contacts
Build and publish container images / images (push) Successful in 16m37s
Build and publish container images / images (push) Successful in 16m37s
This commit is contained in:
1 parent
50b8b0323f
commit
b4792bb175
50 files changed
+2678
-17
No files matched your search
@@ -0,0 +1,80 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestProductivityChromium(t *testing.T) {
|
||||
if os.Getenv("PAGESWIKI_BROWSER_TEST") != "1" {
|
||||
t.Skip("opt-in Chromium")
|
||||
}
|
||||
for _, view := range []string{"contacts", "settings", "report", "tasks", "home"} {
|
||||
for _, size := range []string{"desktop", "mobile"} {
|
||||
t.Run(view+"-"+size, func(t *testing.T) {
|
||||
s, token, domain, actor := taskFixture(t)
|
||||
s.mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { s.renderSearchHome(w, r, "search") })
|
||||
item := newTaskRecord("task", "Browser work task")
|
||||
item.Status = "done"
|
||||
item.Estimate = 60
|
||||
item.Complexity = 3
|
||||
if _, e := s.store.SaveTask(context.Background(), domain, actor, item, 0); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
repo, e := s.calendars()
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, e = repo.Create(context.Background(), domain, actor, "Command calendar", "local"); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
script, e := os.ReadFile("internal/server/testdata/productivity-browser.js")
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
path := map[string]string{"contacts": "/v/plan/contacts", "settings": "/v/plan/tasks/settings", "report": "/v/plan/tasks/report", "tasks": "/v/plan/tasks", "home": "/"}[view]
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
r.Header.Set("Authorization", "Bearer "+token)
|
||||
if r.Method == "GET" && r.URL.Path == path {
|
||||
rec := httptest.NewRecorder()
|
||||
s.withAuthorization(s.mux).ServeHTTP(rec, r)
|
||||
for k, v := range rec.Header() {
|
||||
w.Header()[k] = v
|
||||
}
|
||||
w.WriteHeader(rec.Code)
|
||||
// The home template uses nonce CSP. Reuse its already generated nonce
|
||||
// only in this synthetic fixture; production HTML is never rewritten.
|
||||
nonce := ""
|
||||
if csp := rec.Header().Get("Content-Security-Policy"); strings.Contains(csp, "'nonce-") {
|
||||
nonce = strings.SplitN(strings.SplitN(csp, "'nonce-", 2)[1], "'", 2)[0]
|
||||
}
|
||||
w.Write([]byte(strings.Replace(rec.Body.String(), "</body>", "<script nonce=\""+nonce+"\">"+string(script)+"</script></body>", 1)))
|
||||
return
|
||||
}
|
||||
s.withAuthorization(s.mux).ServeHTTP(w, r)
|
||||
}))
|
||||
defer server.Close()
|
||||
width, height := "1440", "1000"
|
||||
if size == "mobile" {
|
||||
width, height = "390", "844"
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 45*time.Second)
|
||||
defer cancel()
|
||||
shot := ""
|
||||
if prefix := os.Getenv("PAGESWIKI_PRODUCTIVITY_SCREENSHOT"); prefix != "" {
|
||||
shot = prefix + "-" + view + "-" + size + ".png"
|
||||
}
|
||||
out, e := exec.CommandContext(ctx, "node", "internal/server/testdata/vim-browser-smoke.mjs", strings.Replace(server.URL, "127.0.0.1", "localhost", 1)+path, t.TempDir(), shot, width, height).CombinedOutput()
|
||||
if e != nil {
|
||||
t.Fatalf("%v: %s", e, out)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user