merged tests
This commit is contained in:
parent
4be45f8f7c
commit
67ffe6a823
7 changed files with 212 additions and 599 deletions
|
|
@ -75,65 +75,39 @@ test.describe("Profile - Regular User Access", () => {
|
|||
await loginUser(page, REGULAR_USER.email, REGULAR_USER.password);
|
||||
});
|
||||
|
||||
test("can navigate to profile page from exchange", async ({ page }) => {
|
||||
test("can navigate to profile page and page displays correct elements", async ({ page }) => {
|
||||
// Test navigation from exchange
|
||||
await page.goto("/exchange");
|
||||
|
||||
// Should see My Profile link
|
||||
await expect(page.getByText("My Profile")).toBeVisible();
|
||||
|
||||
// Click to navigate
|
||||
await page.click('a[href="/profile"]');
|
||||
await expect(page).toHaveURL("/profile");
|
||||
});
|
||||
|
||||
test("can navigate to profile page from trades", async ({ page }) => {
|
||||
// Test navigation from trades
|
||||
await page.goto("/trades");
|
||||
|
||||
// Should see My Profile link
|
||||
await expect(page.getByText("My Profile")).toBeVisible();
|
||||
|
||||
// Click to navigate
|
||||
await page.click('a[href="/profile"]');
|
||||
await expect(page).toHaveURL("/profile");
|
||||
});
|
||||
|
||||
test("profile page displays correct elements", async ({ page }) => {
|
||||
await page.goto("/profile");
|
||||
|
||||
// Should see page title
|
||||
// Test page structure
|
||||
await expect(page.getByRole("heading", { name: "My Profile" })).toBeVisible();
|
||||
|
||||
// Should see login email label with read-only badge
|
||||
await expect(page.getByText("Login EmailRead only")).toBeVisible();
|
||||
|
||||
// Should see contact details section
|
||||
await expect(page.getByText("Contact Details")).toBeVisible();
|
||||
await expect(page.getByText(/communication purposes only/i)).toBeVisible();
|
||||
|
||||
// Should see all form fields
|
||||
// Test form fields visibility
|
||||
await expect(page.getByLabel("Contact Email")).toBeVisible();
|
||||
await expect(page.getByLabel("Telegram")).toBeVisible();
|
||||
await expect(page.getByLabel("Signal")).toBeVisible();
|
||||
await expect(page.getByLabel("Nostr (npub)")).toBeVisible();
|
||||
});
|
||||
|
||||
test("login email is displayed and read-only", async ({ page }) => {
|
||||
await page.goto("/profile");
|
||||
|
||||
// Login email should show the user's email
|
||||
// Test login email is read-only
|
||||
const loginEmailInput = page.locator('input[type="email"][disabled]');
|
||||
await expect(loginEmailInput).toHaveValue(REGULAR_USER.email);
|
||||
await expect(loginEmailInput).toBeDisabled();
|
||||
});
|
||||
|
||||
test("navigation shows Exchange, My Trades, and My Profile", async ({ page }) => {
|
||||
await page.goto("/profile");
|
||||
|
||||
// Should see all nav items (Exchange and My Trades as links)
|
||||
// Test navigation links
|
||||
await expect(page.locator('a[href="/exchange"]')).toBeVisible();
|
||||
await expect(page.locator('a[href="/trades"]')).toBeVisible();
|
||||
// My Profile is the page title (h1) since we're on this page
|
||||
await expect(page.getByRole("heading", { name: "My Profile" })).toBeVisible();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -145,7 +119,7 @@ test.describe("Profile - Form Behavior", () => {
|
|||
await clearProfileData(page);
|
||||
});
|
||||
|
||||
test("new user has empty profile fields", async ({ page }) => {
|
||||
test("form state management - empty fields, button states", async ({ page }) => {
|
||||
await page.goto("/profile");
|
||||
|
||||
// All editable fields should be empty
|
||||
|
|
@ -153,28 +127,17 @@ test.describe("Profile - Form Behavior", () => {
|
|||
await expect(page.getByLabel("Telegram")).toHaveValue("");
|
||||
await expect(page.getByLabel("Signal")).toHaveValue("");
|
||||
await expect(page.getByLabel("Nostr (npub)")).toHaveValue("");
|
||||
});
|
||||
|
||||
test("save button is disabled when no changes", async ({ page }) => {
|
||||
await page.goto("/profile");
|
||||
|
||||
// Save button should be disabled
|
||||
// Save button should be disabled when no changes
|
||||
const saveButton = page.getByRole("button", { name: /save changes/i });
|
||||
await expect(saveButton).toBeDisabled();
|
||||
});
|
||||
|
||||
test("save button is enabled after making changes", async ({ page }) => {
|
||||
await page.goto("/profile");
|
||||
|
||||
// Make a change
|
||||
// Make a change - button should be enabled
|
||||
await page.fill("#telegram", "@testhandle");
|
||||
|
||||
// Save button should be enabled
|
||||
const saveButton = page.getByRole("button", { name: /save changes/i });
|
||||
await expect(saveButton).toBeEnabled();
|
||||
});
|
||||
|
||||
test("can save profile and values persist", async ({ page }) => {
|
||||
test("can save profile, values persist, and can clear fields", async ({ page }) => {
|
||||
await page.goto("/profile");
|
||||
|
||||
// Fill in all fields
|
||||
|
|
@ -185,28 +148,19 @@ test.describe("Profile - Form Behavior", () => {
|
|||
|
||||
// Save
|
||||
await page.click('button:has-text("Save Changes")');
|
||||
|
||||
// Should see success message
|
||||
await expect(page.getByText(/saved successfully/i)).toBeVisible();
|
||||
|
||||
// Reload and verify values persist
|
||||
await page.reload();
|
||||
|
||||
await expect(page.getByLabel("Contact Email")).toHaveValue("contact@test.com");
|
||||
await expect(page.getByLabel("Telegram")).toHaveValue("@testuser");
|
||||
await expect(page.getByLabel("Signal")).toHaveValue("signal.42");
|
||||
await expect(page.getByLabel("Nostr (npub)")).toHaveValue(VALID_NPUB);
|
||||
});
|
||||
|
||||
test("can clear a field and save", async ({ page }) => {
|
||||
await page.goto("/profile");
|
||||
|
||||
// First set a value
|
||||
// Test clearing a field
|
||||
await page.fill("#telegram", "@initial");
|
||||
await page.click('button:has-text("Save Changes")');
|
||||
await expect(page.getByText(/saved successfully/i)).toBeVisible();
|
||||
|
||||
// Wait for toast to disappear
|
||||
await expect(page.getByText(/saved successfully/i)).not.toBeVisible({ timeout: 5000 });
|
||||
|
||||
// Clear the field
|
||||
|
|
@ -227,44 +181,23 @@ test.describe("Profile - Validation", () => {
|
|||
await clearProfileData(page);
|
||||
});
|
||||
|
||||
test("auto-prepends @ for telegram when starting with letter", async ({ page }) => {
|
||||
test("validation - telegram auto-prepend, errors for invalid inputs", async ({ page }) => {
|
||||
await page.goto("/profile");
|
||||
|
||||
// Type a letter without @ - should auto-prepend @
|
||||
// Test telegram auto-prepend
|
||||
await page.fill("#telegram", "testhandle");
|
||||
|
||||
// Should show @testhandle in the input
|
||||
await expect(page.locator("#telegram")).toHaveValue("@testhandle");
|
||||
});
|
||||
|
||||
test("shows error for telegram handle with no characters after @", async ({ page }) => {
|
||||
await page.goto("/profile");
|
||||
|
||||
// Enter telegram with @ but nothing after (needs at least 1 char)
|
||||
// Test telegram error - no characters after @
|
||||
await page.fill("#telegram", "@");
|
||||
|
||||
// Wait for debounced validation
|
||||
await page.waitForTimeout(600);
|
||||
|
||||
// Should show error about needing at least one character
|
||||
await expect(page.getByText(/at least one character after @/i)).toBeVisible();
|
||||
|
||||
// Save button should be disabled
|
||||
const saveButton = page.getByRole("button", { name: /save changes/i });
|
||||
await expect(saveButton).toBeDisabled();
|
||||
});
|
||||
|
||||
test("shows error for invalid npub", async ({ page }) => {
|
||||
await page.goto("/profile");
|
||||
|
||||
// Enter invalid npub
|
||||
// Test invalid npub
|
||||
await page.fill("#nostr_npub", "invalidnpub");
|
||||
|
||||
// Should show error
|
||||
await expect(page.getByText(/must start with 'npub1'/i)).toBeVisible();
|
||||
|
||||
// Save button should be disabled
|
||||
const saveButton = page.getByRole("button", { name: /save changes/i });
|
||||
await expect(saveButton).toBeDisabled();
|
||||
});
|
||||
|
||||
|
|
@ -313,35 +246,26 @@ test.describe("Profile - Admin User Access", () => {
|
|||
await loginUser(page, ADMIN_USER.email, ADMIN_USER.password);
|
||||
});
|
||||
|
||||
test("admin does not see My Profile link", async ({ page }) => {
|
||||
test("admin cannot access profile page or API", async ({ page, request }) => {
|
||||
// Admin should not see profile link
|
||||
await page.goto("/admin/trades");
|
||||
|
||||
// Should be on admin trades page
|
||||
await expect(page).toHaveURL("/admin/trades");
|
||||
|
||||
// Should NOT see My Profile link
|
||||
await expect(page.locator('a[href="/profile"]')).toHaveCount(0);
|
||||
});
|
||||
|
||||
test("admin cannot access profile page - redirected to admin trades", async ({ page }) => {
|
||||
// Admin should be redirected when accessing profile page
|
||||
await page.goto("/profile");
|
||||
|
||||
// Should be redirected to admin trades
|
||||
await expect(page).toHaveURL("/admin/trades");
|
||||
});
|
||||
|
||||
test("admin API call to profile returns 403", async ({ page, request }) => {
|
||||
// Admin API call should return 403
|
||||
const cookies = await page.context().cookies();
|
||||
const authCookie = cookies.find((c) => c.name === "auth_token");
|
||||
|
||||
if (authCookie) {
|
||||
// Try to call profile API directly
|
||||
const response = await request.get(`${API_URL}/api/profile`, {
|
||||
headers: {
|
||||
Cookie: `auth_token=${authCookie.value}`,
|
||||
},
|
||||
});
|
||||
|
||||
expect(response.status()).toBe(403);
|
||||
}
|
||||
});
|
||||
|
|
@ -352,12 +276,12 @@ test.describe("Profile - Unauthenticated Access", () => {
|
|||
await clearAuth(page);
|
||||
});
|
||||
|
||||
test("profile page redirects to login", async ({ page }) => {
|
||||
test("profile page and API require authentication", async ({ page, request }) => {
|
||||
// Page redirects to login
|
||||
await page.goto("/profile");
|
||||
await expect(page).toHaveURL("/login");
|
||||
});
|
||||
|
||||
test("profile API requires authentication", async ({ page: _page, request }) => {
|
||||
// API requires authentication
|
||||
const response = await request.get(`${API_URL}/api/profile`);
|
||||
expect(response.status()).toBe(401);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue