Skip to content

Commit 4154b3f

Browse files
authored
Merge pull request #1955 from dscho/verify-search-results-in-playwright
Verify the search results page in playwright
2 parents d76e3d1 + 5bad107 commit 4154b3f

File tree

2 files changed

+23
-40
lines changed

2 files changed

+23
-40
lines changed

.github/workflows/playwright.yml

-5
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ on:
66
description: 'URL to test'
77
required: true
88
default: 'https://git-scm.com'
9-
assume-rails-app:
10-
description: 'Whether the URL points to the original Rails app variant of the site'
11-
required: false
12-
default: 'false'
139
jobs:
1410
test:
1511
timeout-minutes: 60
@@ -24,7 +20,6 @@ jobs:
2420
- name: Run Playwright tests
2521
env:
2622
PLAYWRIGHT_TEST_URL: ${{ github.event.inputs.url }}
27-
PLAYWRIGHT_ASSUME_RAILS_APP: ${{ github.event.inputs.assume-rails-app }}
2823
run: npx playwright test --project=chrome
2924
- uses: actions/upload-artifact@v4
3025
if: always()

tests/git-scm.spec.js

+23-35
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const { test, expect, selectors, devices } = require('@playwright/test')
33
const url = process.env.PLAYWRIGHT_TEST_URL
44
? process.env.PLAYWRIGHT_TEST_URL.replace(/[^/]$/, '$&/')
55
: 'https://git-scm.com/'
6-
const isRailsApp = process.env.PLAYWRIGHT_ASSUME_RAILS_APP === 'true'
76

87
// Whenever a test fails, attach a screenshot to diagnose failures better
98
test.afterEach(async ({ page }, testInfo) => {
@@ -24,11 +23,7 @@ test.afterEach(async ({ page }, testInfo) => {
2423

2524
test('generator is Hugo', async ({page}) => {
2625
await page.goto(url)
27-
if (isRailsApp) {
28-
await expect(page.locator('meta[name="generator"]')).toHaveCount(0)
29-
} else {
30-
await expect(page.locator('meta[name="generator"]')).toHaveAttribute('content', /^Hugo /)
31-
}
26+
await expect(page.locator('meta[name="generator"]')).toHaveAttribute('content', /^Hugo /)
3227
})
3328

3429
async function pretendPlatform(page, browserName, userAgent, platform) {
@@ -122,23 +117,31 @@ test('search', async ({ page }) => {
122117
await expect(searchResults.getByRole("link")).not.toHaveCount(0)
123118
await expect(searchResults.getByRole("link").nth(0)).toHaveText('git-commit')
124119

120+
// Expect the search page to show up
121+
await searchBox.press('Enter')
122+
await expect(page).toHaveURL(/\/search/)
123+
const filters = await page.getByRole('group', { name: 'Filters' })
124+
await expect(filters).toBeVisible()
125+
await expect(filters.filter({ hasText: 'Category' })).toBeVisible()
126+
127+
await expect(page.getByText(/results for commit/)).toContainText(/^\d+ results for commit$/)
128+
129+
const searchLinks = await page
130+
.getByRole('listItem')
131+
.filter({ has: page.getByRole('link', { name: 'commit' }) })
132+
await expect(searchLinks).not.toHaveCount(0)
133+
134+
await expect(page.getByRole('button', { name: 'Load more results' })).toBeVisible()
135+
125136
// On localized pages, the search results should be localized as well
126137
await page.goto(`${url}docs/git-commit/fr`)
127138
await searchBox.fill('add')
128139
await searchBox.press('Shift')
129-
if (isRailsApp) {
130-
await expect(searchResults.getByRole("link").nth(0)).toHaveAttribute('href', /\/docs\/git-add$/)
131-
} else {
132-
await expect(searchResults.getByRole("link").nth(0)).toHaveAttribute('href', /\/docs\/git-add\/fr(\.html)?$/)
133-
}
140+
await expect(searchResults.getByRole("link").nth(0)).toHaveAttribute('href', /\/docs\/git-add\/fr(\.html)?$/)
134141

135142
// pressing the Enter key should navigate to the full search results page
136143
await searchBox.press('Enter')
137-
if (isRailsApp) {
138-
await expect(page).toHaveURL(/\/search/)
139-
} else {
140-
await expect(page).toHaveURL(/\/search.*language=fr/)
141-
}
144+
await expect(page).toHaveURL(/\/search.*language=fr/)
142145
})
143146

144147
test('manual pages', async ({ page }) => {
@@ -152,11 +155,7 @@ test('manual pages', async ({ page }) => {
152155
// Verify that the drop-downs are shown when clicked
153156
const previousVersionDropdown = page.locator('#previous-versions-dropdown')
154157
await expect(previousVersionDropdown).toBeHidden()
155-
if (isRailsApp) {
156-
await page.getByRole('link', { name: /Version \d+\.\d+\.\d+/ }).click()
157-
} else {
158-
await page.getByRole('link', { name: 'Latest version' }).click()
159-
}
158+
await page.getByRole('link', { name: 'Latest version' }).click()
160159
await expect(previousVersionDropdown).toBeVisible()
161160

162161
const topicsDropdown = page.locator('#topics-dropdown')
@@ -188,14 +187,8 @@ test('manual pages', async ({ page }) => {
188187
// Ensure that the French mis-translation of `git remote renom` is not present
189188
await page.goto(`${url}docs/git-remote/fr`)
190189
const synopsis = page.locator('xpath=//h2[contains(text(), "SYNOPSIS")]/following-sibling::*[1]').first()
191-
if (isRailsApp) {
192-
// This is a bug in the Rails app, and it is unclear what the root cause is
193-
await expect(synopsis).not.toHaveText(/git remote rename.*<ancien> <nouveau>/)
194-
await expect(synopsis).toHaveText(/git remote renom.*<ancien> <nouveau>/)
195-
} else {
196-
await expect(synopsis).toHaveText(/git remote rename.*<ancien> <nouveau>/)
197-
await expect(synopsis).not.toHaveText(/git remote renom.*<ancien> <nouveau>/)
198-
}
190+
await expect(synopsis).toHaveText(/git remote rename.*<ancien> <nouveau>/)
191+
await expect(synopsis).not.toHaveText(/git remote renom.*<ancien> <nouveau>/)
199192
})
200193

201194
test('book', async ({ page }) => {
@@ -245,12 +238,7 @@ test('book', async ({ page }) => {
245238

246239
// Navigate to a page whose URL contains a question mark
247240
await page.goto(`${url}book/az/v2/Başlanğıc-Git-Nədir?`)
248-
if (isRailsApp) {
249-
await expect(page).toHaveURL(/book\/az\/v2$/)
250-
await page.goto(`${url}book/az/v2/Başlanğıc-Git-Nədir%3F`)
251-
} else {
252-
await expect(page).toHaveURL(/Ba%C5%9Flan%C4%9F%C4%B1c-Git-N%C9%99dir%3F/)
253-
}
241+
await expect(page).toHaveURL(/Ba%C5%9Flan%C4%9F%C4%B1c-Git-N%C9%99dir%3F/)
254242
await expect(page.getByRole('document')).toHaveText(/Snapshotlar, Fərqlər Yox/)
255243

256244
// the repository URL now points to the Azerbaijani translation

0 commit comments

Comments
 (0)