Skip to content

chore: add more e2e template settings tests #12717

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 10 commits into from
Mar 28, 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
Prev Previous commit
Next Next commit
yay!!!!
  • Loading branch information
aslilac committed Mar 28, 2024
commit 13412e2e6f28e67984fc010e2c80641b83cae514
7 changes: 7 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,13 @@ jobs:
- run: pnpm playwright:install
working-directory: site

# Run tests that don't require an enterprise license without an enterprise license
- run: pnpm playwright:test --forbid-only --workers 1
env:
DEBUG: pw:api
working-directory: site

# Run all of the tests with an enterprise license
- run: pnpm playwright:test --forbid-only --workers 1
env:
DEBUG: pw:api
Expand Down
1 change: 0 additions & 1 deletion site/e2e/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,3 @@ export const gitAuth = {
};

export const enterpriseLicense = process.env.CODER_E2E_ENTERPRISE_LICENSE ?? "";
export const skipEnterpriseTests = !enterpriseLicense;
14 changes: 0 additions & 14 deletions site/e2e/enterprise.setup.ts

This file was deleted.

12 changes: 12 additions & 0 deletions site/e2e/tests.setup.ts → site/e2e/global.setup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { test, expect } from "@playwright/test";
import { Language } from "pages/CreateUserPage/CreateUserForm";
import * as constants from "./constants";
import { requiresEnterpriseLicense } from "./helpers";
import { storageState } from "./playwright.config";

test("setup first user", async ({ page }) => {
Expand All @@ -16,3 +17,14 @@ test("setup first user", async ({ page }) => {

await page.getByTestId("button-select-template").isVisible();
});

test("setup license", async ({ page }) => {
requiresEnterpriseLicense();
await page.goto("/deployment/licenses", { waitUntil: "domcontentloaded" });

await page.getByText("Add a license").click();
await page.getByRole("textbox").fill(constants.enterpriseLicense);
await page.getByText("Upload License").click();

await page.getByText("You have successfully added a license").isVisible();
});
8 changes: 7 additions & 1 deletion site/e2e/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type BrowserContext, expect, type Page } from "@playwright/test";
import { type BrowserContext, expect, type Page, test } from "@playwright/test";
import axios from "axios";
import { type ChildProcess, exec, spawn } from "child_process";
import { randomUUID } from "crypto";
Expand All @@ -16,6 +16,7 @@ import {
agentPProfPort,
coderMain,
coderPort,
enterpriseLicense,
prometheusPort,
} from "./constants";
import {
Expand All @@ -30,6 +31,11 @@ import {
type RichParameter,
} from "./provisionerGenerated";

// requiresEnterpriseLicense will skip the test if we're not running with an enterprise license
export function requiresEnterpriseLicense() {
test.skip(!enterpriseLicense);
}

// createWorkspace creates a workspace for a template.
// It does not wait for it to be running, but it does navigate to the page.
export const createWorkspace = async (
Expand Down
23 changes: 2 additions & 21 deletions site/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,18 @@ export default defineConfig({
projects: [
{
name: "testsSetup",
testMatch: /tests.setup\.ts/,
testMatch: /global.setup\.ts/,
},
{
name: "tests",
testMatch: /.*\.spec\.ts/,
dependencies: ["testsSetup"],
use: {
storageState: storageState,
},
timeout: 60_000,
},
{
name: "enterpriseSetup",
testMatch: /enterprise.setup\.ts/,
dependencies: ["testsSetup"],
use: {
storageState: storageState,
},
},
{
name: "enterprise",
testMatch: /.*\.enterpriseSpec\.ts/,
dependencies: ["enterpriseSetup"],
use: {
storageState: storageState,
},
timeout: 60_000,
},
],
reporter: [["./reporter.ts"]],
use: {
storageState,
baseURL: `http://localhost:${coderPort}`,
video: "retain-on-failure",
...(wsEndpoint
Expand Down
23 changes: 0 additions & 23 deletions site/e2e/tests/updateTemplate.enterpriseSpec.ts

This file was deleted.

29 changes: 27 additions & 2 deletions site/e2e/tests/updateTemplate.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { test } from "@playwright/test";
import { createTemplate, updateTemplateSettings } from "../helpers";
import { expect, test } from "@playwright/test";
import {
createTemplate,
requiresEnterpriseLicense,
updateTemplateSettings,
} from "../helpers";

test("template update with new name redirects on successful submit", async ({
page,
Expand All @@ -10,3 +14,24 @@ test("template update with new name redirects on successful submit", async ({
name: "new-name",
});
});

test("require latest version", async ({ page }) => {
requiresEnterpriseLicense();

const templateName = await createTemplate(page);

await page.goto(`/templates/${templateName}/settings`, {
waitUntil: "domcontentloaded",
});
await expect(page).toHaveURL(`/templates/${templateName}/settings`);
let checkbox = await page.waitForSelector("#require_active_version");
await checkbox.click();
await page.getByTestId("form-submit").click();

await page.goto(`/templates/${templateName}/settings`, {
waitUntil: "domcontentloaded",
});
checkbox = await page.waitForSelector("#require_active_version");
await checkbox.scrollIntoViewIfNeeded();
expect(await checkbox.isChecked()).toBe(true);
});
Loading