Skip to content

Commit 63f610b

Browse files
committed
added test, consolidated names
1 parent 3455992 commit 63f610b

File tree

7 files changed

+132
-17
lines changed

7 files changed

+132
-17
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import { MockWorkspaceAgent } from "testHelpers/entities";
2+
import { WorkspaceAgent, DisplayApps, DisplayApp } from "api/typesGenerated";
3+
import { renderComponent } from "testHelpers/renderHelpers";
4+
import { AgentRowPreview } from "./AgentRowPreview";
5+
import { screen } from "@testing-library/react";
6+
import { DisplayAppNameMap } from "./AppLink/AppLink";
7+
8+
const AllDisplayAppsAndModule = MockWorkspaceAgent;
9+
const VSCodeNoInsiders = {
10+
...MockWorkspaceAgent,
11+
display_apps: [
12+
"ssh_helper",
13+
"port_forwarding_helper",
14+
"vscode",
15+
"web_terminal",
16+
] as DisplayApp[],
17+
};
18+
const VSCodeWithInsiders = {
19+
...MockWorkspaceAgent,
20+
display_apps: [
21+
"ssh_helper",
22+
"port_forwarding_helper",
23+
"vscode",
24+
"vscode_insiders",
25+
"web_terminal",
26+
] as DisplayApp[],
27+
};
28+
const NoVSCode = {
29+
...MockWorkspaceAgent,
30+
display_apps: [
31+
"ssh_helper",
32+
"port_forwarding_helper",
33+
"web_terminal",
34+
] as DisplayApp[],
35+
};
36+
37+
describe("AgentRowPreviewApps", () => {
38+
it.each<{
39+
workspaceAgent: WorkspaceAgent;
40+
testName: string;
41+
}>([
42+
{
43+
workspaceAgent: AllDisplayAppsAndModule,
44+
testName: "AllDisplayAppsAndModule",
45+
},
46+
{
47+
workspaceAgent: VSCodeNoInsiders,
48+
testName: "VSCodeNoInsiders",
49+
},
50+
{
51+
workspaceAgent: VSCodeWithInsiders,
52+
testName: "VSCodeWithInsiders",
53+
},
54+
{
55+
workspaceAgent: NoVSCode,
56+
testName: "NoVSCode",
57+
},
58+
])(
59+
`<AgentRowPreview agent={$testName} /> displays appropriately`,
60+
({ workspaceAgent }) => {
61+
renderComponent(<AgentRowPreview agent={workspaceAgent} />);
62+
workspaceAgent.apps.forEach((module) => {
63+
expect(screen.getByText(module.display_name)).toBeInTheDocument();
64+
});
65+
workspaceAgent.display_apps
66+
.filter((app) => app !== "vscode" && app !== "vscode_insiders") // these get special treatment
67+
.forEach((app) => {
68+
expect(screen.getByText(DisplayAppNameMap[app])).toBeInTheDocument();
69+
});
70+
71+
// test VS Code display
72+
if (workspaceAgent.display_apps.includes("vscode")) {
73+
expect(
74+
screen.getByText(DisplayAppNameMap["vscode"]),
75+
).toBeInTheDocument();
76+
} else if (workspaceAgent.display_apps.includes("vscode_insiders")) {
77+
expect(
78+
screen.getByText(DisplayAppNameMap["vscode_insiders"]),
79+
).toBeInTheDocument();
80+
} else {
81+
expect(screen.queryByText("vscode")).not.toBeInTheDocument();
82+
expect(screen.queryByText("vscode_insiders")).not.toBeInTheDocument();
83+
}
84+
85+
// difference between all possible display apps and those displayed
86+
const excludedApps = DisplayApps.filter(
87+
(a) => !workspaceAgent.display_apps.includes(a),
88+
);
89+
90+
excludedApps.forEach((app) => {
91+
expect(
92+
screen.queryByText(DisplayAppNameMap[app]),
93+
).not.toBeInTheDocument();
94+
});
95+
},
96+
);
97+
});

site/src/components/Resources/AgentRowPreview.tsx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Stack } from "../Stack/Stack";
55
import { AppPreview } from "./AppLink/AppPreview";
66
import { BaseIcon } from "./AppLink/BaseIcon";
77
import { VSCodeIcon } from "components/Icons/VSCodeIcon";
8+
import { DisplayAppNameMap } from "./AppLink/AppLink";
89

