Skip to content

Commit 98b7119

Browse files
committed
test: use testid in e2e tests
1 parent 1c99d3d commit 98b7119

File tree

4 files changed

+61
-66
lines changed

4 files changed

+61
-66
lines changed

e2e/website.spec.js

Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -26,56 +26,60 @@ test.describe('Website Router', () => {
2626
await expect(mainContent).toBeVisible()
2727

2828
// Check for the Projects heading
29-
const projectsHeading = page.locator('h2:has-text("Projects")')
29+
const projectsHeading = page.locator('[data-testid="projects-heading"]')
3030
await expect(projectsHeading).toBeVisible()
3131

3232
// Check for project links in the list
33-
const projectLinks = page.locator('ul li a')
33+
const projectLinks = page.locator('[data-testid="projects-list"] li a')
3434
const count = await projectLinks.count()
3535

3636
// We should have at least one project link
3737
expect(count).toBeGreaterThan(0)
3838

3939
// Check for the Checklists heading
40-
const checklistsHeading = page.locator('h2:has-text("Checklists")')
40+
const checklistsHeading = page.locator('[data-testid="checklists-heading"]')
4141
await expect(checklistsHeading).toBeVisible()
4242

4343
// Check for the first table
44-
const firstTable = page.locator('table').first()
45-
await expect(firstTable).toBeVisible()
44+
const checklistsTable = page.locator('[data-testid="checklists-table"]')
45+
await expect(checklistsTable).toBeVisible()
4646
// Check that the table headers exist
47-
const docHeader = firstTable.locator('thead tr th:has-text("Documentation")')
48-
const titleHeader = firstTable.locator('thead tr th:has-text("Title")')
49-
const descHeader = firstTable.locator('thead tr th:has-text("Description")')
50-
const authorHeader = firstTable.locator('thead tr th:has-text("Author")')
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")')
5151

5252
await expect(docHeader).toBeVisible()
5353
await expect(titleHeader).toBeVisible()
5454
await expect(descHeader).toBeVisible()
5555
await expect(authorHeader).toBeVisible()
5656

5757
// Check for at least one row in the table
58-
const rows = await firstTable.locator('tr')
58+
const rows = await checklistsTable.locator('tr')
5959
expect(await rows.count()).toBeGreaterThan(0)
6060

6161
// Check for the Compliance Checks heading
62-
const complianceChecksHeading = page.locator('h2:has-text("Compliance Checks")')
62+
const complianceChecksHeading = page.locator('[data-testid="compliance-checks-heading"]')
6363
await expect(complianceChecksHeading).toBeVisible()
6464

65+
// Check for Compliance Checks Description
66+
const complianceChecksDescription = page.locator('[data-testid="compliance-checks-description"]')
67+
await expect(complianceChecksDescription).toBeVisible()
68+
6569
// Check for the second table
66-
const secondTable = page.locator('table').last()
67-
await expect(secondTable).toBeVisible()
70+
const complianceChecksTable = page.locator('[data-testid="compliance-checks-table"]')
71+
await expect(complianceChecksTable).toBeVisible()
6872
// Check that the table headers exist
69-
const docHeader2 = secondTable.locator('thead tr th:has-text("Documentation")')
70-
const nameHeader = secondTable.locator('thead tr th:has-text("Name")')
71-
const descHeader2 = secondTable.locator('thead tr th:has-text("Description")')
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")')
7276

7377
await expect(docHeader2).toBeVisible()
7478
await expect(nameHeader).toBeVisible()
7579
await expect(descHeader2).toBeVisible()
7680

7781
// Check for at least one row in the table
78-
const rows2 = await secondTable.locator('tr')
82+
const rows2 = await complianceChecksTable.locator('tr')
7983
expect(await rows2.count()).toBeGreaterThan(0)
8084
})
8185

