Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify the search results page in playwright #1955

Merged
merged 2 commits into from
Mar 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ on:
description: 'URL to test'
required: true
default: 'https://git-scm.com'
assume-rails-app:
description: 'Whether the URL points to the original Rails app variant of the site'
required: false
default: 'false'
jobs:
test:
timeout-minutes: 60
Expand All @@ -24,7 +20,6 @@ jobs:
- name: Run Playwright tests
env:
PLAYWRIGHT_TEST_URL: ${{ github.event.inputs.url }}
PLAYWRIGHT_ASSUME_RAILS_APP: ${{ github.event.inputs.assume-rails-app }}
run: npx playwright test --project=chrome
- uses: actions/upload-artifact@v4
if: always()
Expand Down
58 changes: 23 additions & 35 deletions tests/git-scm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const { test, expect, selectors, devices } = require('@playwright/test')
const url = process.env.PLAYWRIGHT_TEST_URL
? process.env.PLAYWRIGHT_TEST_URL.replace(/[^/]$/, '$&/')
: 'https://git-scm.com/'
const isRailsApp = process.env.PLAYWRIGHT_ASSUME_RAILS_APP === 'true'

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

test('generator is Hugo', async ({page}) => {
await page.goto(url)
if (isRailsApp) {
await expect(page.locator('meta[name="generator"]')).toHaveCount(0)
} else {
await expect(page.locator('meta[name="generator"]')).toHaveAttribute('content', /^Hugo /)
}
await expect(page.locator('meta[name="generator"]')).toHaveAttribute('content', /^Hugo /)
})

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

// Expect the search page to show up
await searchBox.press('Enter')
await expect(page).toHaveURL(/\/search/)
const filters = await page.getByRole('group', { name: 'Filters' })
await expect(filters).toBeVisible()
await expect(filters.filter({ hasText: 'Category' })).toBeVisible()

await expect(page.getByText(/results for commit/)).toContainText(/^\d+ results for commit$/)

const searchLinks = await page
.getByRole('listItem')
.filter({ has: page.getByRole('link', { name: 'commit' }) })
await expect(searchLinks).not.toHaveCount(0)

await expect(page.getByRole('button', { name: 'Load more results' })).toBeVisible()

// On localized pages, the search results should be localized as well
await page.goto(`${url}docs/git-commit/fr`)
await searchBox.fill('add')
await searchBox.press('Shift')
if (isRailsApp) {
await expect(searchResults.getByRole("link").nth(0)).toHaveAttribute('href', /\/docs\/git-add$/)
} else {
await expect(searchResults.getByRole("link").nth(0)).toHaveAttribute('href', /\/docs\/git-add\/fr(\.html)?$/)
}
await expect(searchResults.getByRole("link").nth(0)).toHaveAttribute('href', /\/docs\/git-add\/fr(\.html)?$/)

// pressing the Enter key should navigate to the full search results page
await searchBox.press('Enter')
if (isRailsApp) {
await expect(page).toHaveURL(/\/search/)
} else {
await expect(page).toHaveURL(/\/search.*language=fr/)
}
await expect(page).toHaveURL(/\/search.*language=fr/)
})

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

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

test('book', async ({ page }) => {
Expand Down Expand Up @@ -245,12 +238,7 @@ test('book', async ({ page }) => {

// Navigate to a page whose URL contains a question mark
await page.goto(`${url}book/az/v2/Başlanğıc-Git-Nədir?`)
if (isRailsApp) {
await expect(page).toHaveURL(/book\/az\/v2$/)
await page.goto(`${url}book/az/v2/Başlanğıc-Git-Nədir%3F`)
} else {
await expect(page).toHaveURL(/Ba%C5%9Flan%C4%9F%C4%B1c-Git-N%C9%99dir%3F/)
}
await expect(page).toHaveURL(/Ba%C5%9Flan%C4%9F%C4%B1c-Git-N%C9%99dir%3F/)
await expect(page.getByRole('document')).toHaveText(/Snapshot’lar, Fərqlər Yox/)

// the repository URL now points to the Azerbaijani translation
Expand Down
Loading