|
| 1 | +import path from 'node:path'; |
| 2 | +import { expect, test } from '@playwright/test'; |
| 3 | +import { getPort, killProcess, runDevCommand } from '../utils/runCommands'; |
| 4 | +import { searchInPage } from '../utils/search'; |
| 5 | + |
| 6 | +const fixtureDir = path.resolve(__dirname, '../fixtures'); |
| 7 | + |
| 8 | +test.describe('search i18n test', async () => { |
| 9 | + let appPort; |
| 10 | + let app; |
| 11 | + |
| 12 | + test.beforeAll(async () => { |
| 13 | + const appDir = path.join(fixtureDir, 'search-i18n'); |
| 14 | + appPort = await getPort(); |
| 15 | + app = await runDevCommand(appDir, appPort); |
| 16 | + }); |
| 17 | + |
| 18 | + test.afterAll(async () => { |
| 19 | + if (app) { |
| 20 | + await killProcess(app); |
| 21 | + } |
| 22 | + }); |
| 23 | + |
| 24 | + test('should update search index when language changed', async ({ page }) => { |
| 25 | + await page.goto(`http://localhost:${appPort}`); |
| 26 | + |
| 27 | + const suggestItems1 = await searchInPage(page, 'Button'); |
| 28 | + expect(await suggestItems1[0].textContent()).toContain('Button en'); |
| 29 | + |
| 30 | + // close the search modal |
| 31 | + await page.click('body'); |
| 32 | + |
| 33 | + // Switch language to Chinese |
| 34 | + await page.click('.rspress-nav-menu-group-button'); |
| 35 | + await page.click('.rspress-nav-menu-group-content a'); |
| 36 | + await page.waitForLoadState(); |
| 37 | + |
| 38 | + const suggestItems2 = await searchInPage(page, 'Button'); |
| 39 | + expect(await suggestItems2[0].textContent()).toContain('Button 中文'); |
| 40 | + await page.click('body'); |
| 41 | + |
| 42 | + // Switch language to English |
| 43 | + await page.click('.rspress-nav-menu-group-button'); |
| 44 | + await page.click('.rspress-nav-menu-group-content a'); |
| 45 | + await page.waitForLoadState(); |
| 46 | + |
| 47 | + const suggestItems3 = await searchInPage(page, 'Button'); |
| 48 | + expect(await suggestItems3[0].textContent()).toContain('Button en'); |
| 49 | + }); |
| 50 | +}); |
0 commit comments