chore: add e2e tests for basic template and workspace flow (#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>
This commit is contained in:
Presley Pizzo 2023-01-10 12:30:44 -05:00 committed by GitHub
parent 19ae42af53
commit 56a69b7eea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 100 additions and 28 deletions

5
.gitignore vendored
View File

@ -23,7 +23,10 @@ site/**/*.typegen.ts
site/build-storybook.log
site/coverage/
site/storybook-static/
site/test-results/
site/test-results/*
site/e2e/test-results/*
site/e2e/storageState.json
site/playwright-report/*
# Make target for updating golden files.
cli/testdata/.gen-golden

View File

@ -26,7 +26,10 @@ site/**/*.typegen.ts
site/build-storybook.log
site/coverage/
site/storybook-static/
site/test-results/
site/test-results/*
site/e2e/test-results/*
site/e2e/storageState.json
site/playwright-report/*
# Make target for updating golden files.
cli/testdata/.gen-golden

View File

@ -26,7 +26,10 @@ yarn-error.log
build-storybook.log
coverage/
storybook-static/
test-results/
test-results/*
e2e/test-results/*
e2e/storageState.json
playwright-report/*
# Make target for updating golden files.
../cli/testdata/.gen-golden

View File

@ -26,7 +26,10 @@ yarn-error.log
build-storybook.log
coverage/
storybook-static/
test-results/
test-results/*
e2e/test-results/*
e2e/storageState.json
playwright-report/*
# Make target for updating golden files.
../cli/testdata/.gen-golden

View File

@ -4,11 +4,12 @@ import * as constants from "./constants"
const globalSetup = async (): Promise<void> => {
axios.defaults.baseURL = `http://localhost:${constants.basePort}`
// Create a user
await createFirstUser({
email: constants.email,
organization: constants.organization,
username: constants.username,
password: constants.password,
trial: false,
})
}

24
site/e2e/helpers.ts Normal file
View File

@ -0,0 +1,24 @@
import { Page } from "@playwright/test"
export const buttons = {
starterTemplates: "Starter templates",
dockerTemplate: "Develop in Docker",
useTemplate: "Use template",
createTemplate: "Create template",
createWorkspace: "Create workspace",
submitCreateWorkspace: "Create workspace",
stopWorkspace: "Stop",
startWorkspace: "Start",
}
export const clickButton = async (page: Page, name: string): Promise<void> => {
await page.getByRole("button", { name, exact: true }).click()
}
export const fillInput = async (
page: Page,
label: string,
value: string,
): Promise<void> => {
await page.fill(`text=${label}`, value)
}

View File

@ -0,0 +1,40 @@
import { test } from "@playwright/test"
import { email, password } from "../constants"
import { SignInPage } from "../pom"
import { clickButton, buttons, fillInput } from "../helpers"
test("Basic flow", async ({ baseURL, page }) => {
test.slow()
await page.goto(baseURL + "/", { waitUntil: "networkidle" })
// Log-in with the default credentials we set up in the development server
const signInPage = new SignInPage(baseURL, page)
await signInPage.submitBuiltInAuthentication(email, password)
// create Docker template
await page.waitForSelector("text=Templates")
await page.click("text=Templates")
await clickButton(page, buttons.starterTemplates)
await page.click(`text=${buttons.dockerTemplate}`)
await clickButton(page, buttons.useTemplate)
await clickButton(page, buttons.createTemplate)
// create workspace
await clickButton(page, buttons.createWorkspace)
await fillInput(page, "Workspace Name", "my-workspace")
await clickButton(page, buttons.submitCreateWorkspace)
// stop workspace
await page.waitForSelector("text=Started")
await clickButton(page, buttons.stopWorkspace)
// start workspace
await page.waitForSelector("text=Stopped")
await clickButton(page, buttons.startWorkspace)
await page.waitForSelector("text=Started")
})

View File

@ -1,13 +0,0 @@
import { test } from "@playwright/test"
import { email, password } from "../constants"
import { SignInPage } from "../pom"
test("Login takes user to /workspaces", async ({ baseURL, page }) => {
await page.goto(baseURL + "/", { waitUntil: "networkidle" })
// Log-in with the default credentials we set up in the development server
const signInPage = new SignInPage(baseURL, page)
await signInPage.submitBuiltInAuthentication(email, password)
await page.waitForSelector("text=Workspaces")
})

View File

@ -57,6 +57,7 @@
"i18next": "21.9.1",
"js-untar": "2.0.0",
"just-debounce-it": "3.1.1",
"playwright": "^1.29.2",
"react": "18.2.0",
"react-chartjs-2": "4.3.1",
"react-color": "2.19.3",
@ -81,7 +82,7 @@
"yup": "0.32.11"
},
"devDependencies": {
"@playwright/test": "1.26.1",
"@playwright/test": "1.29.2",
"@storybook/addon-actions": "6.5.9",
"@storybook/addon-essentials": "6.5.12",
"@storybook/addon-links": "6.5.9",

View File

@ -1921,13 +1921,13 @@
tiny-glob "^0.2.9"
tslib "^2.4.0"
"@playwright/test@1.26.1":
version "1.26.1"
resolved "https://registry.yarnpkg.com/@playwright/test/-/test-1.26.1.tgz#73ada4e70f618bca69ba7509c4ba65b5a41c4b10"
integrity sha512-bNxyZASVt2adSZ9gbD7NCydzcb5JaI0OR9hc7s+nmPeH604gwp0zp17NNpwXY4c8nvuBGQQ9oGDx72LE+cUWvw==
"@playwright/test@1.29.2":
version "1.29.2"
resolved "https://registry.yarnpkg.com/@playwright/test/-/test-1.29.2.tgz#c48184721d0f0b7627a886e2ec42f1efb2be339d"
integrity sha512-+3/GPwOgcoF0xLz/opTnahel1/y42PdcgZ4hs+BZGIUjtmEFSXGg+nFoaH3NSmuc7a6GSFwXDJ5L7VXpqzigNg==
dependencies:
"@types/node" "*"
playwright-core "1.26.1"
playwright-core "1.29.2"
"@pmmmwh/react-refresh-webpack-plugin@^0.5.3":
version "0.5.9"
@ -11321,10 +11321,17 @@ pkg-dir@^5.0.0:
dependencies:
find-up "^5.0.0"
playwright-core@1.26.1:
version "1.26.1"
resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.26.1.tgz#a162f476488312dcf12638d97685144de6ada512"
integrity sha512-hzFchhhxnEiPc4qVPs9q2ZR+5eKNifY2hQDHtg1HnTTUuphYCBP8ZRb2si+B1TR7BHirgXaPi48LIye5SgrLAA==
playwright-core@1.29.2:
version "1.29.2"
resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.29.2.tgz#2e8347e7e8522409f22b244e600e703b64022406"
integrity sha512-94QXm4PMgFoHAhlCuoWyaBYKb92yOcGVHdQLoxQ7Wjlc7Flg4aC/jbFW7xMR52OfXMVkWicue4WXE7QEegbIRA==
playwright@^1.29.2:
version "1.29.2"
resolved "https://registry.yarnpkg.com/playwright/-/playwright-1.29.2.tgz#d6a0a3e8e44f023f7956ed19ffa8af915a042769"
integrity sha512-hKBYJUtdmYzcjdhYDkP9WGtORwwZBBKAW8+Lz7sr0ZMxtJr04ASXVzH5eBWtDkdb0c3LLFsehfPBTRfvlfKJOA==
dependencies:
playwright-core "1.29.2"
pluralize@^8.0.0:
version "8.0.0"