1 import { test, expect } from './shared.js';
3 const reverse_only = !!process.env.REVERSE_ONLY;
5 test.describe('Reverse Page', () => {
7 test.describe('No search', () => {
10 test.beforeAll(async ({ browser }) => {
11 page = await browser.newPage();
12 await page.goto('/reverse.html');
15 test.afterAll(async () => {
19 test('should allow switching coordinates', async () => {
20 expect(await page.locator('input[name=lat]').inputValue()).toBe('');
21 expect(await page.locator('input[name=lon]').inputValue()).toBe('');
23 await page.locator('#switch-coords').click();
25 expect(await page.locator('input[name=lat]').inputValue()).toBe('');
26 expect(await page.locator('input[name=lon]').inputValue()).toBe('');
28 await page.locator('input[name=lat]').fill('5');
29 await page.locator('input[name=lon]').fill('10');
30 await page.locator('#switch-coords').click();
32 expect(await page.locator('input[name=lat]').inputValue()).toBe('10');
33 expect(await page.locator('input[name=lon]').inputValue()).toBe('5');
37 test.describe('With search', () => {
40 test.beforeAll(async ({ browser }) => {
41 page = await browser.newPage();
42 await page.goto('/reverse.html');
43 await page.locator('input[name=lat]').fill('27.1750090510034');
44 await page.locator('input[name=lon]').fill('78.04209025');
45 await page.locator('button[type=submit]').click();
46 await page.locator('#searchresults').waitFor();
49 test.afterAll(async () => {
53 test('should return single result', async () => {
54 const results_count = await page.locator(
55 '#searchresults .result'
57 expect(results_count).toBe(1);
60 test('should display a map', async () => {
61 await page.locator('#map').waitFor();
62 await expect(page.locator('#map')).toHaveCount(1);
65 test('should preserve advanced options when searching from a map click',
67 // Set layer=address, submit form
68 await page.locator('#searchAdvancedOptions summary').click();
69 await page.locator('#option_layer').waitFor();
70 await page.locator('#option_layer').evaluate(
71 (input) => { input.value = ''; }
73 await page.locator('#option_layer').fill('address');
74 await page.locator('button[type=submit]').click();
75 await page.waitForFunction(() => {
76 return new URLSearchParams(location.search).get('layer') === 'address';
79 const initialUrl = new URL(page.url());
80 const initialLat = initialUrl.searchParams.get('lat');
82 // Click on new position
83 await page.locator('#map').click({ position: { x: 50, y: 50 } });
85 // Wait until latitude in URL changed
86 await page.waitForFunction(
88 return new URL(window.location.href)
89 .searchParams.get('lat') !== previousLat;
94 // Confirm the layer=address is still in URL
95 const refreshedUrl = new URL(page.url());
96 expect(refreshedUrl.searchParams.get('layer')).toBe('address');
100 test('should redirect to details page on clicking details button',
102 await page.locator('#searchresults .result a').first().click();
103 await page.locator('table#address').waitFor();
105 const current_url = new URL(page.url());
106 expect(current_url.pathname).toBe('/details.html');
111 test('should clear results when switching to search page', async () => {
112 await page.locator('nav .nav-link[href="search.html"]').click();
114 const results_count = await page.locator(
115 '#searchresults .result'
117 expect(results_count).toBe(0);