Skip to content

Commit aae70a0

Browse files
committed
chore(site): add e2e to test add and remove user
1 parent 7698cfd commit aae70a0

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

site/e2e/tests/manageUsers.spec.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { test, expect } from "@playwright/test";
2+
import { beforeCoderTest } from "../hooks";
3+
4+
test.beforeEach(async ({ page }) => await beforeCoderTest(page));
5+
6+
test("manage users", async ({ page, baseURL }) => {
7+
await page.goto(`${baseURL}/users`, { waitUntil: "domcontentloaded" });
8+
await expect(page).toHaveTitle("Users - Coder");
9+
10+
await page.getByRole("button", { name: "Create user" }).click();
11+
await expect(page).toHaveTitle("Create User - Coder");
12+
13+
const userValues = {
14+
username: "testuser",
15+
email: "testuser@coder.com",
16+
loginType: "password",
17+
password: "s3cure&password!",
18+
};
19+
await page.getByLabel("Username").fill(userValues.username);
20+
await page.getByLabel("Email").fill(userValues.email);
21+
await page.getByLabel("Login Type").click();
22+
await page.getByRole("option", { name: "Password", exact: false }).click();
23+
// Using input[name=password] due to the select element utilizing 'password'
24+
// as the label for the currently active option.
25+
const passwordField = page.locator("input[name=password]");
26+
await passwordField.fill(userValues.password);
27+
await page.getByRole("button", { name: "Create user" }).click();
28+
await expect(page.getByText("Successfully created user.")).toBeVisible();
29+
30+
const userRow = page.locator("tr", { hasText: userValues.email });
31+
await userRow.getByRole("button", { name: "More options" }).click();
32+
await page.getByText("Delete", { exact: false }).click();
33+
await page.getByLabel("Name of the user to delete").fill(userValues.username);
34+
await page.getByRole("button", { name: "Delete" }).click();
35+
await expect(page.getByText("Successfully deleted the user.")).toBeVisible();
36+
});

site/src/pages/CreateUserPage/CreateUserForm.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,11 @@ export const CreateUserForm: FC<
193193
type="password"
194194
/>
195195
</Stack>
196-
<FormFooter onCancel={onCancel} isLoading={isLoading} />
196+
<FormFooter
197+
submitLabel="Create user"
198+
onCancel={onCancel}
199+
isLoading={isLoading}
200+
/>
197201
</form>
198202
</FullPageForm>
199203
);

site/src/pages/CreateUserPage/CreateUserPage.test.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { fireEvent, screen } from "@testing-library/react";
22
import userEvent from "@testing-library/user-event";
3-
import { Language as FooterLanguage } from "components/FormFooter/FormFooter";
43
import {
54
renderWithAuth,
65
waitForLoaderToBeRemoved,
@@ -35,9 +34,7 @@ const fillForm = async ({
3534
await userEvent.type(emailField, email);
3635
await userEvent.type(loginTypeField, "password");
3736
await userEvent.type(passwordField as HTMLElement, password);
38-
const submitButton = await screen.findByText(
39-
FooterLanguage.defaultSubmitLabel,
40-
);
37+
const submitButton = await screen.findByText("Create user");
4138
fireEvent.click(submitButton);
4239
};
4340

0 commit comments

Comments
 (0)