File size: 2,611 Bytes
9b906ea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { render, screen, fireEvent, waitFor } from "@testing-library/react";
import { afterEach, describe, expect, it, vi } from "vitest";
import { BackendConnectionOptions } from "./backend-form-modal";

// Isolate the manual "add backend" column: the sibling Cloud-login column
// drives an OAuth device flow that is irrelevant to backend-kind selection.
vi.mock("./device-flow-auth", () => ({
  DeviceFlowAuth: () => null,
}));

afterEach(() => {
  vi.clearAllMocks();
});

describe("BackendConnectionOptions — manual backend type", () => {
  it("defaults the Type selector to Cloud for an OpenHands Cloud host", () => {
    render(
      <BackendConnectionOptions
        onConnected={vi.fn()}
        initialManualBackend={{ host: "https://app.all-hands.dev" }}
      />,
    );

    expect(screen.getByTestId("add-backend-kind-option-cloud")).toHaveAttribute(
      "aria-checked",
      "true",
    );
    expect(screen.getByTestId("add-backend-kind-option-local")).toHaveAttribute(
      "aria-checked",
      "false",
    );
  });

  it("defaults the Type selector to Local for a self-hosted host on a custom domain", () => {
    // A self-hosted OHE on a custom domain is indistinguishable from a local
    // agent-server by host alone, so it must not be auto-classified as Cloud.
    render(
      <BackendConnectionOptions
        onConnected={vi.fn()}
        initialManualBackend={{ host: "https://app.adorable.build.one" }}
      />,
    );

    expect(screen.getByTestId("add-backend-kind-option-local")).toHaveAttribute(
      "aria-checked",
      "true",
    );
  });

  it("persists the user-selected Cloud kind when adding a self-hosted OHE on a custom domain", async () => {
    const onConnected = vi.fn();
    render(
      <BackendConnectionOptions
        onConnected={onConnected}
        initialManualBackend={{
          name: "Adorable Enterprise",
          host: "app.adorable.build.one",
          apiKey: "oh-cloud-key",
        }}
      />,
    );

    // The user overrides the (Local) default to declare this custom domain a
    // Cloud app-server, then connects.
    fireEvent.click(screen.getByTestId("add-backend-kind-option-cloud"));
    fireEvent.click(screen.getByTestId("add-backend-submit"));

    await waitFor(() => expect(onConnected).toHaveBeenCalledTimes(1));
    expect(onConnected).toHaveBeenCalledWith(
      expect.objectContaining({
        kind: "cloud",
        name: "Adorable Enterprise",
        host: "https://app.adorable.build.one",
        apiKey: "oh-cloud-key",
      }),
      "manual",
      { agentServerVersion: null },
    );
  });
});