nakarte

Source code of https://map.sikmir.ru (fork)
git clone git://git.sikmir.ru/nakarte
Log | Files | Refs | LICENSE

test_search_links.js (11912B)


      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://yandex.ru/maps/-/CCQpqZXJCB',
     37         [{title: 'Yandex map view', latlng: {lat: 49.219896, lng: 16.548629}, zoom: 14}],
     38     ],
     39     [
     40         'https://yandex.ru/maps/-/CCQpqZdgpA',
     41         [{title: 'Yandex map view', latlng: {lat: 49.219896, lng: 16.548629}, zoom: 14}],
     42     ],
     43     [
     44         'https://yandex.ru/maps/-/CCQpqZhrsB',
     45         [{title: 'Yandex map view', latlng: {lat: 49.219896, lng: 16.548629}, zoom: 14}],
     46     ],
     47     [
     48         'https://www.openstreetmap.org/#map=14/49.2199/16.5486',
     49         [{title: 'OpenStreetMap view', latlng: {lat: 49.2199, lng: 16.5486}, zoom: 14}],
     50     ],
     51     [
     52         'https://en.mapy.cz/turisticka?x=16.5651083&y=49.2222502&z=14',
     53         [{title: 'Mapy.cz view', latlng: {lat: 49.2222502, lng: 16.5651083}, zoom: 14}],
     54     ],
     55     [
     56         '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
     57         [{title: 'OpenStreetMap view', latlng: {lat: 55.56647, lng: 38.87365}, zoom: 17}],
     58     ],
     59     [
     60         '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
     61         [
     62             {title: 'Google map - Nerskoye Ozero', latlng: {lat: 56.0826073, lng: 37.388256}, zoom: 14},
     63             {title: 'Google map view', latlng: {lat: 56.0836099, lng: 37.3849634}, zoom: 16},
     64         ],
     65     ],
     66     [
     67         '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
     68         [
     69             {title: 'Google map - Москва, Россия', latlng: {lat: 55.755826, lng: 37.6173}, zoom: 14},
     70             {title: 'Google map view', latlng: {lat: 55.5807481, lng: 36.8251331}, zoom: 9},
     71         ],
     72     ],
     73     [
     74         '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
     75         [
     76             {title: 'Google map - Vavřinecká, 514 01 Jilemnice', latlng: {lat: 50.6092632, lng: 15.5045576}, zoom: 14},
     77             {title: 'Google map view', latlng: {lat: 50.6092632, lng: 15.5023689}, zoom: 17},
     78         ],
     79     ],
     80     [
     81         'https://www.google.com/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://maps.google.com/maps?q=49.223089,16.554547&ll=49.223089,16.554547&z=16',
     86         [{title: 'Google map view', latlng: {lat: 49.223089, lng: 16.554547}, zoom: 17}],
     87     ],
     88     [
     89         'https://www.google.com/maps?q=loc:-49.1817864,-16.5771214',
     90         [{title: 'Google map view', latlng: {lat: -49.1817864, lng: -16.5771214}, zoom: 17}],
     91     ],
     92     [
     93         'https://www.google.ru/maps?q=loc:-49.1817864,-16.5771214',
     94         [{title: 'Google map view', latlng: {lat: -49.1817864, lng: -16.5771214}, zoom: 17}],
     95     ],
     96     [
     97         'https://www.google.com/maps/@49.1906435,16.5429962,14z?q=loc:49.1817864,16.5771214',
     98         [{title: 'Google map view', latlng: {lat: 49.1906435, lng: 16.5429962}, zoom: 14}],
     99     ],
    100     [
    101         '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
    102         [
    103             {title: 'Google map - Nerskoye Ozero', latlng: {lat: 56.0826073, lng: 37.388256}, zoom: 14},
    104             {title: 'Google map view', latlng: {lat: 56.0836099, lng: 37.3849634}, zoom: 16},
    105         ],
    106     ],
    107     [
    108         '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
    109         [{title: 'Google map - Nerskoye Ozero', latlng: {lat: 56.0826073, lng: 37.388256}, zoom: 14}],
    110     ],
    111     [
    112         'https://www.google.com/maps/place/Nerskoye+Ozero/@56.0836099,37.3849634,16z/', // eslint-disable-line max-len
    113         [{title: 'Google map view', latlng: {lat: 56.0836099, lng: 37.3849634}, zoom: 16}],
    114     ],
    115     [
    116         '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
    117         [{title: 'Google map view', latlng: {lat: 56.0836099, lng: 37.3849634}, zoom: 16}],
    118     ],
    119     [
    120         '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
    121         [{title: 'Google map view', latlng: {lat: 48.6514614, lng: 16.9945421}, zoom: 16}],
    122     ],
    123     [
    124         'https://nakarte.me/#m=11/49.44893/16.59897&l=O',
    125         [{title: 'Nakarte view', latlng: {lat: 49.44893, lng: 16.59897}, zoom: 11}],
    126     ],
    127     [
    128         'https://nakarte.me/#l=O&m=11/49.44893/16.59897',
    129         [{title: 'Nakarte view', latlng: {lat: 49.44893, lng: 16.59897}, zoom: 11}],
    130     ],
    131     [
    132         'https://example.com/#l=O&m=11/49.44893/16.59897',
    133         [{title: 'Nakarte view', latlng: {lat: 49.44893, lng: 16.59897}, zoom: 11}],
    134     ],
    135     [
    136         'https://en.mapy.cz/s/favepemeko',
    137         [{title: 'Mapy.cz view', latlng: {lat: 49.4113109, lng: 16.8975623}, zoom: 11}],
    138     ],
    139     [
    140         'https://en.mapy.cz/s/lucacunomo',
    141         [{title: 'Mapy.cz view', latlng: {lat: 49.4113109, lng: 16.8975623}, zoom: 11}],
    142     ],
    143     [
    144         'https://en.mapy.cz/s/mepevemazo',
    145         [{title: 'Mapy.cz view', latlng: {lat: 50.1592323, lng: 16.8245081}, zoom: 12}],
    146     ],
    147     [
    148         'https://goo.gl/maps/cJ8wwQi9oMYM9yiy6',
    149         [{title: 'Google map view', latlng: {lat: 49.0030846, lng: 15.2993434}, zoom: 14}],
    150     ],
    151     [
    152         'https://goo.gl/maps/ZvjVBY78HUP8HjQi6',
    153         [
    154             {title: 'Google map - 561 69 Dolní Morava', latlng: {lat: 50.1223171, lng: 16.7995866}, zoom: 14},
    155             {title: 'Google map view', latlng: {lat: 50.1568257, lng: 16.754047}, zoom: 12},
    156         ],
    157     ],
    158     [
    159         'https://goo.gl/maps/iMv4esLL1nwF9yns7',
    160         [
    161             {title: 'Google map - 561 69 Dolní Morava', latlng: {lat: 50.1223171, lng: 16.7995866}, zoom: 14},
    162             {title: 'Google map view', latlng: {lat: 50.1568257, lng: 16.754047}, zoom: 12},
    163         ],
    164     ],
    165     [
    166         'http://openstreetmap.ru/?mapid=497235296#map=12/60.9426/29.849&layer=C',
    167         [{title: 'OpenStreetMap view', latlng: {lat: 60.9426, lng: 29.849}, zoom: 12}],
    168     ],
    169 ].forEach(function ([query, expectedResults]) {
    170     test(`Parse link ${query}`, async function () {
    171         this.timeout(10000);
    172         assert.isTrue(links.isOurQuery(query));
    173         const result = await links.search(query);
    174         assert.notProperty(result, 'error');
    175         assert.property(result, 'results');
    176         const actualResults = result.results.map((item) => ({
    177             title: item.title,
    178             latlng: {lat: item.latlng.lat, lng: item.latlng.lng},
    179             zoom: item.zoom,
    180         }));
    181         assert.deepEqual(expectedResults, actualResults);
    182     });
    183 });
    184 
    185 suite('LinksProvider - parse invalid links');
    186 [
    187     ['https://', 'Invalid link'],
    188     ['http://', 'Invalid link'],
    189     ['https://example.com', 'Unsupported link'],
    190     ['https://yandex.ru/maps/', 'Invalid coordinates in Yandex link'],
    191     ['https://yandex.ru/maps/10509/brno/?ll=16.548629%2C149.219896&z=14', 'Invalid coordinates in Yandex link'],
    192     [
    193         'https://static-maps.yandex.ru/1.x/?lang=ru_RU&size=520%2C440&l=sat%2Cskl&ll=16.548629%2C49.219896',
    194         'Invalid coordinates in Yandex link',
    195     ],
    196     ['https://en.mapy.cz/turisticka?x=16.5651083&y=49.2222502&z=', 'Invalid coordinates in Mapy.cz link'],
    197     ['https://www.google.com/maps', 'Invalid coordinates in Google link'],
    198     ['https://www.google.com/maps/@99.1906435,16.5429962,14z', 'Invalid coordinates in Google link'],
    199     ['https://www.google.com/maps/@49.1906435,190.5429962,14z', 'Invalid coordinates in Google link'],
    200     ['https://www.google.com/maps/@49.1906435,19.5429962,45z', 'Invalid coordinates in Google link'],
    201     ['https://www.google.com/maps?q=loc:49.1817864,', 'Invalid coordinates in Google link'],
    202     ['https://www.google.com/maps?q=loc:49.1817864', 'Invalid coordinates in Google link'],
    203     ['https://www.google.com/maps?q=loc:4', 'Invalid coordinates in Google link'],
    204     ['https://www.google.com/maps?q=loc:', 'Invalid coordinates in Google link'],
    205     ['https://www.google.com/maps?q=', 'Invalid coordinates in Google link'],
    206     ['https://www.google.com/maps?q', 'Invalid coordinates in Google link'],
    207     ['https://www.google.com/maps?', 'Invalid coordinates in Google link'],
    208     ['https://www.google.com/maps?q=loc:99.1817864,16.5771214', 'Invalid coordinates in Google link'],
    209     ['https://www.google.com/maps?q=loc:49.1817864,196.5771214', 'Invalid coordinates in Google link'],
    210     ['https://nakarte.me/', 'Invalid coordinates in Nakarte link'],
    211     ['https://nakarte.me/#l=O', 'Invalid coordinates in Nakarte link'],
    212     ['https://example.com/#l=O&m=11/49.44893/', 'Unsupported link'],
    213     ['https://example.com/#l=O&m=99/49.44893/52.5547', 'Unsupported link'],
    214     ['https://en.mapy.cz/s/lucacunom', 'Broken Mapy.cz short link'],
    215     ['https://goo.gl/maps/ZvjVBY78HUP8HjQi', 'Broken Google short link'],
    216     // ['https://yandex.ru/maps/-/CCQpqZXJ', 'Broken Yandex short link'], // Yandex returns good result for broken link
    217 ].forEach(function ([query, expectedError]) {
    218     test(`Invalid link ${query}`, async function () {
    219         assert.isTrue(links.isOurQuery(query));
    220         const result = await links.search(query);
    221         assert.notProperty(result, 'results');
    222         assert.propertyVal(result, 'error', expectedError);
    223     });
    224 });
    225 
    226 suite('LinksProvider - not links');
    227 ['abc', 'http:/', 'https:/', 'https:/'].forEach(function (query) {
    228     test(`Not a link ${query}`, function () {
    229         assert.isFalse(links.isOurQuery(query));
    230     });
    231 });