| 656 | } |
| 657 | |
| 658 | func TestHandleAction_ScrollDown(t *testing.T) { |
| 659 | t.Parallel() |
| 660 | |
| 661 | logger := slogtest.Make(t, nil) |
| 662 | fake := &fakeDesktop{ |
| 663 | startCfg: agentdesktop.DisplayConfig{Width: 1920, Height: 1080}, |
| 664 | } |
| 665 | api := agentdesktop.NewAPI(logger, fake, nil) |
| 666 | defer api.Close() |
| 667 | |
| 668 | dir := "down" |
| 669 | amount := 5 |
| 670 | body := agentdesktop.DesktopAction{ |
| 671 | Action: "scroll", |
| 672 | Coordinate: &[2]int{500, 400}, |
| 673 | ScrollDirection: &dir, |
| 674 | ScrollAmount: &amount, |
| 675 | } |
| 676 | b, err := json.Marshal(body) |
| 677 | require.NoError(t, err) |
| 678 | |
| 679 | rr := httptest.NewRecorder() |
| 680 | req := httptest.NewRequest(http.MethodPost, "/action", bytes.NewReader(b)) |
| 681 | req.Header.Set("Content-Type", "application/json") |
| 682 | |
| 683 | handler := api.Routes() |
| 684 | handler.ServeHTTP(rr, req) |
| 685 | |
| 686 | assert.Equal(t, http.StatusOK, rr.Code) |
| 687 | assert.Equal(t, [4]int{500, 400, 0, 5}, fake.lastScroll) |
| 688 | } |
| 689 | |
| 690 | func TestHandleAction_CoordinateScaling(t *testing.T) { |
| 691 | t.Parallel() |