910
interface AgentRowPreviewStyles {
1011
// Helpful when there are more than one row so the values are aligned
@@ -100,23 +101,29 @@ export const AgentRowPreview: FC<AgentRowPreviewProps> = ({
100101
{/* Additionally, we display any apps that are visible, e.g.
101102
apps that are included in agent.display_apps */}
102103
{agent.display_apps.includes("web_terminal") && (
103-
<AppPreview>Terminal</AppPreview>
104+
<AppPreview>{DisplayAppNameMap["web_terminal"]}</AppPreview>
104105
)}
105106
{agent.display_apps.includes("ssh_helper") && (
106-
<AppPreview>SSH</AppPreview>
107+
<AppPreview>{DisplayAppNameMap["ssh_helper"]}</AppPreview>
107108
)}
108109
{agent.display_apps.includes("port_forwarding_helper") && (
109-
<AppPreview>Ports</AppPreview>
110+
<AppPreview>
111+
{DisplayAppNameMap["port_forwarding_helper"]}
112+
</AppPreview>
110113
)}
111114
{/* VSCode display apps (vscode, vscode_insiders) get special presentation */}
112-
{(agent.display_apps.includes("vscode") ||
113-
agent.display_apps.includes("vscode_insiders")) && (
115+
{agent.display_apps.includes("vscode") ? (
114116
<AppPreview>
115-
<>
116-
<VSCodeIcon sx={{ width: 12, height: 12 }} />
117-
VS Code Desktop
118-
</>
117+
<VSCodeIcon sx={{ width: 12, height: 12 }} />
118+
{DisplayAppNameMap["vscode"]}
119119
</AppPreview>
120+
) : (
121+
agent.display_apps.includes("vscode_insiders") && (
122+
<AppPreview>
123+
<VSCodeIcon sx={{ width: 12, height: 12 }} />
124+
{DisplayAppNameMap["vscode_insiders"]}
125+
</AppPreview>
126+
)
120127
)}
121128
{agent.apps.length === 0 && (
122129
<span css={styles.agentDataValue}>None</span>

site/src/components/Resources/AppLink/AppLink.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ import { generateRandomString } from "utils/random";
1313
import { BaseIcon } from "./BaseIcon";
1414
import { ShareIcon } from "./ShareIcon";
1515

16+
export const DisplayAppNameMap: Record<TypesGen.DisplayApp, string> = {
17+
port_forwarding_helper: "Ports",
18+
ssh_helper: "SSH",
19+
vscode: "VS Code Desktop",
20+
vscode_insiders: "VS Code Insiders",
21+
web_terminal: "Terminal",
22+
};
23+
1624
const Language = {
1725
appTitle: (appName: string, identifier: string): string =>
1826
`${appName} - ${identifier}`,

site/src/components/Resources/PortForwardButton.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
PopoverContent,
2727
PopoverTrigger,
2828
} from "components/Popover/Popover";
29+
import { DisplayAppNameMap } from "./AppLink/AppLink";
2930

3031
export interface PortForwardButtonProps {
3132
host: string;
@@ -50,7 +51,7 @@ export const PortForwardButton: FC<PortForwardButtonProps> = (props) => {
5051
<Popover>
5152
<PopoverTrigger>
5253
<AgentButton disabled={!portsQuery.data}>
53-
Ports
54+
{DisplayAppNameMap["port_forwarding_helper"]}
5455
{portsQuery.data ? (
5556
<div css={styles.portCount}>{portsQuery.data.ports.length}</div>
5657
) : (

site/src/components/Resources/SSHButton/SSHButton.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
} from "components/Popover/Popover";
1616
import { Stack } from "components/Stack/Stack";
1717
import { AgentButton } from "../AgentButton";
18+
import { DisplayAppNameMap } from "../AppLink/AppLink";
1819

1920
export interface SSHButtonProps {
2021
workspaceName: string;
@@ -34,7 +35,7 @@ export const SSHButton: FC<PropsWithChildren<SSHButtonProps>> = ({
3435
return (
3536
<Popover isDefaultOpen={isDefaultOpen}>
3637
<PopoverTrigger>
37-
<AgentButton>SSH</AgentButton>
38+
<AgentButton>{DisplayAppNameMap["ssh_helper"]}</AgentButton>
3839
</PopoverTrigger>
3940

4041
<PopoverContent horizontal="right" classes={{ paper }}>

site/src/components/Resources/TerminalLink/TerminalLink.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { AgentButton } from "components/Resources/AgentButton";
33
import { FC } from "react";
44
import * as TypesGen from "api/typesGenerated";
55
import { generateRandomString } from "utils/random";
6+
import { DisplayAppNameMap } from "../AppLink/AppLink";
67

78
export const Language = {
8-
linkText: "Terminal",
99
terminalTitle: (identifier: string): string => `Terminal - ${identifier}`,
1010
};
1111

@@ -46,7 +46,7 @@ export const TerminalLink: FC<React.PropsWithChildren<TerminalLinkProps>> = ({
4646
}}
4747
data-testid="terminal"
4848
>
49-
<AgentButton>{Language.linkText}</AgentButton>
49+
<AgentButton>{DisplayAppNameMap["web_terminal"]}</AgentButton>
5050
</Link>
5151
);
5252
};

site/src/components/Resources/VSCodeDesktopButton/VSCodeDesktopButton.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { useLocalStorage } from "hooks";
99
import Menu from "@mui/material/Menu";
1010
import MenuItem from "@mui/material/MenuItem";
1111
import { DisplayApp } from "api/typesGenerated";
12+
import { DisplayAppNameMap } from "../AppLink/AppLink";
1213

1314
export interface VSCodeDesktopButtonProps {
1415
userName: string;
@@ -97,7 +98,7 @@ export const VSCodeDesktopButton: FC<
9798
}}
9899
>
99100
<VSCodeIcon sx={{ width: 12, height: 12 }} />
100-
VS Code Desktop
101+
{DisplayAppNameMap["vscode"]}
101102
</MenuItem>
102103
<MenuItem
103104
sx={{ fontSize: 14 }}
@@ -106,7 +107,7 @@ export const VSCodeDesktopButton: FC<
106107
}}
107108
>
108109
<VSCodeInsidersIcon sx={{ width: 12, height: 12 }} />
109-
VS Code Insiders
110+
{DisplayAppNameMap["vscode_insiders"]}
110111
</MenuItem>
111112
</Menu>
112113
</div>
@@ -156,7 +157,7 @@ const VSCodeButton = ({
156157
});
157158
}}
158159
>
159-
VS Code Desktop
160+
{DisplayAppNameMap["vscode"]}
160161
</AgentButton>
161162
);
162163
};
@@ -200,7 +201,7 @@ const VSCodeInsidersButton = ({
200201
});
201202
}}
202203
>
203-
VS Code Insiders
204+
{DisplayAppNameMap["vscode_insiders"]}
204205
</AgentButton>
205206
);
206207
};

0 commit comments

Comments
 (0)