|
| 1 | +import { test, expect } from "@playwright/test"; |
| 2 | +import { |
| 3 | + ConsoleErrorCollector, |
| 4 | + navigateTo, |
| 5 | + waitForNoSpinners, |
| 6 | +} from "./helpers"; |
| 7 | + |
| 8 | +test.describe("Review page", () => { |
| 9 | + const consoleErrors = new ConsoleErrorCollector(); |
| 10 | + |
| 11 | + test.beforeEach(async ({ page }) => { |
| 12 | + consoleErrors.reset(); |
| 13 | + consoleErrors.attach(page); |
| 14 | + await navigateTo(page, "/review"); |
| 15 | + await waitForNoSpinners(page); |
| 16 | + }); |
| 17 | + |
| 18 | + test.afterEach(() => { |
| 19 | + consoleErrors.assertNoErrors(); |
| 20 | + }); |
| 21 | + |
| 22 | + // ─── Page header ────────────────────────────────────────────────────── |
| 23 | + |
| 24 | + test("Review heading is visible", async ({ page }) => { |
| 25 | + await expect( |
| 26 | + page.locator("h1", { hasText: "Review" }) |
| 27 | + ).toBeVisible(); |
| 28 | + }); |
| 29 | + |
| 30 | + // ─── Repository picker ──────────────────────────────────────────────── |
| 31 | + |
| 32 | + test("Select repository button exists", async ({ page }) => { |
| 33 | + const repoButton = page.locator("button", { |
| 34 | + hasText: "Select repository...", |
| 35 | + }); |
| 36 | + await expect(repoButton).toBeVisible(); |
| 37 | + }); |
| 38 | + |
| 39 | + // ─── Right panel placeholder ────────────────────────────────────────── |
| 40 | + |
| 41 | + test("Right panel shows placeholder when no review is active", async ({ |
| 42 | + page, |
| 43 | + }) => { |
| 44 | + // When no review is active, the right panel shows a placeholder message |
| 45 | + await expect( |
| 46 | + page.locator("text=Select a branch and run a review") |
| 47 | + ).toBeVisible(); |
| 48 | + }); |
| 49 | + |
| 50 | + // ─── Past Reviews section ───────────────────────────────────────────── |
| 51 | + |
| 52 | + test("Past Reviews section appears if reviews exist", async ({ page }) => { |
| 53 | + // Without Tauri IPC, past reviews won't load. The section only renders |
| 54 | + // when pastReviews.length > 0, so either the section is visible or |
| 55 | + // it isn't — both are valid states depending on the environment. |
| 56 | + const pastReviewsToggle = page.locator("button", { |
| 57 | + hasText: /Past Reviews/, |
| 58 | + }); |
| 59 | + const hasSection = (await pastReviewsToggle.count()) > 0; |
| 60 | + |
| 61 | + if (hasSection) { |
| 62 | + await expect(pastReviewsToggle).toBeVisible(); |
| 63 | + } |
| 64 | + // If no past reviews, the section won't render — that's expected |
| 65 | + }); |
| 66 | + |
| 67 | + // ─── Past review click → findings render ────────────────────────────── |
| 68 | + |
| 69 | + test("Clicking a past review shows findings with severity badges", async ({ |
| 70 | + page, |
| 71 | + }) => { |
| 72 | + // This test only runs meaningfully when past reviews are loaded. |
| 73 | + // Without Tauri, we verify the appropriate fallback state. |
| 74 | + const pastReviewsToggle = page.locator("button", { |
| 75 | + hasText: /Past Reviews/, |
| 76 | + }); |
| 77 | + const hasSection = (await pastReviewsToggle.count()) > 0; |
| 78 | + |
| 79 | + if (!hasSection) { |
| 80 | + // No past reviews — verify the placeholder is still showing |
| 81 | + await expect( |
| 82 | + page.locator("text=Select a branch and run a review") |
| 83 | + ).toBeVisible(); |
| 84 | + return; |
| 85 | + } |
| 86 | + |
| 87 | + // Ensure the section is expanded |
| 88 | + await pastReviewsToggle.click(); |
| 89 | + await page.waitForTimeout(300); |
| 90 | + |
| 91 | + // Click the first past review entry |
| 92 | + const firstReview = page |
| 93 | + .locator("button") |
| 94 | + .filter({ has: page.locator("text=/findings/") }) |
| 95 | + .first(); |
| 96 | + const reviewExists = (await firstReview.count()) > 0; |
| 97 | + |
| 98 | + if (!reviewExists) return; |
| 99 | + |
| 100 | + await firstReview.click(); |
| 101 | + await waitForNoSpinners(page, 10_000); |
| 102 | + |
| 103 | + // After clicking a past review, the right panel should show results. |
| 104 | + // Look for "Review Results" heading or severity badges. |
| 105 | + const hasResults = |
| 106 | + (await page.locator("h2", { hasText: "Review Results" }).count()) > 0; |
| 107 | + const hasCleanReview = |
| 108 | + (await page.locator("text=No findings").count()) > 0; |
| 109 | + |
| 110 | + if (hasResults) { |
| 111 | + // The review has findings — look for severity badges |
| 112 | + const severityBadges = page.locator( |
| 113 | + "text=/critical|high|medium|low/i" |
| 114 | + ); |
| 115 | + const badgeCount = await severityBadges.count(); |
| 116 | + // If findings exist, at least one severity badge should be present |
| 117 | + // (unless it's a clean review with 0 findings) |
| 118 | + expect(badgeCount).toBeGreaterThanOrEqual(0); |
| 119 | + } else if (hasCleanReview) { |
| 120 | + // Clean review — valid state |
| 121 | + await expect(page.locator("text=No findings")).toBeVisible(); |
| 122 | + } |
| 123 | + }); |
| 124 | + |
| 125 | + // ─── New Review button in view mode ─────────────────────────────────── |
| 126 | + |
| 127 | + test("New Review button appears when viewing a past review", async ({ |
| 128 | + page, |
| 129 | + }) => { |
| 130 | + const pastReviewsToggle = page.locator("button", { |
| 131 | + hasText: /Past Reviews/, |
| 132 | + }); |
| 133 | + const hasSection = (await pastReviewsToggle.count()) > 0; |
| 134 | + |
| 135 | + if (!hasSection) { |
| 136 | + // No past reviews available — can't enter view mode |
| 137 | + return; |
| 138 | + } |
| 139 | + |
| 140 | + // Expand and click a past review |
| 141 | + await pastReviewsToggle.click(); |
| 142 | + await page.waitForTimeout(300); |
| 143 | + |
| 144 | + const firstReview = page |
| 145 | + .locator("button") |
| 146 | + .filter({ has: page.locator("text=/findings/") }) |
| 147 | + .first(); |
| 148 | + const reviewExists = (await firstReview.count()) > 0; |
| 149 | + |
| 150 | + if (!reviewExists) return; |
| 151 | + |
| 152 | + await firstReview.click(); |
| 153 | + await waitForNoSpinners(page, 10_000); |
| 154 | + |
| 155 | + // In view mode, the "New Review" button should be visible |
| 156 | + const newReviewButton = page.locator("button", { |
| 157 | + hasText: "New Review", |
| 158 | + }); |
| 159 | + await expect(newReviewButton).toBeVisible({ timeout: 5_000 }); |
| 160 | + }); |
| 161 | + |
| 162 | + // ─── New Review click returns to create form ────────────────────────── |
| 163 | + |
| 164 | + test("Clicking New Review returns to the create form", async ({ page }) => { |
| 165 | + const pastReviewsToggle = page.locator("button", { |
| 166 | + hasText: /Past Reviews/, |
| 167 | + }); |
| 168 | + const hasSection = (await pastReviewsToggle.count()) > 0; |
| 169 | + |
| 170 | + if (!hasSection) { |
| 171 | + // No past reviews — verify the form is already showing |
| 172 | + await expect( |
| 173 | + page.locator("button", { hasText: "Select repository..." }) |
| 174 | + ).toBeVisible(); |
| 175 | + return; |
| 176 | + } |
| 177 | + |
| 178 | + // Expand and click a past review to enter view mode |
| 179 | + await pastReviewsToggle.click(); |
| 180 | + await page.waitForTimeout(300); |
| 181 | + |
| 182 | + const firstReview = page |
| 183 | + .locator("button") |
| 184 | + .filter({ has: page.locator("text=/findings/") }) |
| 185 | + .first(); |
| 186 | + const reviewExists = (await firstReview.count()) > 0; |
| 187 | + |
| 188 | + if (!reviewExists) { |
| 189 | + await expect( |
| 190 | + page.locator("button", { hasText: "Select repository..." }) |
| 191 | + ).toBeVisible(); |
| 192 | + return; |
| 193 | + } |
| 194 | + |
| 195 | + await firstReview.click(); |
| 196 | + await waitForNoSpinners(page, 10_000); |
| 197 | + |
| 198 | + // Click "New Review" to go back to create mode |
| 199 | + const newReviewButton = page.locator("button", { |
| 200 | + hasText: "New Review", |
| 201 | + }); |
| 202 | + await expect(newReviewButton).toBeVisible({ timeout: 5_000 }); |
| 203 | + await newReviewButton.click(); |
| 204 | + |
| 205 | + // The repository picker should reappear |
| 206 | + await expect( |
| 207 | + page.locator("button", { hasText: "Select repository..." }) |
| 208 | + ).toBeVisible({ timeout: 5_000 }); |
| 209 | + }); |
| 210 | + |
| 211 | + // ─── Tauri-unavailable state ────────────────────────────────────────── |
| 212 | + |
| 213 | + test("Shows appropriate state when Tauri is unavailable", async ({ |
| 214 | + page, |
| 215 | + }) => { |
| 216 | + // Without Tauri IPC, the page should still render the create form |
| 217 | + // with the "Select repository..." button. Past reviews won't load. |
| 218 | + const repoButton = page.locator("button", { |
| 219 | + hasText: "Select repository...", |
| 220 | + }); |
| 221 | + const placeholder = page.locator("text=Select a branch and run a review"); |
| 222 | + |
| 223 | + const hasForm = (await repoButton.count()) > 0; |
| 224 | + const hasPlaceholder = (await placeholder.count()) > 0; |
| 225 | + |
| 226 | + // At minimum, the page rendered without crashing |
| 227 | + expect(hasForm || hasPlaceholder).toBe(true); |
| 228 | + }); |
| 229 | +}); |
0 commit comments