Skip to content

test(site): add e2e tests for experiments #12940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test(site): add e2e tests for experiments
  • Loading branch information
mtojek committed Apr 11, 2024
commit d903728eca38517993ee983ce23c203737bf7b94
4 changes: 4 additions & 0 deletions site/e2e/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ export const requireEnterpriseTests = Boolean(
process.env.CODER_E2E_REQUIRE_ENTERPRISE_TESTS,
);
export const enterpriseLicense = process.env.CODER_E2E_ENTERPRISE_LICENSE ?? "";

// Fake experiments to verify that site presents them as enabled.
export const e2eFakeExperiment1 = "e2e-fake-experiment-1";
export const e2eFakeExperiment2 = "e2e-fake-experiment-2";
37 changes: 37 additions & 0 deletions site/e2e/tests/deployment/general.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { expect, test } from "@playwright/test";
import * as API from "api/api";
import { setupApiCalls } from "../../api";
import { requiresEnterpriseLicense } from "../../helpers";

test("experiments", async ({ page }) => {
requiresEnterpriseLicense();
await setupApiCalls(page);

// Load experiments from backend API
const availableExperiments = await API.getAvailableExperiments();
const enabledExperiments = await API.getExperiments();

// Verify if the site lists the same experiments
await page.goto("/deployment/general", { waitUntil: "domcontentloaded" });

const experimentsLocator = page.locator(
"div.options-table tr.option-experiments ul.option-array",
);
await expect(experimentsLocator).toBeVisible();

// Firstly, check if available experiments are listed
availableExperiments.safe.map(async (experiment) => {
const experimentLocator = experimentsLocator.locator(
`li.option-array-item-${experiment}`,
);
await expect(experimentLocator).toBeVisible();
});

// Secondly, check if all enabled experiments are listed
enabledExperiments.map(async (experiment) => {
const experimentLocator = experimentsLocator.locator(
`li.option-array-item-${experiment}.option-enabled`,
);
await expect(experimentLocator).toBeVisible();
});
});
5 changes: 4 additions & 1 deletion site/src/pages/DeploySettingsPage/Option.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const OptionValue: FC<OptionValueProps> = (props) => {

if (typeof value === "object" && !Array.isArray(value)) {
return (
<ul css={{ listStyle: "none" }}>
<ul css={{ listStyle: "none" }} className="option-array">
{Object.entries(value)
.sort((a, b) => a[0].localeCompare(b[0]))
.map(([option, isEnabled]) => (
Expand All @@ -64,6 +64,9 @@ export const OptionValue: FC<OptionValueProps> = (props) => {
color: theme.palette.text.disabled,
},
]}
className={`option-array-item-${option} ${
isEnabled ? "option-enabled" : "option-disabled"
}`}
>
<div
css={{
Expand Down
4 changes: 2 additions & 2 deletions site/src/pages/DeploySettingsPage/OptionsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const OptionsTable: FC<OptionsTableProps> = ({ options, additionalValues }) => {
}

return (
<TableContainer>
<TableContainer className="options-table">
<Table
css={css`
& td {
Expand Down Expand Up @@ -57,7 +57,7 @@ const OptionsTable: FC<OptionsTableProps> = ({ options, additionalValues }) => {
return null;
}
return (
<TableRow key={option.flag}>
<TableRow key={option.flag} className={"option-" + option.flag}>
<TableCell>
<OptionName>{option.name}</OptionName>
<OptionDescription>{option.description}</OptionDescription>
Expand Down