Merge pull request #555 from nrenner/profile-default
Fix default profile not selected with hash
This commit is contained in:
commit
0899a1b26e
2 changed files with 65 additions and 1 deletions
|
|
@ -18,7 +18,8 @@ BR.RoutingOptions = L.Evented.extend({
|
||||||
var option = document.createElement('option');
|
var option = document.createElement('option');
|
||||||
option.value = profiles[i];
|
option.value = profiles[i];
|
||||||
option.text = i18next.t('navbar.profile.' + profiles[i]);
|
option.text = i18next.t('navbar.profile.' + profiles[i]);
|
||||||
if (remembered_profile !== null && remembered_profile === profiles[i]) {
|
// set remembered profile, only when no URL hash (assumes fullHash plugin not initialised yet)
|
||||||
|
if (!location.hash && remembered_profile !== null && remembered_profile === profiles[i]) {
|
||||||
option.selected = true;
|
option.selected = true;
|
||||||
remembered_profile_was_selected = true;
|
remembered_profile_was_selected = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
63
tests/control/RoutingOptions.test.js
Normal file
63
tests/control/RoutingOptions.test.js
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
BR = {};
|
||||||
|
$ = require('jquery');
|
||||||
|
i18next = require('i18next');
|
||||||
|
require('bootstrap');
|
||||||
|
require('bootstrap-select');
|
||||||
|
require('leaflet');
|
||||||
|
|
||||||
|
require('../../config.template.js');
|
||||||
|
require('../../js/Util.js');
|
||||||
|
require('../../js/router/BRouter.js');
|
||||||
|
require('../../js/control/RoutingOptions.js');
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
const indexHtmlString = fs.readFileSync('index.html', 'utf8');
|
||||||
|
const indexHtml = new DOMParser().parseFromString(indexHtmlString, 'text/html');
|
||||||
|
|
||||||
|
let defaultProfile;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
document.body = indexHtml.body.cloneNode(true);
|
||||||
|
location.hash = '';
|
||||||
|
// as used in BRouter.getUrlParams
|
||||||
|
defaultProfile = BR.conf.profiles[0];
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Profile selection', () => {
|
||||||
|
test('sets default profile (trekking) when no hash and no localStorage entry', () => {
|
||||||
|
let routingOptions = new BR.RoutingOptions();
|
||||||
|
routingOptions.setOptions({});
|
||||||
|
const profile = routingOptions.getOptions().profile;
|
||||||
|
expect(profile).toEqual(defaultProfile);
|
||||||
|
});
|
||||||
|
|
||||||
|
// defaults are not set in hash, see BRouter.getUrlParams
|
||||||
|
test('sets default profile (trekking) when hash without `profile` param regardless of localStorage', () => {
|
||||||
|
location.hash = '#map=5/50.986/9.822/standard';
|
||||||
|
localStorage.routingprofile = 'shortest';
|
||||||
|
|
||||||
|
let routingOptions = new BR.RoutingOptions();
|
||||||
|
routingOptions.setOptions({});
|
||||||
|
const profile = routingOptions.getOptions().profile;
|
||||||
|
expect(profile).toEqual(defaultProfile);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('sets profile from hash', () => {
|
||||||
|
location.hash = '#map=5/50.986/9.822/standard&profile=fastbike';
|
||||||
|
localStorage.routingprofile = 'shortest';
|
||||||
|
|
||||||
|
let routingOptions = new BR.RoutingOptions();
|
||||||
|
routingOptions.setOptions({ profile: 'fastbike' });
|
||||||
|
const profile = routingOptions.getOptions().profile;
|
||||||
|
expect(profile).toEqual('fastbike');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('sets profile from localStorage when no hash', () => {
|
||||||
|
localStorage.routingprofile = 'shortest';
|
||||||
|
|
||||||
|
let routingOptions = new BR.RoutingOptions();
|
||||||
|
routingOptions.setOptions({});
|
||||||
|
const profile = routingOptions.getOptions().profile;
|
||||||
|
expect(profile).toEqual('shortest');
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue