//go:build browser package thintest import ( "context" "os" "path/filepath" "strconv" "testing" "github.com/chromedp/chromedp" ) func TestBrowserAutonomySettings(t *testing.T) { r := &toolRig{rig: newRig(t)} if err := r.inst.DB.G.Exec("INSERT INTO chat_projects(id,repo,title,state,revision) VALUES ('autonomy-project','amadan.net/oficina/sample','Sample project','active',1)").Error; err != nil { t.Fatal(err) } for _, size := range settingsSizes { p := openInner(t, r.inst.URL, r.inst.Cookie(), size.w, size.h, size.touch, "light", "no-preference") p.open("/conversation/settings/autonomy") p.check(`document.documentElement.scrollWidth<=innerWidth`, "settings overflow") p.check(`document.querySelectorAll('#autonomy input[type=checkbox]').length===3`, "three choices") p.check(`(()=>{for(const e of document.querySelectorAll('#autonomy input[type=checkbox]')){if(!document.querySelector('label[for="'+e.id+'"]')||!document.getElementById(e.getAttribute('aria-describedby')))return false}return true})()`, "switch labels and descriptions") p.check(`(()=>{window.__page=1;for(const e of document.querySelectorAll('#autonomy input[type=checkbox]'))e.checked=true;return true})()`, "choose settings") p.click(`#autonomy button[type=submit]`) p.wait(`document.querySelector('#autonomy input[name=revision]').value!=='0'`, "saved revision") p.check(`window.__page===1`, "save reloaded the page") if dir := os.Getenv("EQUIPO_AUTONOMY_SHOTS"); dir != "" { var shot []byte p.do(chromedp.Func(func(ctx context.Context, target *chromedp.Target) error { var err error shot, err = chromedp.FullScreenshot(90)(ctx, target) return err })) if err := os.WriteFile(filepath.Join(dir, "autonomy-"+strconv.FormatInt(size.w, 10)+".png"), shot, 0600); err != nil { t.Fatal(err) } } p.stop() } }