1 const assert = require('assert');
3 describe('Reverse Page', function () {
6 describe('No search', function () {
7 before(async function () {
8 page = await browser.newPage();
9 await page.goto('http://localhost:9999/reverse.html');
12 after(async function () {
16 it('should allow switching coordinates', async function () {
17 let lat_handle = await page.$('input[name=lat]');
18 let lon_handle = await page.$('input[name=lon]');
20 assert.equal(await lat_handle.evaluate(node => node.value), '');
21 assert.equal(await lon_handle.evaluate(node => node.value), '');
23 await page.click('#switch-coords');
25 assert.equal(await lat_handle.evaluate(node => node.value), '');
26 assert.equal(await lon_handle.evaluate(node => node.value), '');
28 await page.type('input[name=lat]', '5');
29 await page.type('input[name=lon]', '10');
30 await page.click('#switch-coords');
32 assert.equal(await lat_handle.evaluate(node => node.value), 10);
33 assert.equal(await lon_handle.evaluate(node => node.value), 5);
37 describe('With search', function () {
38 before(async function () {
39 page = await browser.newPage();
40 await page.goto('http://localhost:9999/reverse.html');
41 await page.type('input[name=lat]', '27.1750090510034');
42 await page.type('input[name=lon]', '78.04209025');
43 await page.click('button[type=submit]');
44 await page.waitForSelector('#searchresults');
47 after(async function () {
51 it('should return single result', async function () {
52 let results_count = await page.$$eval('#searchresults .result', elements => elements.length);
54 assert.deepStrictEqual(results_count, 1);
57 it('should display a map', async function () {
58 await page.waitForSelector('#map');
59 assert.equal((await page.$$('#map')).length, 1);
62 it('should redirect to details page on clicking details button', async function () {
64 let results = await page.$$('#searchresults .result a');
66 await results[0].click();
67 await page.waitForNavigation();
69 current_url = new URL(await page.url());
71 assert.deepStrictEqual(current_url.pathname, '/details.html');