Skip to content

Commit dcf1d3a

Browse files
authored
test(site): add e2e tests for experiments (#12940)
1 parent b163bc7 commit dcf1d3a

File tree

5 files changed

+61
-5
lines changed

5 files changed

+61
-5
lines changed

site/e2e/constants.ts

+4
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,7 @@ export const requireEnterpriseTests = Boolean(
3737
process.env.CODER_E2E_REQUIRE_ENTERPRISE_TESTS,
3838
);
3939
export const enterpriseLicense = process.env.CODER_E2E_ENTERPRISE_LICENSE ?? "";
40+
41+
// Fake experiments to verify that site presents them as enabled.
42+
export const e2eFakeExperiment1 = "e2e-fake-experiment-1";
43+
export const e2eFakeExperiment2 = "e2e-fake-experiment-2";

site/e2e/playwright.config.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import { defineConfig } from "@playwright/test";
22
import * as path from "path";
3-
import { coderMain, coderPort, coderdPProfPort, gitAuth } from "./constants";
3+
import {
4+
coderMain,
5+
coderPort,
6+
coderdPProfPort,
7+
e2eFakeExperiment1,
8+
e2eFakeExperiment2,
9+
gitAuth,
10+
} from "./constants";
411

512
export const wsEndpoint = process.env.CODER_E2E_WS_ENDPOINT;
613

@@ -22,7 +29,7 @@ export default defineConfig({
2229
testMatch: /.*\.spec\.ts/,
2330
dependencies: ["testsSetup"],
2431
use: { storageState },
25-
timeout: 20_000,
32+
timeout: 50_000,
2633
},
2734
],
2835
reporter: [["./reporter.ts"]],
@@ -60,6 +67,8 @@ export default defineConfig({
6067
.join(" "),
6168
env: {
6269
...process.env,
70+
// Otherwise, the runner fails on Mac with: could not determine kind of name for C.uuid_string_t
71+
CGO_ENABLED: "0",
6372

6473
// This is the test provider for git auth with devices!
6574
CODER_GITAUTH_0_ID: gitAuth.deviceProvider,
@@ -101,6 +110,7 @@ export default defineConfig({
101110
gitAuth.validatePath,
102111
),
103112
CODER_PPROF_ADDRESS: "127.0.0.1:" + coderdPProfPort,
113+
CODER_EXPERIMENTS: e2eFakeExperiment1 + "," + e2eFakeExperiment2,
104114
},
105115
reuseExistingServer: false,
106116
},
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { expect, test } from "@playwright/test";
2+
import * as API from "api/api";
3+
import { setupApiCalls } from "../../api";
4+
import { e2eFakeExperiment1, e2eFakeExperiment2 } from "../../constants";
5+
6+
test("experiments", async ({ page }) => {
7+
await setupApiCalls(page);
8+
9+
// Load experiments from backend API
10+
const availableExperiments = await API.getAvailableExperiments();
11+
12+
// Verify if the site lists the same experiments
13+
await page.goto("/deployment/general", { waitUntil: "networkidle" });
14+
15+
const experimentsLocator = page.locator(
16+
"div.options-table tr.option-experiments ul.option-array",
17+
);
18+
await expect(experimentsLocator).toBeVisible();
19+
20+
// Firstly, check if all enabled experiments are listed
21+
expect(
22+
experimentsLocator.locator(
23+
`li.option-array-item-${e2eFakeExperiment1}.option-enabled`,
24+
),
25+
).toBeVisible;
26+
expect(
27+
experimentsLocator.locator(
28+
`li.option-array-item-${e2eFakeExperiment2}.option-enabled`,
29+
),
30+
).toBeVisible;
31+
32+
// Secondly, check if available experiments are listed
33+
for (const experiment of availableExperiments.safe) {
34+
const experimentLocator = experimentsLocator.locator(
35+
`li.option-array-item-${experiment}`,
36+
);
37+
await expect(experimentLocator).toBeVisible();
38+
}
39+
});

site/src/pages/DeploySettingsPage/Option.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const OptionValue: FC<OptionValueProps> = (props) => {
5151

5252
if (typeof value === "object" && !Array.isArray(value)) {
5353
return (
54-
<ul css={{ listStyle: "none" }}>
54+
<ul css={{ listStyle: "none" }} className="option-array">
5555
{Object.entries(value)
5656
.sort((a, b) => a[0].localeCompare(b[0]))
5757
.map(([option, isEnabled]) => (
@@ -64,6 +64,9 @@ export const OptionValue: FC<OptionValueProps> = (props) => {
6464
color: theme.palette.text.disabled,
6565
},
6666
]}
67+
className={`option-array-item-${option} ${
68+
isEnabled ? "option-enabled" : "option-disabled"
69+
}`}
6770
>
6871
<div
6972
css={{

site/src/pages/DeploySettingsPage/OptionsTable.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const OptionsTable: FC<OptionsTableProps> = ({ options, additionalValues }) => {
2727
}
2828

2929
return (
30-
<TableContainer>
30+
<TableContainer className="options-table">
3131
<Table
3232
css={css`
3333
& td {
@@ -57,7 +57,7 @@ const OptionsTable: FC<OptionsTableProps> = ({ options, additionalValues }) => {
5757
return null;
5858
}
5959
return (
60-
<TableRow key={option.flag}>
60+
<TableRow key={option.flag} className={"option-" + option.flag}>
6161
<TableCell>
6262
<OptionName>{option.name}</OptionName>
6363
<OptionDescription>{option.description}</OptionDescription>

0 commit comments

Comments
 (0)