maputnik/test/functional/modals/index.js

238 lines
6.7 KiB
JavaScript
Raw Normal View History

2018-01-10 14:19:34 +01:00
var assert = require('assert');
var fs = require("fs");
var wd = require("../../wd-helper");
var config = require("../../config/specs");
var helper = require("../helper");
function closeModal(wdKey) {
const selector = wd.$(wdKey);
2018-01-10 14:19:34 +01:00
browser.waitUntil(function() {
const elem = $(selector);
2019-06-08 07:19:18 +02:00
return elem.isDisplayedInViewport();
2018-01-10 14:19:34 +01:00
});
2019-06-08 07:19:18 +02:00
const closeBtnSelector = $(wd.$(wdKey+".close-modal"));
closeBtnSelector.click();
2018-01-10 14:19:34 +01:00
browser.waitUntil(function() {
return browser.execute((selector) => {
return !document.querySelector(selector);
}, selector);
2018-01-10 14:19:34 +01:00
});
}
describe("modals", function() {
describe("open", function() {
var styleFilePath = __dirname+"/../../example-style.json";
var styleFileData = JSON.parse(fs.readFileSync(styleFilePath));
beforeEach(function() {
browser.url(config.baseUrl+"?debug");
2019-06-08 07:19:18 +02:00
const elem = $(".maputnik-toolbar-link");
elem.waitForExist();
2018-01-10 14:19:34 +01:00
browser.flushReactUpdates();
2019-06-08 07:19:18 +02:00
const elem2 = $(wd.$("nav:open"));
elem2.click();
2018-01-10 14:19:34 +01:00
browser.flushReactUpdates();
});
it("close", function() {
2020-05-31 16:33:09 +02:00
closeModal("modal:open");
2018-01-10 14:19:34 +01:00
});
2019-06-08 17:16:51 +02:00
// "chooseFile" command currently not available for wdio v5 https://github.com/webdriverio/webdriverio/pull/3632
it.skip("upload", function() {
2019-06-08 07:19:18 +02:00
const elem = $("*[type='file']");
elem.waitForExist();
2018-01-10 14:19:34 +01:00
browser.chooseFile("*[type='file']", styleFilePath);
var styleObj = helper.getStyleStore(browser);
assert.deepEqual(styleFileData, styleObj);
});
it("load from url", function() {
var styleFileUrl = helper.getGeoServerUrl("example-style.json");
2020-05-31 16:33:09 +02:00
browser.setValueSafe(wd.$("modal:open.url.input"), styleFileUrl);
2018-01-10 14:19:34 +01:00
2020-05-31 16:33:09 +02:00
const selector = $(wd.$("modal:open.url.button"));
2019-06-08 07:19:18 +02:00
selector.click();
2018-01-10 14:19:34 +01:00
// Allow the network request to happen
// NOTE: Its localhost so this should be fast.
browser.pause(300);
var styleObj = helper.getStyleStore(browser);
assert.deepEqual(styleFileData, styleObj);
});
// TODO: Need to work out how to mock out the end points
it("gallery")
})
2020-05-31 16:33:09 +02:00
describe("shortcuts", function() {
it("open/close", function() {
browser.url(config.baseUrl+"?debug");
const elem = $(".maputnik-toolbar-link");
elem.waitForExist();
browser.flushReactUpdates();
browser.keys(["?"]);
const modalEl = $(wd.$("modal:shortcuts"))
assert(modalEl.isDisplayed());
closeModal("modal:shortcuts");
});
});
2018-01-10 14:19:34 +01:00
describe("export", function() {
beforeEach(function() {
browser.url(config.baseUrl+"?debug");
2019-06-08 07:19:18 +02:00
const elem = $(".maputnik-toolbar-link");
elem.waitForExist();
2018-01-10 14:19:34 +01:00
browser.flushReactUpdates();
2019-06-08 07:19:18 +02:00
const elem2 = $(wd.$("nav:export"));
elem2.click();
2018-01-10 14:19:34 +01:00
browser.flushReactUpdates();
});
it("close", function() {
2020-05-31 16:33:09 +02:00
closeModal("modal:export");
2018-01-10 14:19:34 +01:00
});
// TODO: Work out how to download a file and check the contents
it("download")
2018-04-10 15:23:11 +02:00
2018-01-10 14:19:34 +01:00
})
describe("sources", function() {
it("active sources")
it("public source")
it("add new source")
})
describe("inspect", function() {
it("toggle", function() {
browser.url(config.baseUrl+"?debug&style="+helper.getStyleUrl([
"geojson:example"
]));
2019-06-08 07:19:18 +02:00
browser.acceptAlert();
2018-01-10 14:19:34 +01:00
2019-06-08 07:19:18 +02:00
const selectBox = $(wd.$("nav:inspect", "select"));
selectBox.selectByAttribute('value', "inspect");
2018-01-10 14:19:34 +01:00
})
})
describe("style settings", function() {
beforeEach(function() {
browser.url(config.baseUrl+"?debug");
2019-06-08 07:19:18 +02:00
const elem = $(".maputnik-toolbar-link");
elem.waitForExist();
2018-01-10 14:19:34 +01:00
browser.flushReactUpdates();
2019-06-08 07:19:18 +02:00
const elem2 = $(wd.$("nav:settings"));
elem2.click();
2018-01-10 14:19:34 +01:00
browser.flushReactUpdates();
});
it("name", function() {
2020-05-31 16:33:09 +02:00
browser.setValueSafe(wd.$("modal:settings.name"), "foobar")
const elem = $(wd.$("modal:settings.owner"));
2019-06-08 07:19:18 +02:00
elem.click();
2018-01-10 14:19:34 +01:00
browser.flushReactUpdates();
var styleObj = helper.getStyleStore(browser);
assert.equal(styleObj.name, "foobar");
})
it("owner", function() {
2020-05-31 16:33:09 +02:00
browser.setValueSafe(wd.$("modal:settings.owner"), "foobar")
const elem = $(wd.$("modal:settings.name"));
2019-06-08 07:19:18 +02:00
elem.click();
2018-01-10 14:19:34 +01:00
browser.flushReactUpdates();
var styleObj = helper.getStyleStore(browser);
assert.equal(styleObj.owner, "foobar");
})
it("sprite url", function() {
2020-05-31 16:33:09 +02:00
browser.setValueSafe(wd.$("modal:settings.sprite"), "http://example.com")
const elem = $(wd.$("modal:settings.name"));
2019-06-08 07:19:18 +02:00
elem.click();
2018-01-10 14:19:34 +01:00
browser.flushReactUpdates();
var styleObj = helper.getStyleStore(browser);
assert.equal(styleObj.sprite, "http://example.com");
})
it("glyphs url", function() {
var glyphsUrl = "http://example.com/{fontstack}/{range}.pbf"
2020-05-31 16:33:09 +02:00
browser.setValueSafe(wd.$("modal:settings.glyphs"), glyphsUrl)
const elem = $(wd.$("modal:settings.name"));
2019-06-08 07:19:18 +02:00
elem.click();
2018-01-10 14:19:34 +01:00
browser.flushReactUpdates();
var styleObj = helper.getStyleStore(browser);
assert.equal(styleObj.glyphs, glyphsUrl);
})
it("mapbox access token", function() {
var apiKey = "testing123";
2020-05-31 16:33:09 +02:00
browser.setValueSafe(wd.$("modal:settings.maputnik:mapbox_access_token"), apiKey);
const elem = $(wd.$("modal:settings.name"));
2019-06-08 07:19:18 +02:00
elem.click();
2018-01-10 14:19:34 +01:00
browser.flushReactUpdates();
var styleObj = helper.getStyleStore(browser);
browser.waitUntil(function() {
return styleObj.metadata["maputnik:mapbox_access_token"] == apiKey;
})
})
2018-10-30 20:37:56 +01:00
it("maptiler access token", function() {
2018-01-10 14:19:34 +01:00
var apiKey = "testing123";
2020-05-31 16:33:09 +02:00
browser.setValueSafe(wd.$("modal:settings.maputnik:openmaptiles_access_token"), apiKey);
const elem = $(wd.$("modal:settings.name"));
2019-06-08 07:19:18 +02:00
elem.click();
2018-01-10 14:19:34 +01:00
browser.flushReactUpdates();
var styleObj = helper.getStyleStore(browser);
assert.equal(styleObj.metadata["maputnik:openmaptiles_access_token"], apiKey);
})
2018-10-30 20:37:56 +01:00
it("thunderforest access token", function() {
var apiKey = "testing123";
2020-05-31 16:33:09 +02:00
browser.setValueSafe(wd.$("modal:settings.maputnik:thunderforest_access_token"), apiKey);
const elem = $(wd.$("modal:settings.name"));
2019-06-08 07:19:18 +02:00
elem.click();
2018-10-30 20:37:56 +01:00
browser.flushReactUpdates();
var styleObj = helper.getStyleStore(browser);
assert.equal(styleObj.metadata["maputnik:thunderforest_access_token"], apiKey);
})
2018-10-30 20:06:52 +01:00
it("style renderer", function() {
2020-05-31 16:33:09 +02:00
const selector = $(wd.$("modal:settings.maputnik:renderer"));
2019-06-08 07:19:18 +02:00
selector.selectByAttribute('value', "ol");
2020-05-31 16:33:09 +02:00
const elem = $(wd.$("modal:settings.name"));
2019-06-08 07:19:18 +02:00
elem.click();
2018-01-10 14:19:34 +01:00
browser.flushReactUpdates();
var styleObj = helper.getStyleStore(browser);
2018-10-30 20:06:52 +01:00
assert.equal(styleObj.metadata["maputnik:renderer"], "ol");
2018-01-10 14:19:34 +01:00
})
})
describe("sources", function() {
it("toggle")
})
})