Skip to content

Commit fcd1dbb

Browse files
committed
fix: added tests for min and max username values and error messages.
1 parent f9140cf commit fcd1dbb

File tree

1 file changed

+39
-21
lines changed

1 file changed

+39
-21
lines changed

e2e/settings.spec.ts

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,56 @@ test.describe("Authenticated settings Page", () => {
1010
test.beforeEach(async ({ page }) => {
1111
await loggedInAsUserOne(page);
1212
});
13-
13+
1414
// Test for changing username
15-
test('Username input field', async ({ page }) => {
16-
await page.goto('http://localhost:3000/settings', { timeout: 30000 });
17-
18-
// Wait for the username input field to be visible
19-
await page.locator('input[id="username"]').waitFor();
20-
21-
// Test that the input field is visible and has the correct attributes
15+
test("Username input field", async ({ page }) => {
16+
await page.goto("http://localhost:3000/settings", { timeout: 30000 });
17+
2218
const inputField = page.locator('input[id="username"]');
19+
const submitButton = page.locator('button[type="submit"]');
20+
21+
// Test that the input field is visible and has the correct attributes
2322
await expect(inputField).toBeVisible();
24-
await expect(inputField).toHaveAttribute('type', 'text');
25-
await expect(inputField).toHaveAttribute('autocomplete', 'username');
26-
23+
await expect(inputField).toHaveAttribute("type", "text");
24+
await expect(inputField).toHaveAttribute("autocomplete", "username");
25+
2726
// Test that the error message appears when the input field is invalid
28-
await inputField.fill('45&p^x#@!96%*()');
29-
await page.locator('button[type="submit"]').click();
30-
const errorMessage = page.locator('p:text-is("Username can only contain alphanumerics and dashes.")')
27+
await inputField.fill("45&p^x#@!96%*()");
28+
await submitButton.click();
29+
const errorMessage = page.locator(
30+
'p:text-is("Username can only contain alphanumerics and dashes.")',
31+
);
3132
await expect(errorMessage).toBeVisible();
32-
await expect(errorMessage).toHaveText('Username can only contain alphanumerics and dashes.');
33-
// Reset the form
33+
await expect(errorMessage).toHaveText(
34+
"Username can only contain alphanumerics and dashes.",
35+
);
36+
37+
// Test minimum length
38+
await inputField.fill("ab");
39+
await submitButton.click();
40+
await expect(
41+
page.locator('p:text-is("String must contain at least 3 character(s)")'),
42+
).toBeVisible();
43+
44+
// Test maximum length
45+
await inputField.fill("a".repeat(51));
46+
await submitButton.click();
47+
await expect(
48+
page.locator('p:text-is("Max username length is 40 characters.")'),
49+
).toBeVisible();
50+
51+
// Reset the form
3452
await page.locator('button:has-text("Reset")').click();
35-
53+
3654
// Test that the input field can be filled with a valid value and saves it
37-
await inputField.fill('codu-rules');
38-
await page.locator('button[type="submit"]').click();
39-
const toastError = page.locator('.toast-success');
55+
await inputField.fill("codu-rules");
56+
await page.locator('button[type="submit"]').click();
57+
const toastError = page.locator(".toast-success");
4058
await expect(toastError).toBeVisible();
4159
await expect(toastError).toBeHidden();
4260

4361
// Reload the page and check that the input field has the correct value
4462
await page.reload();
45-
await expect(inputField).toHaveValue('codu-rules');
63+
await expect(inputField).toHaveValue("codu-rules");
4664
});
4765
});

0 commit comments

Comments
 (0)