|
| 1 | +import { test, expect } from '@playwright/test'; |
| 2 | +import { waitForASFAPIResponse } from 'e2e/helpers'; |
| 3 | + |
| 4 | +const MAPBOX_API_GLOB = 'https://api.mapbox.com/geocoding/**'; |
| 5 | + |
| 6 | +const MOCK_RESPONSES = { |
| 7 | + Tibet: { |
| 8 | + type: 'FeatureCollection', |
| 9 | + features: [ |
| 10 | + { |
| 11 | + id: 'region.tibet', |
| 12 | + type: 'Feature', |
| 13 | + place_name: 'Tibet Autonomous Region, China', |
| 14 | + geometry: { type: 'Point', coordinates: [88.0439, 31.5534] }, |
| 15 | + bbox: [78.3955, 26.8562, 99.1159, 36.4833], |
| 16 | + }, |
| 17 | + ], |
| 18 | + }, |
| 19 | + 'Big Bear Lake': { |
| 20 | + type: 'FeatureCollection', |
| 21 | + features: [ |
| 22 | + { |
| 23 | + id: 'place.bigbear', |
| 24 | + type: 'Feature', |
| 25 | + place_name: 'Big Bear Lake, California, United States', |
| 26 | + geometry: { type: 'Point', coordinates: [-116.9115, 34.2437] }, |
| 27 | + bbox: [-116.95, 34.2, -116.87, 34.28], |
| 28 | + }, |
| 29 | + ], |
| 30 | + }, |
| 31 | + 'Sierra Le': { |
| 32 | + type: 'FeatureCollection', |
| 33 | + features: [ |
| 34 | + { |
| 35 | + id: 'place.sierra1', |
| 36 | + type: 'Feature', |
| 37 | + place_name: 'Sierra Leone', |
| 38 | + geometry: { type: 'Point', coordinates: [-11.7799, 8.4606] }, |
| 39 | + bbox: [-13.3, 6.9, -10.3, 10.0], |
| 40 | + }, |
| 41 | + { |
| 42 | + id: 'place.sierra2', |
| 43 | + type: 'Feature', |
| 44 | + place_name: |
| 45 | + 'Sierra Leone Avenue, Nassau, New Providence, Bahamas', |
| 46 | + geometry: { type: 'Point', coordinates: [-77.3788, 25.0113] }, |
| 47 | + bbox: [-77.38, 25.01, -77.37, 25.02], |
| 48 | + }, |
| 49 | + ], |
| 50 | + }, |
| 51 | +}; |
| 52 | + |
| 53 | +async function mockGeocoding(page: any) { |
| 54 | + await page.route(MAPBOX_API_GLOB, (route: any) => { |
| 55 | + const url = route.request().url(); |
| 56 | + let response = MOCK_RESPONSES['Tibet']; |
| 57 | + |
| 58 | + for (const key of Object.keys(MOCK_RESPONSES)) { |
| 59 | + if (url.includes(encodeURIComponent(key))) { |
| 60 | + response = MOCK_RESPONSES[key]; |
| 61 | + break; |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + route.fulfill({ |
| 66 | + status: 200, |
| 67 | + contentType: 'application/json', |
| 68 | + body: JSON.stringify(response), |
| 69 | + }); |
| 70 | + }); |
| 71 | +} |
| 72 | + |
| 73 | +test('Place name is geocoded to WKT AOI and returns search results', async ({ |
| 74 | + page, |
| 75 | +}) => { |
| 76 | + await mockGeocoding(page); |
| 77 | + await page.goto('/'); |
| 78 | + await page.getByRole('button', { name: 'Sentinel-' }).click(); |
| 79 | + await page.getByRole('menuitem', { name: 'S1 Burst' }).click(); |
| 80 | + |
| 81 | + const aoiFilter = page.locator('app-aoi-filter'); |
| 82 | + await aoiFilter.locator('.additional-aoi-toggle').click(); |
| 83 | + |
| 84 | + const geocodeInput = aoiFilter |
| 85 | + .locator('app-geocode-selector') |
| 86 | + .getByLabel('Search for a location'); |
| 87 | + await geocodeInput.fill('Tibet'); |
| 88 | + await page.getByRole('option').first().click(); |
| 89 | + |
| 90 | + await expect(aoiFilter.locator('input[name="searchPolygon"]')).toHaveValue( |
| 91 | + /POINT\(88\.0439 31\.5534\)/, |
| 92 | + ); |
| 93 | + await expect(geocodeInput).toHaveValue(/Tibet Autonomous Region.*China/); |
| 94 | + |
| 95 | + const responsePromise = waitForASFAPIResponse(page); |
| 96 | + await page |
| 97 | + .locator('#mat-button-toggle-8-button') |
| 98 | + .getByRole('button', { name: 'SEARCH' }) |
| 99 | + .click(); |
| 100 | + await responsePromise; |
| 101 | + |
| 102 | + await expect(page.locator('mat-card-header').first()).toBeVisible(); |
| 103 | +}); |
| 104 | + |
| 105 | +test('Place name geocode pans the map to the entered location', async ({ |
| 106 | + page, |
| 107 | +}) => { |
| 108 | + await mockGeocoding(page); |
| 109 | + await page.goto('/'); |
| 110 | + |
| 111 | + const aoiFilter = page.locator('app-aoi-filter'); |
| 112 | + await aoiFilter.locator('.additional-aoi-toggle').click(); |
| 113 | + |
| 114 | + const geocodeInput = aoiFilter |
| 115 | + .locator('app-geocode-selector') |
| 116 | + .getByLabel('Search for a location'); |
| 117 | + await geocodeInput.fill('Big Bear Lake'); |
| 118 | + await page.getByRole('option').first().click(); |
| 119 | + |
| 120 | + await expect(aoiFilter.locator('input[name="searchPolygon"]')).toHaveValue( |
| 121 | + /POINT\(-116\.9115 34\.2437\)/, |
| 122 | + ); |
| 123 | + await expect(geocodeInput).toHaveValue( |
| 124 | + /Big Bear Lake.*California.*United States/, |
| 125 | + ); |
| 126 | + |
| 127 | + await expect(page).toHaveURL(/polygon=POINT/); |
| 128 | +}); |
| 129 | + |
| 130 | +test('Geocoded place name is cleared when AOI is manually updated', async ({ |
| 131 | + page, |
| 132 | +}) => { |
| 133 | + await mockGeocoding(page); |
| 134 | + await page.goto('/'); |
| 135 | + await page.getByRole('button', { name: 'Sentinel-' }).click(); |
| 136 | + await page.getByRole('menuitem', { name: 'S1 Burst' }).click(); |
| 137 | + |
| 138 | + const aoiFilter = page.locator('app-aoi-filter'); |
| 139 | + await aoiFilter.locator('.additional-aoi-toggle').click(); |
| 140 | + |
| 141 | + const geocodeInput = aoiFilter |
| 142 | + .locator('app-geocode-selector') |
| 143 | + .getByLabel('Search for a location'); |
| 144 | + await geocodeInput.fill('Sierra Le'); |
| 145 | + await page.getByRole('option').nth(1).click(); |
| 146 | + |
| 147 | + await expect(aoiFilter.locator('input[name="searchPolygon"]')).toHaveValue( |
| 148 | + /POINT\(-77\.3788 25\.0113\)/, |
| 149 | + ); |
| 150 | + await expect(geocodeInput).toHaveValue( |
| 151 | + /Sierra Leone Avenue.*Nassau.*Bahamas/, |
| 152 | + ); |
| 153 | + |
| 154 | + await aoiFilter |
| 155 | + .locator('textarea[name="searchPolygonLarge"]') |
| 156 | + .fill('POINT(-120.6999 38.3044)'); |
| 157 | + |
| 158 | + const responsePromise = waitForASFAPIResponse(page); |
| 159 | + await page |
| 160 | + .locator('#mat-button-toggle-8-button') |
| 161 | + .getByRole('button', { name: 'SEARCH' }) |
| 162 | + .click(); |
| 163 | + await responsePromise; |
| 164 | + |
| 165 | + await aoiFilter.locator('.additional-aoi-toggle').click(); |
| 166 | + await expect(geocodeInput).toHaveValue(''); |
| 167 | +}); |
0 commit comments