Skip to content

Commit 4699c2b

Browse files
committed
fix: fixed typo and added test for max length on location input.
1 parent ed62c79 commit 4699c2b

File tree

1 file changed

+45
-32
lines changed

1 file changed

+45
-32
lines changed

e2e/settings.spec.ts

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,55 +10,68 @@ 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-
15+
test("Username input field", async ({ page }) => {
16+
await page.goto("http://localhost:3000/settings");
17+
1818
// Wait for the username input field to be visible
1919
await page.locator('input[id="username"]').waitFor();
20-
20+
2121
// Test that the input field is visible and has the correct attributes
2222
const inputField = page.locator('input[id="username"]');
2323
await expect(inputField).toBeVisible();
24-
await expect(inputField).toHaveAttribute('type', 'text');
25-
await expect(inputField).toHaveAttribute('autocomplete', 'username');
26-
24+
await expect(inputField).toHaveAttribute("type", "text");
25+
await expect(inputField).toHaveAttribute("autocomplete", "username");
26+
2727
// 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.")')
28+
await inputField.fill("45&p^x#@!96%*()");
29+
await page.locator('button[type="submit"]').click();
30+
const errorMessage = page.locator(
31+
'p:text-is("Username can only contain alphanumerics and dashes.")',
32+
);
3133
await expect(errorMessage).toBeVisible();
32-
await expect(errorMessage).toHaveText('Username can only contain alphanumerics and dashes.');
33-
// Reset the form
34+
await expect(errorMessage).toHaveText(
35+
"Username can only contain alphanumerics and dashes.",
36+
);
37+
// Reset the form
3438
await page.locator('button:has-text("Reset")').click();
35-
39+
3640
// 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-
await expect(inputField).toHaveValue('codu-rules');
41+
await inputField.fill("codu-rules");
42+
await page.locator('button[type="submit"]').click();
43+
await expect(inputField).toHaveValue("codu-rules");
4044
});
4145

42-
// Tests location input, autocomplete, and saved values
43-
test('location input is visible', async ({page}) => {
46+
// Tests location input, autocomplete, and saved values
47+
test("location input is visible", async ({ page }) => {
48+
await page.goto("http://localhost:3000/settings");
49+
4450
// Test to see if input is visible
45-
await page.locator('#location').isVisible();
51+
await page.locator('input[id="location"]').isVisible();
4652

4753
// Test to fill if value can be changed
48-
await page.locator('#location').fill('New York');
49-
await expect(page.locator('#location')).toHaveValue('New York');
54+
await page.fill('input[id="location"]', "New York");
55+
await expect(page.locator('input[id="location"]')).toHaveValue("New York");
5056

5157
// Test to see if autocomplete is working
52-
await expect(page.locator('#location')).toHaveAttribute('autocomplete', 'country-name');
53-
54-
// Test to see if change in location persits
55-
await page.locator('#location').fill('A fun place to visit.');
58+
await expect(page.locator('input[id="location"]')).toHaveAttribute(
59+
"autocomplete",
60+
"country-name",
61+
);
62+
63+
// Add validation tests for location
64+
await page.locator('input[id="location"]').fill("a".repeat(101));
65+
await page.locator('button[type="submit"]').click();
66+
await expect(
67+
page.getByText("Max location length is 100 characters."),
68+
).toBeVisible();
69+
70+
// Test to see if change in location persists after submit and page reload
71+
await page.fill('input[id="location"]', "A fun place to visit.");
5672
await page.locator('button[type="submit"]').click();
57-
await expect(page.locator('#location')).toHaveValue('A fun place to visit.');
73+
await expect(page.locator('input[id="location"]')).toHaveValue(
74+
"A fun place to visit.",
75+
);
5876
});
59-
60-
61-
62-
63-
6477
});

0 commit comments

Comments
 (0)