oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1//go:build browser
2
3package thintest
4
5import (
6 "testing"
7
8 "amadan.net/oficina/equipo/internal/wire"
9)
10
11// TestBrowserTokenRowEmail: on Connections, a token row's quiet "Add the
12// account email" opens the field in place. What is typed stays while the
13// page reads itself again for another row's change; a shape the server
14// refuses says so beside the field; a good one saves with no reload, the
15// field closes and the row shows the email as the person's, "(added by you)".
16func TestBrowserTokenRowEmail(t *testing.T) {
17 r, runner, token, login := tokenRowRig(t)
18 p := openInner(t, r.inst.URL, r.inst.Cookie(), 1280, 900, false, "light", "reduce")
19 defer p.stop()
20 p.open("/conversation/settings/connections")
21 details := `document.querySelector('details[data-account-email="` + token + `"]')`
22 field := details + `.querySelector('[data-email-field]')`
23 p.wait(details, "the account email field")
24 p.check(`!`+details+`.open && `+details+`.querySelector('summary').textContent==='Add the account email'`, "the field is closed behind its link")
25 p.click(`details[data-account-email="` + token + `"] summary`)
26 p.check(details+`.open`, "the link did not open the field")
27 p.check(`(()=>{const f=`+field+`;f.focus();f.value='me@example';return true})()`, "type")
28
29 // Another row changes: the page reads itself again, the field stays.
30 hello := held(wire.HeldConnection{LocalID: "claude-9", Person: Owner, Provider: "claude", Kind: wire.KindToken, State: wire.ConnHealthy},
31 wire.HeldConnection{LocalID: "claude-1", Person: Owner, Provider: "claude", Kind: "subscription", Label: Owner, State: wire.ConnSignInAgain})
32 hello.Generation = runner.Welcome.Generation
33 if err := runner.Send(r.ctx, "h2", wire.FrameHello, hello); err != nil {
34 t.Fatal(err)
35 }
36 p.wait(`document.querySelector('[data-connection="`+login+`"][data-state="sign_in_again"]')`, "the other row's change in place")
37 p.check(details+`.open && `+field+`.value==='me@example' && document.activeElement===`+field, "the refresh took the field away")
38
39 // Refused by the server (the browser takes this shape): said here.
40 p.click(`details[data-account-email="` + token + `"] [data-email-save]`)
41 p.wait(`!`+details+`.querySelector('[data-email-note]').hidden`, "the refusal beside the field")
42 p.check(details+`.querySelector('[data-email-note]').textContent==='That does not look like an email address.' && `+details+`.open`, "the refusal's words")
43
44 p.check(`(()=>{`+field+`.value='me@example.com';return true})()`, "retype")
45 p.click(`details[data-account-email="` + token + `"] [data-email-save]`)
46 row := `document.querySelector('[data-connection="` + token + `"]')`
47 p.wait(row+` && `+row+`.querySelector('[data-stated-email]') && `+row+`.querySelector('[data-stated-email]').textContent==='me@example.com'`, "the stated email on the row")
48 p.check(row+`.querySelector('[equipo-conn-said]').textContent==='(added by you)' && !`+details+`.open && `+details+`.querySelector('summary').textContent==='Change the account email'`, "the saved row")
49 p.stayed("saving the email")
50 p.fits("the token row")
51 p.shot("token-row-email-1280")
52 waitFor(t, "the email stored", func() bool {
53 var got string
54 err := r.inst.DB.Writer().QueryRow("SELECT coalesce(stated_email, '') FROM chat_connections WHERE id = ?", token).Scan(&got)
55 return err == nil && got == "me@example.com"
56 })
57}
58