MCPcopy Index your code
hub / github.com/coder/coder / TestHandleAction_LeftClick

Function TestHandleAction_LeftClick

agent/x/agentdesktop/api_test.go:411–442  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

409}
410
411func TestHandleAction_LeftClick(t *testing.T) {
412 t.Parallel()
413
414 logger := slogtest.Make(t, nil)
415 fake := &fakeDesktop{
416 startCfg: agentdesktop.DisplayConfig{Width: 1920, Height: 1080},
417 }
418 api := agentdesktop.NewAPI(logger, fake, nil)
419 defer api.Close()
420
421 body := agentdesktop.DesktopAction{
422 Action: "left_click",
423 Coordinate: &[2]int{100, 200},
424 }
425 b, err := json.Marshal(body)
426 require.NoError(t, err)
427
428 rr := httptest.NewRecorder()
429 req := httptest.NewRequest(http.MethodPost, "/action", bytes.NewReader(b))
430 req.Header.Set("Content-Type", "application/json")
431
432 handler := api.Routes()
433 handler.ServeHTTP(rr, req)
434
435 assert.Equal(t, http.StatusOK, rr.Code)
436
437 var resp agentdesktop.DesktopActionResponse
438 err = json.NewDecoder(rr.Body).Decode(&resp)
439 require.NoError(t, err)
440 assert.Equal(t, "left_click action performed", resp.Output)
441 assert.Equal(t, [3]int{100, 200, 1}, fake.lastClick)
442}
443
444func TestHandleAction_UnknownAction(t *testing.T) {
445 t.Parallel()

Callers

nothing calls this directly

Calls 7

CloseMethod · 0.95
RoutesMethod · 0.95
NewAPIFunction · 0.92
SetMethod · 0.65
MarshalMethod · 0.45
ServeHTTPMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected