Skip to content

Commit 56a69b7

Browse files
presleypbpmct
andauthored
chore: add e2e tests for basic template and workspace flow (coder#5637)
* Fix type error in first user setup * Save auth state * Add template creation - wip Remove saved auth state because it wasn't working * Try adding the rest of the tests Can't see if they work yet, waiting on a release * Update playwright * Update gitignore * Write tests * Format * Update ignores * Check that start worked Co-authored-by: Ben Potter <ben@coder.com> Co-authored-by: Ben Potter <ben@coder.com>
1 parent 19ae42a commit 56a69b7

10 files changed

+100
-28
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ site/**/*.typegen.ts
2323
site/build-storybook.log
2424
site/coverage/
2525
site/storybook-static/
26-
site/test-results/
26+
site/test-results/*
27+
site/e2e/test-results/*
28+
site/e2e/storageState.json
29+
site/playwright-report/*
2730

2831
# Make target for updating golden files.
2932
cli/testdata/.gen-golden

.prettierignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ site/**/*.typegen.ts
2626
site/build-storybook.log
2727
site/coverage/
2828
site/storybook-static/
29-
site/test-results/
29+
site/test-results/*
30+
site/e2e/test-results/*
31+
site/e2e/storageState.json
32+
site/playwright-report/*
3033

3134
# Make target for updating golden files.
3235
cli/testdata/.gen-golden

site/.eslintignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ yarn-error.log
2626
build-storybook.log
2727
coverage/
2828
storybook-static/
29-
test-results/
29+
test-results/*
30+
e2e/test-results/*
31+
e2e/storageState.json
32+
playwright-report/*
3033

3134
# Make target for updating golden files.
3235
../cli/testdata/.gen-golden

site/.prettierignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ yarn-error.log
2626
build-storybook.log
2727
coverage/
2828
storybook-static/
29-
test-results/
29+
test-results/*
30+
e2e/test-results/*
31+
e2e/storageState.json
32+
playwright-report/*
3033

3134
# Make target for updating golden files.
3235
../cli/testdata/.gen-golden

site/e2e/globalSetup.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import * as constants from "./constants"
44

55
const globalSetup = async (): Promise<void> => {
66
axios.defaults.baseURL = `http://localhost:${constants.basePort}`
7+
// Create a user
78
await createFirstUser({
89
email: constants.email,
9-
organization: constants.organization,
1010
username: constants.username,
1111
password: constants.password,
12+
trial: false,
1213
})
1314
}
1415

site/e2e/helpers.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Page } from "@playwright/test"
2+
3+
export const buttons = {
4+
starterTemplates: "Starter templates",
5+
dockerTemplate: "Develop in Docker",
6+
useTemplate: "Use template",
7+
createTemplate: "Create template",
8+
createWorkspace: "Create workspace",
9+
submitCreateWorkspace: "Create workspace",
10+
stopWorkspace: "Stop",
11+
startWorkspace: "Start",
12+
}
13+
14+
export const clickButton = async (page: Page, name: string): Promise<void> => {
15+
await page.getByRole("button", { name, exact: true }).click()
16+
}
17+
18+
export const fillInput = async (
19+
page: Page,
20+
label: string,
21+
value: string,
22+
): Promise<void> => {
23+
await page.fill(`text=${label}`, value)
24+
}

site/e2e/tests/basicFlow.spec.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { test } from "@playwright/test"
2+
import { email, password } from "../constants"
3+
import { SignInPage } from "../pom"
4+
import { clickButton, buttons, fillInput } from "../helpers"
5+
6+
test("Basic flow", async ({ baseURL, page }) => {
7+
test.slow()
8+
await page.goto(baseURL + "/", { waitUntil: "networkidle" })
9+
10+
// Log-in with the default credentials we set up in the development server
11+
const signInPage = new SignInPage(baseURL, page)
12+
await signInPage.submitBuiltInAuthentication(email, password)
13+
14+
// create Docker template
15+
await page.waitForSelector("text=Templates")
16+
await page.click("text=Templates")
17+
18+
await clickButton(page, buttons.starterTemplates)
19+
20+
await page.click(`text=${buttons.dockerTemplate}`)
21+
22+
await clickButton(page, buttons.useTemplate)
23+
24+
await clickButton(page, buttons.createTemplate)
25+
26+
// create workspace
27+
await clickButton(page, buttons.createWorkspace)
28+
29+
await fillInput(page, "Workspace Name", "my-workspace")
30+
await clickButton(page, buttons.submitCreateWorkspace)
31+
32+
// stop workspace
33+
await page.waitForSelector("text=Started")
34+
await clickButton(page, buttons.stopWorkspace)
35+
36+
// start workspace
37+
await page.waitForSelector("text=Stopped")
38+
await clickButton(page, buttons.startWorkspace)
39+
await page.waitForSelector("text=Started")
40+
})

site/e2e/tests/login.spec.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

site/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"i18next": "21.9.1",
5858
"js-untar": "2.0.0",
5959
"just-debounce-it": "3.1.1",
60+
"playwright": "^1.29.2",
6061
"react": "18.2.0",
6162
"react-chartjs-2": "4.3.1",
6263
"react-color": "2.19.3",
@@ -81,7 +82,7 @@
8182
"yup": "0.32.11"
8283
},
8384
"devDependencies": {
84-
"@playwright/test": "1.26.1",
85+
"@playwright/test": "1.29.2",
8586
"@storybook/addon-actions": "6.5.9",
8687
"@storybook/addon-essentials": "6.5.12",
8788
"@storybook/addon-links": "6.5.9",

site/yarn.lock

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,13 +1921,13 @@
19211921
tiny-glob "^0.2.9"
19221922
tslib "^2.4.0"
19231923

1924-
"@playwright/test@1.26.1":
1925-
version "1.26.1"
1926-
resolved "https://registry.yarnpkg.com/@playwright/test/-/test-1.26.1.tgz#73ada4e70f618bca69ba7509c4ba65b5a41c4b10"
1927-
integrity sha512-bNxyZASVt2adSZ9gbD7NCydzcb5JaI0OR9hc7s+nmPeH604gwp0zp17NNpwXY4c8nvuBGQQ9oGDx72LE+cUWvw==
1924+
"@playwright/test@1.29.2":
1925+
version "1.29.2"
1926+
resolved "https://registry.yarnpkg.com/@playwright/test/-/test-1.29.2.tgz#c48184721d0f0b7627a886e2ec42f1efb2be339d"
1927+
integrity sha512-+3/GPwOgcoF0xLz/opTnahel1/y42PdcgZ4hs+BZGIUjtmEFSXGg+nFoaH3NSmuc7a6GSFwXDJ5L7VXpqzigNg==
19281928
dependencies:
19291929
"@types/node" "*"
1930-
playwright-core "1.26.1"
1930+
playwright-core "1.29.2"
19311931

19321932
"@pmmmwh/react-refresh-webpack-plugin@^0.5.3":
19331933
version "0.5.9"
@@ -11321,10 +11321,17 @@ pkg-dir@^5.0.0:
1132111321
dependencies:
1132211322
find-up "^5.0.0"
1132311323

11324-
playwright-core@1.26.1:
11325-
version "1.26.1"
11326-
resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.26.1.tgz#a162f476488312dcf12638d97685144de6ada512"
11327-
integrity sha512-hzFchhhxnEiPc4qVPs9q2ZR+5eKNifY2hQDHtg1HnTTUuphYCBP8ZRb2si+B1TR7BHirgXaPi48LIye5SgrLAA==
11324+
playwright-core@1.29.2:
11325+
version "1.29.2"
11326+
resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.29.2.tgz#2e8347e7e8522409f22b244e600e703b64022406"
11327+
integrity sha512-94QXm4PMgFoHAhlCuoWyaBYKb92yOcGVHdQLoxQ7Wjlc7Flg4aC/jbFW7xMR52OfXMVkWicue4WXE7QEegbIRA==
11328+
11329+
playwright@^1.29.2:
11330+
version "1.29.2"
11331+
resolved "https://registry.yarnpkg.com/playwright/-/playwright-1.29.2.tgz#d6a0a3e8e44f023f7956ed19ffa8af915a042769"
11332+
integrity sha512-hKBYJUtdmYzcjdhYDkP9WGtORwwZBBKAW8+Lz7sr0ZMxtJr04ASXVzH5eBWtDkdb0c3LLFsehfPBTRfvlfKJOA==
11333+
dependencies:
11334+
playwright-core "1.29.2"
1132811335

1132911336
pluralize@^8.0.0:
1133011337
version "8.0.0"

0 commit comments

Comments
 (0)