|
| 1 | +// @ts-check |
| 2 | +const { test, expect } = require('@playwright/test') |
| 3 | + |
| 4 | +/** |
| 5 | + * E2E tests for the website router functionality |
| 6 | + * This tests the routes defined in src/httpServer/routers/website.js |
| 7 | + */ |
| 8 | +test.describe('Website Router', () => { |
| 9 | + // @TODO: load this from fixtures |
| 10 | + const testProjectId = 1 |
| 11 | + |
| 12 | + test('should render the index page with projects, checklists and Compliance Checks', async ({ page }) => { |
| 13 | + // Navigate to the root path (handled by router.get('/')) |
| 14 | + await page.goto('/') |
| 15 | + |
| 16 | + // Check that the page title contains expected text |
| 17 | + await expect(page).toHaveTitle(/VisionBoard Reports/) |
| 18 | + |
| 19 | + // Check for the header with the logo |
| 20 | + const header = page.locator('header') |
| 21 | + await expect(header).toBeVisible() |
| 22 | + await expect(header.locator('a')).toContainText('VisionBoard Reports') |
| 23 | + |
| 24 | + // Check for main content container |
| 25 | + const mainContent = page.locator('main.container') |
| 26 | + await expect(mainContent).toBeVisible() |
| 27 | + |
| 28 | + // Check for the Projects heading |
| 29 | + const projectsHeading = page.locator('[data-testid="projects-heading"]') |
| 30 | + await expect(projectsHeading).toBeVisible() |
| 31 | + |
| 32 | + // Check for project links in the list |
| 33 | + const projectLinks = page.locator('[data-testid="projects-list"] li a') |
| 34 | + const count = await projectLinks.count() |
| 35 | + |
| 36 | + // We should have at least one project link |
| 37 | + expect(count).toBeGreaterThan(0) |
| 38 | + |
| 39 | + // Check for the Checklists heading |
| 40 | + const checklistsHeading = page.locator('[data-testid="checklists-heading"]') |
| 41 | + await expect(checklistsHeading).toBeVisible() |
| 42 | + |
| 43 | + // Check for the first table |
| 44 | + const checklistsTable = page.locator('[data-testid="checklists-table"]') |
| 45 | + await expect(checklistsTable).toBeVisible() |
| 46 | + // Check that the table headers exist |
| 47 | + const docHeader = checklistsTable.locator('thead tr th:has-text("Documentation")') |
| 48 | + const titleHeader = checklistsTable.locator('thead tr th:has-text("Title")') |
| 49 | + const descHeader = checklistsTable.locator('thead tr th:has-text("Description")') |
| 50 | + const authorHeader = checklistsTable.locator('thead tr th:has-text("Author")') |
| 51 | + |
| 52 | + await expect(docHeader).toBeVisible() |
| 53 | + await expect(titleHeader).toBeVisible() |
| 54 | + await expect(descHeader).toBeVisible() |
| 55 | + await expect(authorHeader).toBeVisible() |
| 56 | + |
| 57 | + // Check for at least one row in the table |
| 58 | + const rows = await checklistsTable.locator('tr') |
| 59 | + expect(await rows.count()).toBeGreaterThan(0) |
| 60 | + |
| 61 | + // Check for the Compliance Checks heading |
| 62 | + const complianceChecksHeading = page.locator('[data-testid="compliance-checks-heading"]') |
| 63 | + await expect(complianceChecksHeading).toBeVisible() |
| 64 | + |
| 65 | + // Check for Compliance Checks Description |
| 66 | + const complianceChecksDescription = page.locator('[data-testid="compliance-checks-description"]') |
| 67 | + await expect(complianceChecksDescription).toBeVisible() |
| 68 | + |
| 69 | + // Check for the second table |
| 70 | + const complianceChecksTable = page.locator('[data-testid="compliance-checks-table"]') |
| 71 | + await expect(complianceChecksTable).toBeVisible() |
| 72 | + // Check that the table headers exist |
| 73 | + const docHeader2 = complianceChecksTable.locator('thead tr th:has-text("Documentation")') |
| 74 | + const nameHeader = complianceChecksTable.locator('thead tr th:has-text("Name")') |
| 75 | + const descHeader2 = complianceChecksTable.locator('thead tr th:has-text("Description")') |
| 76 | + |
| 77 | + await expect(docHeader2).toBeVisible() |
| 78 | + await expect(nameHeader).toBeVisible() |
| 79 | + await expect(descHeader2).toBeVisible() |
| 80 | + |
| 81 | + // Check for at least one row in the table |
| 82 | + const rows2 = await complianceChecksTable.locator('tr') |
| 83 | + expect(await rows2.count()).toBeGreaterThan(0) |
| 84 | + }) |
| 85 | + |
| 86 | + test('should navigate to and render project details page', async ({ page }) => { |
| 87 | + // Navigate directly to the project page using our test project ID |
| 88 | + await page.goto(`/projects/${testProjectId}`) |
| 89 | + |
| 90 | + // Check that we're on the correct project page URL |
| 91 | + await expect(page).toHaveURL(`/projects/${testProjectId}`) |
| 92 | + |
| 93 | + // Check for the project name in the heading |
| 94 | + const projectHeading = page.locator('[data-testid="project-heading"]') |
| 95 | + await expect(projectHeading).toBeVisible() |
| 96 | + await expect(projectHeading).toContainText('Report') |
| 97 | + |
| 98 | + // Check for main content container |
| 99 | + const mainContent = page.locator('main.container') |
| 100 | + await expect(mainContent).toBeVisible() |
| 101 | + |
| 102 | + // Check for section headings that should be present on project pages |
| 103 | + const sectionHeadings = [ |
| 104 | + '[data-testid="alerts-heading"]', |
| 105 | + '[data-testid="results-heading"]', |
| 106 | + '[data-testid="tasks-heading"]', |
| 107 | + '[data-testid="ossf-scorecard-heading"]', |
| 108 | + '[data-testid="github-orgs-heading"]', |
| 109 | + '[data-testid="github-repos-heading"]' |
| 110 | + ] |
| 111 | + |
| 112 | + for (const headingText of sectionHeadings) { |
| 113 | + const heading = page.locator(headingText) |
| 114 | + await expect(heading).toBeVisible() |
| 115 | + } |
| 116 | + |
| 117 | + // Check for a GitHub organization list |
| 118 | + const list = page.locator('[data-testid="github-orgs-list"] li') |
| 119 | + await expect(list).toBeVisible() |
| 120 | + |
| 121 | + // Check for the GitHub repositories table |
| 122 | + const githubReposTable = page.locator('[data-testid="github-repos-table"]') |
| 123 | + await expect(githubReposTable).toBeVisible() |
| 124 | + // Check that the table headers exist |
| 125 | + const repositoryHeader = githubReposTable.locator('thead tr th:has-text("Repository")') |
| 126 | + const starsHeader = githubReposTable.locator('thead tr th:has-text("Stars")') |
| 127 | + const forksHeader = githubReposTable.locator('thead tr th:has-text("Forks")') |
| 128 | + const subscribersHeader = githubReposTable.locator('thead tr th:has-text("Subscribers")') |
| 129 | + const issuesHeader = githubReposTable.locator('thead tr th:has-text("Open Issues")') |
| 130 | + |
| 131 | + await expect(repositoryHeader).toBeVisible() |
| 132 | + await expect(starsHeader).toBeVisible() |
| 133 | + await expect(forksHeader).toBeVisible() |
| 134 | + await expect(subscribersHeader).toBeVisible() |
| 135 | + await expect(issuesHeader).toBeVisible() |
| 136 | + |
| 137 | + // Check for at least one row in the table |
| 138 | + const rows = await githubReposTable.locator('tr') |
| 139 | + expect(await rows.count()).toBeGreaterThan(0) |
| 140 | + }) |
| 141 | + |
| 142 | + test('should handle invalid project IDs correctly', async ({ page }) => { |
| 143 | + // Test with non-numeric ID (should render 404 page) |
| 144 | + await page.goto('/projects/invalid') |
| 145 | + |
| 146 | + // Check for the Not Found heading |
| 147 | + const notFoundHeading = page.locator('[data-testid="not-found-title"]') |
| 148 | + await expect(notFoundHeading).toBeVisible() |
| 149 | + |
| 150 | + // Test with non-existent numeric ID |
| 151 | + await page.goto('/projects/999999') |
| 152 | + |
| 153 | + // Check for the Not Found heading |
| 154 | + const notFoundHeading2 = page.locator('[data-testid="not-found-title"]') |
| 155 | + await expect(notFoundHeading2).toBeVisible() |
| 156 | + }) |
| 157 | + |
| 158 | + test('should have working navigation between pages', async ({ page }) => { |
| 159 | + // Start at the index page |
| 160 | + await page.goto('/') |
| 161 | + |
| 162 | + // Find project links in the list |
| 163 | + const projectLinks = page.locator('ul li a') |
| 164 | + |
| 165 | + // Click the first project link |
| 166 | + await projectLinks.first().click() |
| 167 | + |
| 168 | + // Verify we're on a project page by checking for project-specific content |
| 169 | + const projectHeading = page.locator('h1:has-text("Report")') |
| 170 | + await expect(projectHeading).toBeVisible() |
| 171 | + |
| 172 | + // Verify the project page URL |
| 173 | + await expect(page).toHaveURL(`/projects/${testProjectId}`) |
| 174 | + |
| 175 | + // Navigate back to the index page using the header link |
| 176 | + const headerLink = page.locator('header a') |
| 177 | + await expect(headerLink).toBeVisible() |
| 178 | + await headerLink.click() |
| 179 | + |
| 180 | + // Verify we're back at the index page by checking for index-specific content |
| 181 | + const welcomeHeading = page.locator('h1:has-text("Welcome")') |
| 182 | + await expect(welcomeHeading).toBeVisible() |
| 183 | + |
| 184 | + // Also verify we're at the root URL |
| 185 | + await expect(page).toHaveURL('/') |
| 186 | + }) |
| 187 | +}) |
0 commit comments