1import { test, expect, devices } from '@playwright/test';
2
3const httpHost = process.env.HTTP_HOST
4
5if (typeof httpHost !== 'string') {
6    throw new Error('Environment variable "HTTP_HOST" is not set.')
7}
8
9test.use({ javaScriptEnabled: false });
10
11test('search should fallback when javascript is disabled', async ({ page }) => {
12    await page.goto(httpHost);
13    let searchInput = await page.getByRole('searchbox', { name: 'Search docs' });
14    await searchInput.fill('strpos');
15    await searchInput.press('Enter');
16    await expect(page).toHaveURL(`http://${httpHost}/manual/en/function.strpos.php`);
17
18    searchInput = await page.getByRole('searchbox', { name: 'Search docs' });
19    await searchInput.fill('php basics');
20    await searchInput.press('Enter');
21    await expect(page).toHaveURL(`http://${httpHost}/manual-lookup.php?pattern=php+basics&scope=quickref`);
22});
23
24test('search should fallback when javascript is disabled on mobile', async ({ browser }) => {
25    const context = await browser.newContext({
26        ...devices['iPhone SE']
27    });
28    const page = await context.newPage();
29    await page.goto(httpHost);
30    await page
31        .getByRole('link', { name: 'Search docs' })
32        .click();
33    await expect(page).toHaveURL(`http://${httpHost}/lookup-form.php`);
34
35    const searchInput = await page.getByRole('searchbox', { name: 'Lookup docs' });
36    await searchInput.fill('strpos');
37    await searchInput.press('Enter');
38    await expect(page).toHaveURL(`http://${httpHost}/manual/en/function.strpos.php`);
39});
40
41test('menu should fallback when javascript is disabled on mobile', async ({ browser }) => {
42    const context = await browser.newContext({
43        ...devices['iPhone SE']
44    });
45    const page = await context.newPage();
46    await page.goto(httpHost);
47    await page
48        .getByRole('link', { name: 'Menu' })
49        .click();
50    await expect(page).toHaveURL(`http://${httpHost}/menu.php`);
51});
52