@@ -87,7 +91,7 @@ test.describe('Website Router', () => {
8791
await expect(page).toHaveURL(`/projects/${testProjectId}`)
8892

8993
// Check for the project name in the heading
90-
const projectHeading = page.locator('h1')
94+
const projectHeading = page.locator('[data-testid="project-heading"]')
9195
await expect(projectHeading).toBeVisible()
9296
await expect(projectHeading).toContainText('Report')
9397

@@ -97,41 +101,32 @@ test.describe('Website Router', () => {
97101

98102
// Check for section headings that should be present on project pages
99103
const sectionHeadings = [
100-
'Alerts',
101-
'Results',
102-
'Tasks'
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"]'
103110
]
104111

105112
for (const headingText of sectionHeadings) {
106-
const heading = page.locator(`h2:has-text("${headingText}")`)
113+
const heading = page.locator(headingText)
107114
await expect(heading).toBeVisible()
108115
}
109116

110-
// Check for OSSF scorecard section
111-
const ossfHeading = page.locator('h2:has-text("OSSF Scorecard Analysis")')
112-
await expect(ossfHeading).toBeVisible()
113-
114-
// Check for GitHub organizations section
115-
const githubOrgsHeading = page.locator('h2:has-text("GitHub Organizations in scope")')
116-
await expect(githubOrgsHeading).toBeVisible()
117-
118-
// Check for an organization list
119-
const list = page.locator('ul li')
117+
// Check for a GitHub organization list
118+
const list = page.locator('[data-testid="github-orgs-list"] li')
120119
await expect(list).toBeVisible()
121120

122-
// Check for GitHub repositories section
123-
const githubReposHeading = page.locator('h2:has-text("GitHub repositories in scope")')
124-
await expect(githubReposHeading).toBeVisible()
125-
126-
// Check for the first table
127-
const firstTable = page.locator('table').first()
128-
await expect(firstTable).toBeVisible()
121+
// Check for the GitHub repositories table
122+
const githubReposTable = page.locator('[data-testid="github-repos-table"]')
123+
await expect(githubReposTable).toBeVisible()
129124
// Check that the table headers exist
130-
const repositoryHeader = firstTable.locator('thead tr th:has-text("Repository")')
131-
const starsHeader = firstTable.locator('thead tr th:has-text("Stars")')
132-
const forksHeader = firstTable.locator('thead tr th:has-text("Forks")')
133-
const subscribersHeader = firstTable.locator('thead tr th:has-text("Subscribers")')
134-
const issuesHeader = firstTable.locator('thead tr th:has-text("Open Issues")')
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")')
135130

136131
await expect(repositoryHeader).toBeVisible()
137132
await expect(starsHeader).toBeVisible()
@@ -140,7 +135,7 @@ test.describe('Website Router', () => {
140135
await expect(issuesHeader).toBeVisible()
141136

142137
// Check for at least one row in the table
143-
const rows = await firstTable.locator('tr')
138+
const rows = await githubReposTable.locator('tr')
144139
expect(await rows.count()).toBeGreaterThan(0)
145140
})
146141

@@ -149,14 +144,14 @@ test.describe('Website Router', () => {
149144
await page.goto('/projects/invalid')
150145

151146
// Check for the Not Found heading
152-
const notFoundHeading = page.locator('h1:has-text("Not Found!")')
147+
const notFoundHeading = page.locator('[data-testid="not-found-title"]')
153148
await expect(notFoundHeading).toBeVisible()
154149

155150
// Test with non-existent numeric ID
156151
await page.goto('/projects/999999')
157152

158153
// Check for the Not Found heading
159-
const notFoundHeading2 = page.locator('h1:has-text("Not Found!")')
154+
const notFoundHeading2 = page.locator('[data-testid="not-found-title"]')
160155
await expect(notFoundHeading2).toBeVisible()
161156
})
162157

src/reports/templates/index.ejs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
registered. Every project listed includes additional reports with its own dashboard, tasks, and alerts.
1717
</p>
1818

19-
<h2 class="text-2xl font-bold mb-4">Projects</h2>
19+
<h2 class="text-2xl font-bold mb-4" data-testid="projects-heading">Projects</h2>
2020
<p class="mb-4">Click on any project to get more details:</p>
21-
<ul class="list-disc list-inside mb-6">
21+
<ul class="list-disc list-inside mb-6" data-testid="projects-list">
2222
<% projects.forEach(project=> { %>
2323
<li>
2424
<a href="<%= resolveLink('', project) %>" class="text-blue-500 underline font-bold">
@@ -28,8 +28,8 @@
2828
<% }) %>
2929
</ul>
3030

31-
<h2 class="text-2xl font-bold mb-4">Checklists</h2>
32-
<table class="w-full border border-gray-300 border-collapse mb-6">
31+
<h2 class="text-2xl font-bold mb-4" data-testid="checklists-heading">Checklists</h2>
32+
<table class="w-full border border-gray-300 border-collapse mb-6" data-testid="checklists-table">
3333
<thead>
3434
<tr class="bg-gray-200">
3535
<th class="border border-gray-300 px-4 py-2 text-left">Documentation</th>
@@ -61,13 +61,13 @@
6161
</tbody>
6262
</table>
6363

64-
<h2 class="text-2xl font-bold mb-4">Compliance Checks</h2>
65-
<p class="mb-4">Currently <span class="font-bold">
64+
<h2 class="text-2xl font-bold mb-4" data-testid="compliance-checks-heading">Compliance Checks</h2>
65+
<p class="mb-4" data-testid="compliance-checks-description">Currently <span class="font-bold">
6666
<%= checks.filter(i=> i.implementation_status === "completed").length %>/<%= checks.length %>
6767
</span> are implemented. <a href="https://openpathfinder.com/contribute"
6868
class="text-blue-500 underline font-bold">Help us</a> to implement more!</p>
6969

70-
<table class="w-full border border-gray-300 border-collapse">
70+
<table class="w-full border border-gray-300 border-collapse" data-testid="compliance-checks-table">
7171
<thead>
7272
<tr class="bg-gray-200">
7373
<th class="border border-gray-300 px-4 py-2 text-left">Documentation</th>

src/reports/templates/notFound.ejs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
<div class="flex-grow">
1212
<main class="container mx-auto p-6">
13-
<h1 class="text-2xl font-bold mb-4">Not Found!</h1>
14-
<p class="text-gray-700 mb-4">The page you are looking for does not exist.</p>
15-
<a href="/" class="text-blue-600 underline">Return to the home page</a>
13+
<h1 class="text-2xl font-bold mb-4" data-testid="not-found-title">Not Found!</h1>
14+
<p class="text-gray-700 mb-4" data-testid="not-found-description">The page you are looking for does not exist.</p>
15+
<a href="/" class="text-blue-600 underline" data-testid="not-found-return-link">Return to the home page</a>
1616
</main>
1717
</div>
1818
<div class="mt-auto">

src/reports/templates/project.ejs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<%- include('partials/navigation') %>
1010
<div class="flex-grow">
1111
<main class="container mx-auto p-6">
12-
<h1 class="text-2xl font-bold mb-4">
12+
<h1 class="text-2xl font-bold mb-4" data-testid="project-heading">
1313
<%= project.name %> Report
1414
</h1>
1515
<p class="text-gray-700 mb-4">In this dashboard, you can find the relevant information for the project <span
@@ -27,7 +27,7 @@
2727
</span>.</p>
2828

2929
<!-- Alerts -->
30-
<h2 class="text-2xl font-bold mb-4">Alerts</h2>
30+
<h2 class="text-2xl font-bold mb-4" data-testid="alerts-heading">Alerts</h2>
3131
<div class="mb-6">
3232
<% if (alerts && alerts.length > 0) { %>
3333
<ul class="space-y-4">
@@ -52,7 +52,7 @@
5252
</div>
5353

5454
<!-- Results -->
55-
<h2 class="text-2xl font-bold mb-4">Results</h2>
55+
<h2 class="text-2xl font-bold mb-4" data-testid="results-heading">Results</h2>
5656
<% if (tasks && tasks.length > 0) { %>
5757
5858
<table class="w-full border border-gray-300 border-collapse mb-6">
@@ -93,7 +93,7 @@
9393
<% } %>
9494

9595
<!-- Tasks -->
96-
<h2 class="text-2xl font-bold mb-4">Tasks</h2>
96+
<h2 class="text-2xl font-bold mb-4" data-testid="tasks-heading">Tasks</h2>
9797
<div class="mb-6">
9898
<% if (tasks && tasks.length > 0) { %>
9999
<% tasks.forEach(task => { %>
@@ -121,7 +121,7 @@
121121

122122

123123
<!-- OSSF Scorecard Analysis -->
124-
<h2 class="text-2xl font-bold mb-4">OSSF Scorecard Analysis</h2>
124+
<h2 class="text-2xl font-bold mb-4" data-testid="ossf-scorecard-heading">OSSF Scorecard Analysis</h2>
125125
<% if (ossfScorecardResults && ossfScorecardResults.length > 0) { %>
126126
127127
<table class="w-full border border-gray-300 border-collapse mb-6">
@@ -171,9 +171,9 @@
171171

172172

173173
<!-- List all the organizations -->
174-
<h2 class="text-2xl font-bold mb-4">GitHub Organizations in scope</h2>
174+
<h2 class="text-2xl font-bold mb-4" data-testid="github-orgs-heading">GitHub Organizations in scope</h2>
175175
<% if (githubOrgs && githubOrgs.length > 0) { %>
176-
<ul class="space-y-4 mb-6">
176+
<ul class="space-y-4 mb-6" data-testid="github-orgs-list">
177177
<% githubOrgs.forEach(org => { %>
178178
<li class="p-4 border border-gray-300 rounded-md shadow">
179179
<img src="<%= org.avatar_url %>" alt="<%= org.name %> logo" class="w-12 h-12 rounded-full mb-2">
@@ -193,11 +193,11 @@
193193

194194

195195
<!-- List all the repositories -->
196-
<h2 class="text-2xl font-bold mb-4">GitHub repositories in scope</h2>
196+
<h2 class="text-2xl font-bold mb-4" data-testid="github-repos-heading">GitHub repositories in scope</h2>
197197

198198
<% if (githubRepos && githubRepos.length > 0) { %>
199199
200-
<table class="w-full border border-gray-300 border-collapse mb-6">
200+
<table class="w-full border border-gray-300 border-collapse mb-6" data-testid="github-repos-table">
201201
<thead>
202202
<tr class="bg-gray-200">
203203
<th class="border border-gray-300 px-4 py-2 text-left">Repository</th>

0 commit comments

Comments
 (0)