//go:build browser package thintest import ( "testing" "amadan.net/oficina/equipo/internal/wire" ) // TestBrowserTokenRowEmail: on Connections, a token row's quiet "Add the // account email" opens the field in place. What is typed stays while the // page reads itself again for another row's change; a shape the server // refuses says so beside the field; a good one saves with no reload, the // field closes and the row shows the email as the person's, "(added by you)". func TestBrowserTokenRowEmail(t *testing.T) { r, runner, token, login := tokenRowRig(t) p := openInner(t, r.inst.URL, r.inst.Cookie(), 1280, 900, false, "light", "reduce") defer p.stop() p.open("/conversation/settings/connections") details := `document.querySelector('details[data-account-email="` + token + `"]')` field := details + `.querySelector('[data-email-field]')` p.wait(details, "the account email field") p.check(`!`+details+`.open && `+details+`.querySelector('summary').textContent==='Add the account email'`, "the field is closed behind its link") p.click(`details[data-account-email="` + token + `"] summary`) p.check(details+`.open`, "the link did not open the field") p.check(`(()=>{const f=`+field+`;f.focus();f.value='me@example';return true})()`, "type") // Another row changes: the page reads itself again, the field stays. hello := held(wire.HeldConnection{LocalID: "claude-9", Person: Owner, Provider: "claude", Kind: wire.KindToken, State: wire.ConnHealthy}, wire.HeldConnection{LocalID: "claude-1", Person: Owner, Provider: "claude", Kind: "subscription", Label: Owner, State: wire.ConnSignInAgain}) hello.Generation = runner.Welcome.Generation if err := runner.Send(r.ctx, "h2", wire.FrameHello, hello); err != nil { t.Fatal(err) } p.wait(`document.querySelector('[data-connection="`+login+`"][data-state="sign_in_again"]')`, "the other row's change in place") p.check(details+`.open && `+field+`.value==='me@example' && document.activeElement===`+field, "the refresh took the field away") // Refused by the server (the browser takes this shape): said here. p.click(`details[data-account-email="` + token + `"] [data-email-save]`) p.wait(`!`+details+`.querySelector('[data-email-note]').hidden`, "the refusal beside the field") p.check(details+`.querySelector('[data-email-note]').textContent==='That does not look like an email address.' && `+details+`.open`, "the refusal's words") p.check(`(()=>{`+field+`.value='me@example.com';return true})()`, "retype") p.click(`details[data-account-email="` + token + `"] [data-email-save]`) row := `document.querySelector('[data-connection="` + token + `"]')` p.wait(row+` && `+row+`.querySelector('[data-stated-email]') && `+row+`.querySelector('[data-stated-email]').textContent==='me@example.com'`, "the stated email on the row") p.check(row+`.querySelector('[equipo-conn-said]').textContent==='(added by you)' && !`+details+`.open && `+details+`.querySelector('summary').textContent==='Change the account email'`, "the saved row") p.stayed("saving the email") p.fits("the token row") p.shot("token-row-email-1280") waitFor(t, "the email stored", func() bool { var got string err := r.inst.DB.Writer().QueryRow("SELECT coalesce(stated_email, '') FROM chat_connections WHERE id = ?", token).Scan(&got) return err == nil && got == "me@example.com" }) }