| index 9463cb0..dea6502 100644 |
| --- a/internal/sheets/typestart_leave_browser_test.go |
| +++ b/internal/sheets/typestart_leave_browser_test.go |
| @@ -29,6 +29,7 @@ func TestFirstKeystrokeAfterLeavingTheGrid(t *testing.T) { |
| sheet, cells := newSheet(t, app, cookies, "Leaving") |
| for r := 0; r < 14; r++ { |
| postCell(t, app, cookies, cells, fmt.Sprintf(`{"r":%d,"c":0,"raw":"old%d"}`, r, r)) |
| + postCell(t, app, cookies, cells, fmt.Sprintf(`{"r":%d,"c":2,"raw":"c%d"}`, r, r)) |
| } |
| rig := harness.New(t, func(string) http.Handler { return productionHandler(t, app) }) |
| var set []chromedp.Action[chromedp.Void] |
| @@ -56,15 +57,21 @@ func TestFirstKeystrokeAfterLeavingTheGrid(t *testing.T) { |
| t.Fatalf("%s: %v", what, err) |
| } |
| } |
| - raw := func(r int) string { |
| - read := decodeGrid(t, do(t, app, as(httptest.NewRequest(http.MethodGet, cells+"?rows=16&cols=2", nil), cookies))) |
| + rawAt := func(r, col int) string { |
| + read := decodeGrid(t, do(t, app, as(httptest.NewRequest(http.MethodGet, cells+"?rows=16&cols=3", nil), cookies))) |
| for _, c := range read.Cells { |
| - if c.R == r && c.C == 0 { |
| + if c.R == r && c.C == col { |
| return c.Raw |
| } |
| } |
| return "" |
| } |
| + raw := func(r int) string { return rawAt(r, 0) } |
| + selection := func() [4]int { |
| + var s [4]int |
| + run("read the selection", evalInto(&s, `(() => { const s = SheetsGrid.selection(); return [s.r, s.c, s.r2, s.c2]; })()`)) |
| + return s |
| + } |
| saved := func(what string, r int, want string) { |
| t.Helper() |
| deadline := time.Now().Add(4 * time.Second) |
| @@ -106,7 +113,7 @@ func TestFirstKeystrokeAfterLeavingTheGrid(t *testing.T) { |
| run("open the sheet", chromedp.Navigate(fmt.Sprintf("%s/sheets/%d", rig.Origin, sheet.ID)), |
| chromedp.WaitVisible(chromedp.CSS(cell(13, 0))), chromedp.Sleep(200*time.Millisecond)) |
| for i, way := range ways { |
| - enter, escape := 2*i, 2*i+1 |
| + enter, escape := 3*i, 3*i+2 |
| // Enter saves what was typed. |
| run(way.name+": select", pointerClick(cell(enter, 0)), chromedp.Sleep(150*time.Millisecond)) |
| run(way.name+": leave", append(way.leave, chromedp.Sleep(way.pause))...) |
| @@ -116,6 +123,13 @@ func TestFirstKeystrokeAfterLeavingTheGrid(t *testing.T) { |
| t.Errorf("%s: Enter left the editor open", way.name) |
| } |
| saved(way.name+", Enter", enter, "q") |
| + // Enter moved on, so the next value lands one row down, not over this one. |
| + run(way.name+": type the next value", append(append(press("r", "KeyR", 82, "r"), chromedp.Sleep(100*time.Millisecond)), |
| + append(press("Enter", "Enter", 13, "\r"), chromedp.Sleep(300*time.Millisecond))...)...) |
| + saved(way.name+", the next value", enter+1, "r") |
| + if got := raw(enter); got != "q" { |
| + t.Errorf("%s: the second value overwrote the first: row %d holds %q", way.name, enter+1, got) |
| + } |
| |
| // Escape cancels, and a click away saves nothing. |
| run(way.name+": select", pointerClick(cell(escape, 0)), chromedp.Sleep(150*time.Millisecond)) |
| @@ -133,5 +147,27 @@ func TestFirstKeystrokeAfterLeavingTheGrid(t *testing.T) { |
| if got := raw(escape); got != fmt.Sprintf("old%d", escape) { |
| t.Errorf("%s: Escape then a click away saved %q over old%d", way.name, got, escape) |
| } |
| + |
| + // The grid's own keys still work after leaving it: an arrow, an |
| + // extending Shift+arrow, and Delete on what that selected. |
| + top := 3 * i |
| + run(way.name+": select in column C", pointerClick(cell(top, 2)), chromedp.Sleep(150*time.Millisecond)) |
| + run(way.name+": leave", append(way.leave, chromedp.Sleep(250*time.Millisecond))...) |
| + run(way.name+": ArrowDown", append(press("ArrowDown", "ArrowDown", 40, ""), chromedp.Sleep(150*time.Millisecond))...) |
| + if s := selection(); s[0] != top+1 || s[1] != 2 { |
| + t.Errorf("%s: ArrowDown left the selection at %v, want row %d", way.name, s, top+2) |
| + } |
| + run(way.name+": leave", append(way.leave, chromedp.Sleep(250*time.Millisecond))...) |
| + run(way.name+": Shift+ArrowDown", command(input.DispatchKeyEvent, input.DispatchKeyEventParams{Type: input.DispatchKeyEventTypeRawKeyDown, Key: "ArrowDown", Code: "ArrowDown", WindowsVirtualKeyCode: 40, Modifiers: 8}), |
| + command(input.DispatchKeyEvent, input.DispatchKeyEventParams{Type: input.DispatchKeyEventTypeKeyUp, Key: "ArrowDown", Code: "ArrowDown", WindowsVirtualKeyCode: 40, Modifiers: 8}), |
| + chromedp.Sleep(150*time.Millisecond)) |
| + if s := selection(); s[0] != top+1 || s[2] != top+2 { |
| + t.Errorf("%s: Shift+ArrowDown selected %v, want rows %d to %d", way.name, s, top+2, top+3) |
| + } |
| + run(way.name+": leave", append(way.leave, chromedp.Sleep(250*time.Millisecond))...) |
| + run(way.name+": Delete", append(press("Delete", "Delete", 46, ""), chromedp.Sleep(400*time.Millisecond))...) |
| + if got := rawAt(top+1, 2); got != "" { |
| + t.Errorf("%s: Delete left row %d of column C holding %q", way.name, top+2, got) |
| + } |
| } |
| } |