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