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
Prev Previous commit
Next Next commit
Scenario covered
  • Loading branch information
mtojek committed Apr 20, 2023
commit ee59c2a87cec7383c7d9051557dbcae84fb4ae9d
2 changes: 1 addition & 1 deletion site/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const config: PlaywrightTestConfig = {
port,
reuseExistingServer: false,
},
timeout: 120 * 1000,
timeout: 5 * 60 * 1000,
}

export default config
49 changes: 42 additions & 7 deletions site/e2e/pom/WorkspacePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,81 @@ import { expect, Locator, Page } from "@playwright/test"
import { BasePom } from "./BasePom"

export class WorkspacePage extends BasePom {
readonly workspaceOptionsButton: Locator
readonly deleteWorkspaceMenuItem: Locator
readonly stopWorkspaceButton: Locator

readonly workspaceRunningBadge: Locator
readonly workspaceStoppedBadge: Locator
readonly workspaceDeletedBadge: Locator

readonly terminalButton: Locator
readonly agentVersion: Locator
readonly agentLifecycleReady: Locator
readonly stopWorkspaceButton: Locator

readonly deleteDialogConfirmation: Locator
readonly deleteDialogConfirm: Locator

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

this.workspaceOptionsButton = page.getByTestId("workspace-options-button")
this.deleteWorkspaceMenuItem = page.getByTestId("menuitem-delete-workspace")
this.stopWorkspaceButton = page.getByTestId("button-stop-workspace")

this.workspaceRunningBadge = page.getByTestId(
"badge-workspace-status-running",
)
this.workspaceStoppedBadge = page.getByTestId(
"badge-workspace-status-stopped",
)
this.workspaceDeletedBadge = page.getByTestId(
"badge-workspace-status-deleted",
)
this.terminalButton = page.getByTestId("button-terminal")
this.agentVersion = page.getByTestId("agent-version")
this.agentLifecycleReady = page.getByTestId("agent-lifecycle-ready")
this.stopWorkspaceButton = page.getByTestId("button-stop-workspace")

this.deleteDialogConfirmation = page.getByTestId(
"delete-dialog-confirmation",
)
this.deleteDialogConfirm = page.getByTestId("delete-dialog-confirm")
}

async loaded() {
await this.stopWorkspaceButton.waitFor({ state: "visible" })
await expect(this.page).toHaveTitle("admin/my-first-workspace - Coder")
}

async stop() {
await this.stopWorkspaceButton.click()
}

async delete() {
await this.workspaceOptionsButton.click()
await this.deleteWorkspaceMenuItem.click()

await this.deleteDialogConfirmation.waitFor({ state: "visible" })
await this.deleteDialogConfirmation
.getByLabel("Name of workspace to delete")
.fill("my-first-workspace")

await this.page.waitForTimeout(1000) // Wait for 1s to snapshot the delete dialog before submitting
await this.deleteDialogConfirm.click()
}

async isRunning() {
await this.workspaceRunningBadge.waitFor({ state: "visible" })
await this.terminalButton.waitFor({ state: "visible" })
await this.agentVersion.waitFor({ state: "visible" })
await this.agentLifecycleReady.waitFor({ state: "visible" })
await this.page.waitForTimeout(1000) // Wait for 1s to snapshot the agent status on the video
}

async stop() {
await this.stopWorkspaceButton.click()
}

async isStopped() {
await this.workspaceStoppedBadge.waitFor({ state: "visible" })
}

async isDeleted() {
await this.workspaceDeletedBadge.waitFor({ state: "visible" })
}
}
13 changes: 5 additions & 8 deletions site/e2e/tests/basicScenario.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,18 @@ test("Basic scenario", async ({ page, baseURL }) => {

await createWorkspacePage.submitForm()
await workspacePage.loaded()
})

await test.step("Workspace is up and running", async () => {
await workspacePage.isRunning()
await page.waitForTimeout(1000) // Wait for 1s to snapshot the agent status on the video
})

await test.step("Stop the workspace", async () => {
await workspacePage.stop()
})

await test.step("Workspace is stopped", async () => {
await workspacePage.isStopped()
})

await test.step("Finally", async () => {
await page.waitForTimeout(5 * 60 * 1000) // FIXME
await test.step("Delete the workspace", async () => {
await workspacePage.delete()
await workspacePage.isDeleted()
await page.waitForTimeout(1000) // Wait to show the deleted workspace
})
})
1 change: 1 addition & 0 deletions site/src/components/Dialogs/DeleteDialog/DeleteDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const DeleteDialog: FC<PropsWithChildren<DeleteDialogProps>> = ({
label={t("deleteDialog.confirmLabel", { entity })}
error={hasError}
helperText={hasError && t("deleteDialog.incorrectName", { entity })}
data-testid="delete-dialog-confirmation"
/>
</>
)
Expand Down
1 change: 1 addition & 0 deletions site/src/components/Dialogs/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const DialogActionButtons: React.FC<DialogActionButtonsProps> = ({
[styles.errorButton]: type === "delete",
[styles.successButton]: type === "success",
})}
data-testid={type + "-dialog-confirm"}
>
{confirmText}
</LoadingButton>
Expand Down
5 changes: 4 additions & 1 deletion site/src/components/WorkspaceActions/WorkspaceActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ export const WorkspaceActions: FC<WorkspaceActionsProps> = ({
Change version
</MenuItem>
)}
<MenuItem onClick={onMenuItemClick(handleDelete)}>
<MenuItem
onClick={onMenuItemClick(handleDelete)}
data-testid="menuitem-delete-workspace"
>
<DeleteOutlined />
Delete
</MenuItem>
Expand Down