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

Function TestHandleAction_KeyDownAndUp

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

Source from the content-addressed store, hash-verified

524}
525
526func TestHandleAction_KeyDownAndUp(t *testing.T) {
527 t.Parallel()
528
529 tests := []struct {
530 name string
531 action string
532 wantOutput string
533 }{
534 {name: "KeyDown", action: "key_down", wantOutput: "key_down action performed"},
535 {name: "KeyUp", action: "key_up", wantOutput: "key_up action performed"},
536 }
537
538 for _, tt := range tests {
539 t.Run(tt.name, func(t *testing.T) {
540 t.Parallel()
541
542 logger := slogtest.Make(t, nil)
543 fake := &fakeDesktop{
544 startCfg: agentdesktop.DisplayConfig{Width: 1920, Height: 1080},
545 }
546 api := agentdesktop.NewAPI(logger, fake, nil)
547 defer api.Close()
548
549 text := "ctrl"
550 body := agentdesktop.DesktopAction{
551 Action: tt.action,
552 Text: &text,
553 }
554 b, err := json.Marshal(body)
555 require.NoError(t, err)
556
557 rr := httptest.NewRecorder()
558 req := httptest.NewRequest(http.MethodPost, "/action", bytes.NewReader(b))
559 req.Header.Set("Content-Type", "application/json")
560
561 handler := api.Routes()
562 handler.ServeHTTP(rr, req)
563
564 assert.Equal(t, http.StatusOK, rr.Code)
565
566 var resp agentdesktop.DesktopActionResponse
567 err = json.NewDecoder(rr.Body).Decode(&resp)
568 require.NoError(t, err)
569 assert.Equal(t, tt.wantOutput, resp.Output)
570 if tt.action == "key_down" {
571 assert.Equal(t, "ctrl", fake.lastKeyDown)
572 } else {
573 assert.Equal(t, "ctrl", fake.lastKeyUp)
574 }
575 })
576 }
577}
578
579func TestHandleAction_HoldKey(t *testing.T) {
580 t.Parallel()

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected