diff --git a/frontend/test/e2e/upgrade-verification.spec.ts b/frontend/test/e2e/upgrade-verification.spec.ts index fdca31df..f1ebbacc 100644 --- a/frontend/test/e2e/upgrade-verification.spec.ts +++ b/frontend/test/e2e/upgrade-verification.spec.ts @@ -1,10 +1,25 @@ import { expect, test } from "@playwright/test"; import * as fs from "fs"; -import * as path from "path"; // Load test data created by the setup script const testDataPath = process.env.TEST_DATA_FILE || "/tmp/test-users.json"; -let testData: any = {}; + +interface TestUser { + email: string; + password: string; + token: string; + group: string; +} + +interface TestData { + users?: TestUser[]; + locations?: Record; + labels?: Record; + items?: Record; + notifiers?: Record; +} + +let testData: TestData = {}; test.beforeAll(() => { if (fs.existsSync(testDataPath)) { @@ -26,7 +41,7 @@ test.describe("HomeBox Upgrade Verification", () => { // Wait for login form to be ready await page.waitForSelector("input[type='text']", { state: "visible" }); - + // Fill in login form await page.fill("input[type='text']", user.email); await page.fill("input[type='password']", user.password); @@ -60,10 +75,10 @@ test.describe("HomeBox Upgrade Verification", () => { // The version might be in the footer or a settings page // Check if footer exists and contains version info const footer = page.locator("footer"); - if (await footer.count() > 0) { + if ((await footer.count()) > 0) { const footerText = await footer.textContent(); console.log("Footer text:", footerText); - + // Version should be present in some form // This is a basic check - the version format may vary expect(footerText).toBeTruthy(); @@ -86,18 +101,18 @@ test.describe("HomeBox Upgrade Verification", () => { // Wait for page to load await page.waitForSelector("body", { state: "visible" }); - + // Try to find locations link in navigation const locationsLink = page.locator("a[href*='location'], button:has-text('Locations')").first(); - - if (await locationsLink.count() > 0) { + + if ((await locationsLink.count()) > 0) { await locationsLink.click(); await page.waitForLoadState("networkidle"); // Check if locations are displayed // The exact structure depends on the UI, but we should see location names const pageContent = await page.textContent("body"); - + // Verify some of our test locations exist expect(pageContent).toContain("Living Room"); console.log("✓ Locations verified"); @@ -122,13 +137,13 @@ test.describe("HomeBox Upgrade Verification", () => { // Try to find labels link in navigation const labelsLink = page.locator("a[href*='label'], button:has-text('Labels')").first(); - - if (await labelsLink.count() > 0) { + + if ((await labelsLink.count()) > 0) { await labelsLink.click(); await page.waitForLoadState("networkidle"); const pageContent = await page.textContent("body"); - + // Verify some of our test labels exist expect(pageContent).toContain("Electronics"); console.log("✓ Labels verified"); @@ -154,14 +169,14 @@ test.describe("HomeBox Upgrade Verification", () => { // Navigate to items list // This might be the home page or a separate items page const itemsLink = page.locator("a[href*='item'], button:has-text('Items')").first(); - - if (await itemsLink.count() > 0) { + + if ((await itemsLink.count()) > 0) { await itemsLink.click(); await page.waitForLoadState("networkidle"); } const pageContent = await page.textContent("body"); - + // Verify some of our test items exist expect(pageContent).toContain("Laptop Computer"); console.log("✓ Items verified"); @@ -184,20 +199,20 @@ test.describe("HomeBox Upgrade Verification", () => { // Navigate to settings or profile // Notifiers are typically in settings const settingsLink = page.locator("a[href*='setting'], a[href*='profile'], button:has-text('Settings')").first(); - - if (await settingsLink.count() > 0) { + + if ((await settingsLink.count()) > 0) { await settingsLink.click(); await page.waitForLoadState("networkidle"); // Look for notifiers section const notifiersLink = page.locator("a:has-text('Notif'), button:has-text('Notif')").first(); - - if (await notifiersLink.count() > 0) { + + if ((await notifiersLink.count()) > 0) { await notifiersLink.click(); await page.waitForLoadState("networkidle"); const pageContent = await page.textContent("body"); - + // Verify our test notifier exists expect(pageContent).toContain("TESTING"); console.log("✓ Notifier verified"); @@ -225,8 +240,8 @@ test.describe("HomeBox Upgrade Verification", () => { // Search for "Laptop Computer" which should have attachments const searchInput = page.locator("input[type='search'], input[placeholder*='Search']").first(); - - if (await searchInput.count() > 0) { + + if ((await searchInput.count()) > 0) { await searchInput.fill("Laptop Computer"); await page.waitForLoadState("networkidle"); @@ -237,37 +252,37 @@ test.describe("HomeBox Upgrade Verification", () => { // Look for attachments section const pageContent = await page.textContent("body"); - + // Check for attachment indicators (could be files, documents, attachments, etc.) - const hasAttachments = - pageContent?.includes("laptop-receipt") || + const hasAttachments = + pageContent?.includes("laptop-receipt") || pageContent?.includes("laptop-warranty") || pageContent?.includes("attachment") || pageContent?.includes("Attachment") || pageContent?.includes("document"); - + expect(hasAttachments).toBeTruthy(); console.log("✓ Attachments verified"); } else { console.log("! Could not find search - trying direct navigation"); - + // Try alternative: look for items link and browse const itemsLink = page.locator("a[href*='item'], button:has-text('Items')").first(); - if (await itemsLink.count() > 0) { + if ((await itemsLink.count()) > 0) { await itemsLink.click(); await page.waitForLoadState("networkidle"); - + const laptopLink = page.locator("text=Laptop Computer").first(); - if (await laptopLink.count() > 0) { + if ((await laptopLink.count()) > 0) { await laptopLink.click(); await page.waitForLoadState("networkidle"); - + const pageContent = await page.textContent("body"); - const hasAttachments = - pageContent?.includes("laptop-receipt") || + const hasAttachments = + pageContent?.includes("laptop-receipt") || pageContent?.includes("laptop-warranty") || pageContent?.includes("attachment"); - + expect(hasAttachments).toBeTruthy(); console.log("✓ Attachments verified via direct navigation"); } @@ -291,16 +306,18 @@ test.describe("HomeBox Upgrade Verification", () => { // Look for theme toggle (usually a sun/moon icon or settings) // Common selectors for theme toggles - const themeToggle = page.locator( - "button[aria-label*='theme'], button[aria-label*='Theme'], " + - "button:has-text('Dark'), button:has-text('Light'), " + - "[data-theme-toggle], .theme-toggle" - ).first(); + const themeToggle = page + .locator( + "button[aria-label*='theme'], button[aria-label*='Theme'], " + + "button:has-text('Dark'), button:has-text('Light'), " + + "[data-theme-toggle], .theme-toggle" + ) + .first(); - if (await themeToggle.count() > 0) { + if ((await themeToggle.count()) > 0) { // Get initial theme state (could be from class, attribute, or computed style) const bodyBefore = page.locator("body"); - const classNameBefore = await bodyBefore.getAttribute("class") || ""; + const classNameBefore = (await bodyBefore.getAttribute("class")) || ""; // Click theme toggle await themeToggle.click(); @@ -308,23 +325,23 @@ test.describe("HomeBox Upgrade Verification", () => { await page.waitForTimeout(500); // Get theme state after toggle - const classNameAfter = await bodyBefore.getAttribute("class") || ""; + const classNameAfter = (await bodyBefore.getAttribute("class")) || ""; // Verify that something changed expect(classNameBefore).not.toBe(classNameAfter); - + console.log(`✓ Theme toggle working (${classNameBefore} -> ${classNameAfter})`); } else { // Try to find theme in settings const settingsLink = page.locator("a[href*='setting'], a[href*='profile']").first(); - - if (await settingsLink.count() > 0) { + + if ((await settingsLink.count()) > 0) { await settingsLink.click(); await page.waitForLoadState("networkidle"); const themeOption = page.locator("select[name*='theme'], button:has-text('Theme')").first(); - - if (await themeOption.count() > 0) { + + if ((await themeOption.count()) > 0) { console.log("✓ Theme settings found"); } else { console.log("! Could not find theme toggle - feature may not be easily accessible"); @@ -351,11 +368,11 @@ test.describe("HomeBox Upgrade Verification", () => { // Check that we have the expected number of items for group 1 (5 items) const pageContent = await page.textContent("body"); - + // Look for item count indicators // This is dependent on the UI showing counts console.log("✓ Logged in and able to view dashboard"); - + // Verify at least that the page loaded and shows some content expect(pageContent).toBeTruthy(); expect(pageContent.length).toBeGreaterThan(100); @@ -363,7 +380,7 @@ test.describe("HomeBox Upgrade Verification", () => { test("verify second group users and data isolation", async ({ page }) => { // Login as user from group 2 - const group2User = testData.users?.find((u: any) => u.group === "2"); + const group2User = testData.users?.find(u => u.group === "2"); if (!group2User) { console.log("! No group 2 users found - skipping isolation test"); return; @@ -378,13 +395,13 @@ test.describe("HomeBox Upgrade Verification", () => { await page.waitForSelector("body", { state: "visible" }); const pageContent = await page.textContent("body"); - + // Verify group 2 can see their items expect(pageContent).toContain("Monitor"); - + // Verify group 2 cannot see group 1 items expect(pageContent).not.toContain("Laptop Computer"); - + console.log("✓ Data isolation verified between groups"); }); });