//go:build browser package slidestest import ( "encoding/json" "net/http" "strings" "testing" ) // replayDeck is the replay cases' deck: a heading, and a text block of two // paragraphs with nothing in code, so the code face is not on the page. const replayDeck = `[{"op":"set_meta","theme":"paper","title":"Replay"}, {"op":"add_slide","id":"slideone0001","layout":"flow","template":"title-body"}, {"op":"add_block","slide":"slideone0001","id":"head00000001","type":"heading","region":"heading","props":{"level":1},"markdown":"Replay"}, {"op":"add_block","slide":"slideone0001","id":"text00000001","type":"text","region":"body","markdown":"First paragraph.\n\nSecond paragraph."}]` // A paste that waited for its font, made after a save was refused, is // kept across the resync in Chromium and WebKit — Claude Fable's eleven // cases on #27 and #88, through the real editor (fixtures/engines/ // replay.mjs). Anchored to the refused text, its Yjs updates cannot be // carried; its ProseMirror transaction is replayed onto the rebuilt text // instead (fixtures/carry.mjs). Ten keep it — on the page, once, never // leaving it once there — and on the server, once, in the same words; the // paste into a paragraph the refused Enter made cannot be replayed, and is // left out cleanly: nothing posted, the save line saying failed. func TestFontEnginesAWaitingPasteSurvivesARefusedSave(t *testing.T) { out, fr, err := runEnginesRig(t, "replay.mjs") if err != nil { t.Fatalf("a paste that waited for its font was not kept across the resync: %v\n%s", err, out) } n := 0 for _, line := range strings.Split(out, "\n") { rest, ok := strings.CutPrefix(line, "RESULT ") if !ok { continue } var r struct { Label, Deck string Want []string } if err := json.Unmarshal([]byte(rest), &r); err != nil { t.Fatal(err) } n++ got := serverParagraphs(t, fr, r.Deck) if strings.Join(got, "\n") != strings.Join(r.Want, "\n") { t.Errorf("%s: the server holds %q, want %q", r.Label, got, r.Want) } } if n != 22 { t.Errorf("%d cases reported, want 22 (eleven in each engine)", n) } } // serverParagraphs is the text block's paragraphs as the server holds // them, each the words of its runs. func serverParagraphs(t *testing.T, fr *fontRig, sqid string) []string { t.Helper() view := apiJSON(t, fr.app, http.MethodGet, "/api/v1/decks/"+sqid, fr.token, "", http.StatusOK) b, _ := json.Marshal(view) var d struct { Slides []struct { Blocks []struct { ID string `json:"id"` Text [][]struct { T string `json:"t"` } `json:"text"` } `json:"blocks"` } `json:"slides"` } if err := json.Unmarshal(b, &d); err != nil { t.Fatal(err) } for _, s := range d.Slides { for _, bl := range s.Blocks { if bl.ID != "text00000001" { continue } var out []string for _, p := range bl.Text { var w strings.Builder for _, r := range p { w.WriteString(r.T) } out = append(out, w.String()) } return out } } t.Fatalf("no text block in %s", b) return nil }