test_search_links.js (11342B)
1 import {LinksProvider} from '~/lib/leaflet.control.search/providers/links'; 2 3 const links = new LinksProvider(); 4 5 suite('LinksProvider - parsing valid links'); 6 [ 7 [ 8 'https://www.google.com/maps/@49.1906435,16.5429962,14z', 9 [{title: 'Google map view', latlng: {lat: 49.1906435, lng: 16.5429962}, zoom: 14}], 10 ], 11 [ 12 'https://www.google.com.ua/maps/@49.1809973,61.6591562,5952m/data=!3m1!1e3?hl=ru', 13 [{title: 'Google map view', latlng: {lat: 49.1809973, lng: 61.6591562}, zoom: 14}], 14 ], 15 [ 16 'https://yandex.ru/maps/10509/brno/?ll=16.548629%2C49.219896&z=14', 17 [{title: 'Yandex map view', latlng: {lat: 49.219896, lng: 16.548629}, zoom: 14}], 18 ], 19 [ 20 'https://yandex.ru/maps/?ll=16.548629%2C49.219896&z=14', 21 [{title: 'Yandex map view', latlng: {lat: 49.219896, lng: 16.548629}, zoom: 14}], 22 ], 23 [ 24 'https://yandex.ru/maps/?l=sat&ll=16.843527%2C49.363860&z=13', 25 [{title: 'Yandex map view', latlng: {lat: 49.36386, lng: 16.843527}, zoom: 13}], 26 ], 27 [ 28 'https://yandex.ru/maps/?l=sat%2Cskl&ll=16.843527%2C49.363860&z=13', 29 [{title: 'Yandex map view', latlng: {lat: 49.36386, lng: 16.843527}, zoom: 13}], 30 ], 31 [ 32 'https://static-maps.yandex.ru/1.x/?lang=ru_RU&size=520%2C440&l=sat%2Cskl&z=14&ll=16.548629%2C49.219896', 33 [{title: 'Yandex map view', latlng: {lat: 49.219896, lng: 16.548629}, zoom: 14}], 34 ], 35 [ 36 'https://www.openstreetmap.org/#map=14/49.2199/16.5486', 37 [{title: 'OpenStreetMap view', latlng: {lat: 49.2199, lng: 16.5486}, zoom: 14}], 38 ], 39 [ 40 'https://en.mapy.cz/turisticka?x=16.5651083&y=49.2222502&z=14', 41 [{title: 'Mapy.cz view', latlng: {lat: 49.2222502, lng: 16.5651083}, zoom: 14}], 42 ], 43 [ 44 'https://www.openstreetmap.org/search?query=%D0%BD%D0%B5%D1%80%D1%81%D0%BA%D0%BE%D0%B5%20%D0%BE%D0%B7%D0%B5%D1%80%D0%BE#map=17/55.56647/38.87365', // eslint-disable-line max-len 45 [{title: 'OpenStreetMap view', latlng: {lat: 55.56647, lng: 38.87365}, zoom: 17}], 46 ], 47 [ 48 'https://www.google.com/maps/place/Nerskoye+Ozero/@56.0836099,37.3849634,16z/data=!3m1!4b1!4m5!3m4!1s0x46b5178a0be6c5b1:0xb13c53547e1d966d!8m2!3d56.0826073!4d37.388256', // eslint-disable-line max-len 49 [ 50 {title: 'Google map - Nerskoye Ozero', latlng: {lat: 56.0826073, lng: 37.388256}, zoom: 14}, 51 {title: 'Google map view', latlng: {lat: 56.0836099, lng: 37.3849634}, zoom: 16}, 52 ], 53 ], 54 [ 55 'https://www.google.ru/maps/place/%D0%9C%D0%BE%D1%81%D0%BA%D0%B2%D0%B0,+%D0%A0%D0%BE%D1%81%D1%81%D0%B8%D1%8F/@55.5807481,36.8251331,9z/data=!3m1!4b1!4m5!3m4!1s0x46b54afc73d4b0c9:0x3d44d6cc5757cf4c!8m2!3d55.755826!4d37.6173', // eslint-disable-line max-len 56 [ 57 {title: 'Google map - Москва, Россия', latlng: {lat: 55.755826, lng: 37.6173}, zoom: 14}, 58 {title: 'Google map view', latlng: {lat: 55.5807481, lng: 36.8251331}, zoom: 9}, 59 ], 60 ], 61 [ 62 'https://www.google.com/maps/place/Vav%C5%99ineck%C3%A1,+514+01+Jilemnice/@50.6092632,15.5023689,17z/data=!3m1!4b1!4m5!3m4!1s0x470ebf1b56d0fca9:0xddb7e19a6b1f5828!8m2!3d50.6092632!4d15.5045576', // eslint-disable-line max-len 63 [ 64 {title: 'Google map - Vavřinecká, 514 01 Jilemnice', latlng: {lat: 50.6092632, lng: 15.5045576}, zoom: 14}, 65 {title: 'Google map view', latlng: {lat: 50.6092632, lng: 15.5023689}, zoom: 17}, 66 ], 67 ], 68 [ 69 'https://www.google.com/maps?q=loc:49.1817864,16.5771214', 70 [{title: 'Google map view', latlng: {lat: 49.1817864, lng: 16.5771214}, zoom: 17}], 71 ], 72 [ 73 'https://maps.google.com/maps?q=49.223089,16.554547&ll=49.223089,16.554547&z=16', 74 [{title: 'Google map view', latlng: {lat: 49.223089, lng: 16.554547}, zoom: 17}], 75 ], 76 [ 77 'https://www.google.com/maps?q=loc:-49.1817864,-16.5771214', 78 [{title: 'Google map view', latlng: {lat: -49.1817864, lng: -16.5771214}, zoom: 17}], 79 ], 80 [ 81 'https://www.google.ru/maps?q=loc:-49.1817864,-16.5771214', 82 [{title: 'Google map view', latlng: {lat: -49.1817864, lng: -16.5771214}, zoom: 17}], 83 ], 84 [ 85 'https://www.google.com/maps/@49.1906435,16.5429962,14z?q=loc:49.1817864,16.5771214', 86 [{title: 'Google map view', latlng: {lat: 49.1906435, lng: 16.5429962}, zoom: 14}], 87 ], 88 [ 89 'https://www.google.com/maps/place/Nerskoye+Ozero/@56.0836099,37.3849634,16z/data=!3m1!4b1!4m5!3m4!1s0x46b5178a0be6c5b1:0xb13c53547e1d966d!8m2!3d56.0826073!4d37.388256?q=loc:-49.1817864,-16.5771214', // eslint-disable-line max-len 90 [ 91 {title: 'Google map - Nerskoye Ozero', latlng: {lat: 56.0826073, lng: 37.388256}, zoom: 14}, 92 {title: 'Google map view', latlng: {lat: 56.0836099, lng: 37.3849634}, zoom: 16}, 93 ], 94 ], 95 [ 96 'https://www.google.com/maps/place/Nerskoye+Ozero/data=!3m1!4b1!4m5!3m4!1s0x46b5178a0be6c5b1:0xb13c53547e1d966d!8m2!3d56.0826073!4d37.388256', // eslint-disable-line max-len 97 [{title: 'Google map - Nerskoye Ozero', latlng: {lat: 56.0826073, lng: 37.388256}, zoom: 14}], 98 ], 99 [ 100 'https://www.google.com/maps/place/Nerskoye+Ozero/@56.0836099,37.3849634,16z/', // eslint-disable-line max-len 101 [{title: 'Google map view', latlng: {lat: 56.0836099, lng: 37.3849634}, zoom: 16}], 102 ], 103 [ 104 'https://www.google.com/maps/@56.0836099,37.3849634,16z/data=!3m1!4b1!4m5!3m4!1s0x46b5178a0be6c5b1:0xb13c53547e1d966d!8m2!3d56.0826073!4d37.388256', // eslint-disable-line max-len 105 [{title: 'Google map view', latlng: {lat: 56.0836099, lng: 37.3849634}, zoom: 16}], 106 ], 107 [ 108 'https://www.google.com/maps/@48.6514614,16.9945421,3a,75y,253.17h,90t/data=!3m7!1e1!3m5!1s4MYpvu63gL3ZArPiSohExg!2e0!6shttps:%2F%2Fstreetviewpixels-pa.googleapis.com%2Fv1%2Fthumbnail%3Fpanoid%3D4MYpvu63gL3ZArPiSohExg%26cb_client%3Dmaps_sv.tactile.gps%26w%3D203%26h%3D100%26yaw%3D253.16992%26pitch%3D0%26thumbfov%3D100!7i13312!8i6656', // eslint-disable-line max-len 109 [{title: 'Google map view', latlng: {lat: 48.6514614, lng: 16.9945421}, zoom: 16}], 110 ], 111 [ 112 'https://nakarte.me/#m=11/49.44893/16.59897&l=O', 113 [{title: 'Nakarte view', latlng: {lat: 49.44893, lng: 16.59897}, zoom: 11}], 114 ], 115 [ 116 'https://nakarte.me/#l=O&m=11/49.44893/16.59897', 117 [{title: 'Nakarte view', latlng: {lat: 49.44893, lng: 16.59897}, zoom: 11}], 118 ], 119 [ 120 'https://example.com/#l=O&m=11/49.44893/16.59897', 121 [{title: 'Nakarte view', latlng: {lat: 49.44893, lng: 16.59897}, zoom: 11}], 122 ], 123 [ 124 'https://en.mapy.cz/s/favepemeko', 125 [{title: 'Mapy.cz view', latlng: {lat: 49.4113109, lng: 16.8975623}, zoom: 11}], 126 ], 127 [ 128 'https://en.mapy.cz/s/lucacunomo', 129 [{title: 'Mapy.cz view', latlng: {lat: 49.4113109, lng: 16.8975623}, zoom: 11}], 130 ], 131 [ 132 'https://en.mapy.cz/s/mepevemazo', 133 [{title: 'Mapy.cz view', latlng: {lat: 50.1592323, lng: 16.8245081}, zoom: 12}], 134 ], 135 [ 136 'https://goo.gl/maps/cJ8wwQi9oMYM9yiy6', 137 [{title: 'Google map view', latlng: {lat: 49.0030846, lng: 15.2993434}, zoom: 14}], 138 ], 139 [ 140 'https://goo.gl/maps/ZvjVBY78HUP8HjQi6', 141 [ 142 {title: 'Google map - 561 69 Dolní Morava', latlng: {lat: 50.1223171, lng: 16.7995866}, zoom: 14}, 143 {title: 'Google map view', latlng: {lat: 50.1568257, lng: 16.754047}, zoom: 12}, 144 ], 145 ], 146 [ 147 'https://goo.gl/maps/iMv4esLL1nwF9yns7', 148 [ 149 {title: 'Google map - 561 69 Dolní Morava', latlng: {lat: 50.1223171, lng: 16.7995866}, zoom: 14}, 150 {title: 'Google map view', latlng: {lat: 50.1568257, lng: 16.754047}, zoom: 12}, 151 ], 152 ], 153 [ 154 'http://openstreetmap.ru/?mapid=497235296#map=12/60.9426/29.849&layer=C', 155 [{title: 'OpenStreetMap view', latlng: {lat: 60.9426, lng: 29.849}, zoom: 12}], 156 ], 157 ].forEach(function ([query, expectedResults]) { 158 test(`Parse link ${query}`, async function () { 159 this.timeout(10000); 160 assert.isTrue(links.isOurQuery(query)); 161 const result = await links.search(query); 162 assert.notProperty(result, 'error'); 163 assert.property(result, 'results'); 164 const actualResults = result.results.map((item) => ({ 165 title: item.title, 166 latlng: {lat: item.latlng.lat, lng: item.latlng.lng}, 167 zoom: item.zoom, 168 })); 169 assert.deepEqual(expectedResults, actualResults); 170 }); 171 }); 172 173 suite('LinksProvider - parse invalid links'); 174 [ 175 ['https://', 'Invalid link'], 176 ['http://', 'Invalid link'], 177 ['https://example.com', 'Unsupported link'], 178 ['https://yandex.ru/maps/', 'Invalid coordinates in Yandex link'], 179 ['https://yandex.ru/maps/10509/brno/?ll=16.548629%2C149.219896&z=14', 'Invalid coordinates in Yandex link'], 180 [ 181 'https://static-maps.yandex.ru/1.x/?lang=ru_RU&size=520%2C440&l=sat%2Cskl&ll=16.548629%2C49.219896', 182 'Invalid coordinates in Yandex link', 183 ], 184 ['https://en.mapy.cz/turisticka?x=16.5651083&y=49.2222502&z=', 'Invalid coordinates in Mapy.cz link'], 185 ['https://www.google.com/maps', 'Invalid coordinates in Google link'], 186 ['https://www.google.com/maps/@99.1906435,16.5429962,14z', 'Invalid coordinates in Google link'], 187 ['https://www.google.com/maps/@49.1906435,190.5429962,14z', 'Invalid coordinates in Google link'], 188 ['https://www.google.com/maps/@49.1906435,19.5429962,45z', 'Invalid coordinates in Google link'], 189 ['https://www.google.com/maps?q=loc:49.1817864,', 'Invalid coordinates in Google link'], 190 ['https://www.google.com/maps?q=loc:49.1817864', 'Invalid coordinates in Google link'], 191 ['https://www.google.com/maps?q=loc:4', 'Invalid coordinates in Google link'], 192 ['https://www.google.com/maps?q=loc:', 'Invalid coordinates in Google link'], 193 ['https://www.google.com/maps?q=', 'Invalid coordinates in Google link'], 194 ['https://www.google.com/maps?q', 'Invalid coordinates in Google link'], 195 ['https://www.google.com/maps?', 'Invalid coordinates in Google link'], 196 ['https://www.google.com/maps?q=loc:99.1817864,16.5771214', 'Invalid coordinates in Google link'], 197 ['https://www.google.com/maps?q=loc:49.1817864,196.5771214', 'Invalid coordinates in Google link'], 198 ['https://nakarte.me/', 'Invalid coordinates in Nakarte link'], 199 ['https://nakarte.me/#l=O', 'Invalid coordinates in Nakarte link'], 200 ['https://example.com/#l=O&m=11/49.44893/', 'Unsupported link'], 201 ['https://example.com/#l=O&m=99/49.44893/52.5547', 'Unsupported link'], 202 ['https://en.mapy.cz/s/lucacunom', 'Broken Mapy.cz short link'], 203 ['https://goo.gl/maps/ZvjVBY78HUP8HjQi', 'Broken Google short link'], 204 ].forEach(function ([query, expectedError]) { 205 test(`Invalid link ${query}`, async function () { 206 assert.isTrue(links.isOurQuery(query)); 207 const result = await links.search(query); 208 assert.notProperty(result, 'results'); 209 assert.propertyVal(result, 'error', expectedError); 210 }); 211 }); 212 213 suite('LinksProvider - not links'); 214 ['abc', 'http:/', 'https:/', 'https:/'].forEach(function (query) { 215 test(`Not a link ${query}`, function () { 216 assert.isFalse(links.isOurQuery(query)); 217 }); 218 });