-
-
Notifications
You must be signed in to change notification settings - Fork 170
Expand file tree
/
Copy pathsettings.spec.ts
More file actions
64 lines (48 loc) · 2.44 KB
/
settings.spec.ts
File metadata and controls
64 lines (48 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { test, expect } from "@playwright/test";
import { loggedInAsUserOne } from "./utils";
test.describe("Unauthenticated setttings Page", () => {
//
// Replace with tests for unauthenticated users
});
test.describe("Authenticated settings Page", () => {
test.beforeEach(async ({ page }) => {
await loggedInAsUserOne(page);
});
// Test for changing username
test('Username input field', async ({ page }) => {
await page.goto('http://localhost:3000/settings', { timeout: 30000 });
// Wait for the username input field to be visible
await page.locator('input[id="username"]').waitFor();
// Test that the input field is visible and has the correct attributes
const inputField = page.locator('input[id="username"]');
await expect(inputField).toBeVisible();
await expect(inputField).toHaveAttribute('type', 'text');
await expect(inputField).toHaveAttribute('autocomplete', 'username');
// Test that the error message appears when the input field is invalid
await inputField.fill('45&p^x#@!96%*()');
await page.locator('button[type="submit"]').click();
const errorMessage = page.locator('p:text-is("Username can only contain alphanumerics and dashes.")')
await expect(errorMessage).toBeVisible();
await expect(errorMessage).toHaveText('Username can only contain alphanumerics and dashes.');
// Reset the form
await page.locator('button:has-text("Reset")').click();
// Test that the input field can be filled with a valid value and saves it
await inputField.fill('codu-rules');
await page.locator('button[type="submit"]').click();
await expect(inputField).toHaveValue('codu-rules');
});
// Tests location input, autocomplete, and saved values
test('location input is visible', async ({page}) => {
// Test to see if input is visible
await page.locator('#location').isVisible();
// Test to fill if value can be changed
await page.locator('#location').fill('New York');
await expect(page.locator('#location')).toHaveValue('New York');
// Test to see if autocomplete is working
await expect(page.locator('#location')).toHaveAttribute('autocomplete', 'country-name');
// Test to see if change in location persits
await page.locator('#location').fill('A fun place to visit.');
await page.locator('button[type="submit"]').click();
await expect(page.locator('#location')).toHaveValue('A fun place to visit.');
});
});