Skip to content

feat: Implement basic e2e scenario #7199

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

Closed
wants to merge 21 commits into from
Closed
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
Form is populated
  • Loading branch information
mtojek committed Apr 19, 2023
commit 497b024e0ff6fa46f5c554591cd9098f64bd1e5b
33 changes: 33 additions & 0 deletions site/e2e/pom/CreateTemplatePage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { expect, Locator, Page } from "@playwright/test"
import { BasePom } from "./BasePom"

export class CreateTemplatePage extends BasePom {
readonly createTemplateForm: Locator
readonly createTemplateButton: Locator

constructor(baseURL: string | undefined, page: Page) {
super(baseURL, `/templates`, page)

this.createTemplateForm = page.getByTestId("form-create-template")
this.createTemplateButton = page.getByTestId("button-create-template")
}

async loaded() {
await expect(this.page).toHaveTitle("Create Template - Coder")

await this.createTemplateForm.waitFor({ state: "visible" })
await this.createTemplateButton.waitFor({ state: "visible" })
}

async fillIn() {
await this.createTemplateForm.getByLabel("Name *").fill("my-first-template")
await this.createTemplateForm
.getByLabel("Display name")
.fill("My First Template")
await this.createTemplateForm
.getByLabel("Description")
.fill("This is my first template.")

await this.createTemplateButton.click()
}
}
26 changes: 26 additions & 0 deletions site/e2e/pom/TemplatesPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { expect, Locator, Page } from "@playwright/test"
import { BasePom } from "./BasePom"

export class TemplatesPage extends BasePom {
readonly addTemplateButton: Locator

constructor(baseURL: string | undefined, page: Page) {
super(baseURL, `/templates`, page)

this.addTemplateButton = page.getByTestId("button-add-template")
}

async goto() {
await this.page.goto(this.url, { waitUntil: "networkidle" })
}

async loaded() {
await expect(this.page).toHaveTitle("Templates - Coder")

await this.addTemplateButton.waitFor({ state: "visible" })
}

async addTemplate() {
await this.addTemplateButton.click()
}
}
25 changes: 25 additions & 0 deletions site/e2e/tests/basicScenario.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { test } from "@playwright/test"
import { getStatePath } from "../helpers"
import { TemplatesPage } from "../pom/TemplatesPage"
import { CreateTemplatePage } from "../pom/CreateTemplatePage"

test.use({ storageState: getStatePath("authState") })

test("Basic scenario", async ({ page, baseURL }) => {
const templatesPage = new TemplatesPage(baseURL, page)
const createTemplatePage = new CreateTemplatePage(baseURL, page)

await test.step("Load empty templates page", async () => {
await templatesPage.goto()
await templatesPage.loaded()
})

await test.step("Upload a template", async () => {
await templatesPage.addTemplate()
await createTemplatePage.loaded()

await createTemplatePage.fillIn()

await page.waitForTimeout(5 * 60 * 1000) // FIXME
})
})
9 changes: 0 additions & 9 deletions site/e2e/tests/listTemplates.spec.ts

This file was deleted.

3 changes: 3 additions & 0 deletions site/src/components/FormFooter/FormFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ export interface FormFooterProps {
styles?: FormFooterStyles
submitLabel?: string
submitDisabled?: boolean
submitTestId?: string
}

export const FormFooter: FC<FormFooterProps> = ({
onCancel,
isLoading,
submitDisabled,
submitLabel = Language.defaultSubmitLabel,
submitTestId,
styles = defaultStyles(),
}) => {
return (
Expand All @@ -35,6 +37,7 @@ export const FormFooter: FC<FormFooterProps> = ({
color="primary"
type="submit"
disabled={submitDisabled}
data-testid={submitTestId}
>
{submitLabel}
</LoadingButton>
Expand Down
6 changes: 5 additions & 1 deletion site/src/pages/CreateTemplatePage/CreateTemplateForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,10 @@ export const CreateTemplateForm: FC<CreateTemplateFormProps> = ({
const { t: commonT } = useTranslation("common")

return (
<HorizontalForm onSubmit={form.handleSubmit}>
<HorizontalForm
onSubmit={form.handleSubmit}
data-testid="form-create-template"
>
{/* General info */}
<FormSection
title={t("form.generalInfo.title")}
Expand Down Expand Up @@ -505,6 +508,7 @@ export const CreateTemplateForm: FC<CreateTemplateFormProps> = ({
onCancel={onCancel}
isLoading={isSubmitting}
submitLabel={jobError ? "Retry" : "Create template"}
submitTestId="button-create-template"
/>
</HorizontalForm>
)
Expand Down
7 changes: 6 additions & 1 deletion site/src/pages/TemplatesPage/TemplatesPageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,12 @@ export const TemplatesPageView: FC<
>
Starter templates
</Button>
<Button startIcon={<AddIcon />} component={RouterLink} to="new">
<Button
startIcon={<AddIcon />}
component={RouterLink}
to="new"
data-testid="button-add-template"
>
Add template
</Button>
</Maybe>
Expand Down