oficina / slides Public

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

Plain git — no account needed to clone.

Download

Download this file

1//go:build browser
2
3package slidestest
4
5import (
6 "encoding/json"
7 "strings"
8 "testing"
9)
10
11// Every change a person makes while a resync is pending is kept, in
12// Chromium and WebKit, through the real editor (fixtures/engines/
13// diverged.mjs; Paul: a lost edit is worse than a flash). The first save is
14// refused and the rebuild held while the person types on the refused text,
15// pastes elsewhere, deletes across the server's words, the refused text
16// and their own new words, and types elsewhere; or types on the refused
17// text, pastes elsewhere and types more after what they typed; or types
18// on the refused text, undoes it and types elsewhere; or types
19// into a paragraph the refused Enter made (which cannot be kept), then
20// elsewhere, then into it again. Afterwards the page holds everything but what the refusal
21// itself took, one undo takes back the last change as it was made, and
22// the server holds what the page shows.
23func TestEnginesEveryChangeWhileARefusalIsPendingIsKept(t *testing.T) {
24 out, fr, err := runEnginesRig(t, "diverged.mjs")
25 if err != nil {
26 t.Fatalf("a change made while the resync was pending was lost: %v\n%s", err, out)
27 }
28 n := 0
29 for _, line := range strings.Split(out, "\n") {
30 rest, ok := strings.CutPrefix(line, "RESULT ")
31 if !ok {
32 continue
33 }
34 var r struct {
35 Label, Deck string
36 Want []string
37 }
38 if err := json.Unmarshal([]byte(rest), &r); err != nil {
39 t.Fatal(err)
40 }
41 n++
42 if got := serverParagraphs(t, fr, r.Deck); strings.Join(got, "\n") != strings.Join(r.Want, "\n") {
43 t.Errorf("%s: the server holds %q, the page %q", r.Label, got, r.Want)
44 }
45 }
46 if n != 8 {
47 t.Errorf("%d cases reported, want 8 (four in each engine)", n)
48 }
49}
50