Trim search string before use

The `window.location.search` string includes the "?" symbol.  Without this change, `createFromQueryData` only works if the "renderer" parameter is not in first position (see 4037bafc45).
This commit is contained in:
Tim Schaub
2013-01-17 13:05:47 -07:00
parent 8d9ac88db7
commit 141e5aa9fc
2 changed files with 51 additions and 2 deletions

View File

@@ -8,6 +8,54 @@ goog.require('ol.View2D');
goog.require('ol.layer.TileLayer');
goog.require('ol.source.XYZ');
describe('ol.RendererHints', function() {
describe('#createFromQueryData()', function() {
var savedGoogGlobal;
beforeEach(function() {
savedGoogGlobal = goog.global;
goog.global = {};
});
afterEach(function() {
goog.global = savedGoogGlobal;
});
it('returns defaults when no query string', function() {
goog.global.location = {search: ''};
var hints = ol.RendererHints.createFromQueryData();
expect(hints).toBe(ol.DEFAULT_RENDERER_HINTS);
});
it('returns defaults when no "renderer" or "renderers"', function() {
goog.global.location = {search: '?foo=bar'};
var hints = ol.RendererHints.createFromQueryData();
expect(hints).toBe(ol.DEFAULT_RENDERER_HINTS);
});
it('returns array of one for "renderer"', function() {
goog.global.location = {search: '?renderer=bogus'};
var hints = ol.RendererHints.createFromQueryData();
expect(hints).toEqual(['bogus']);
});
it('accepts comma delimited list for "renderers"', function() {
goog.global.location = {search: '?renderers=one,two'};
var hints = ol.RendererHints.createFromQueryData();
expect(hints).toEqual(['one', 'two']);
});
it('works with "renderer" in second position', function() {
goog.global.location = {search: '?foo=bar&renderer=one'};
var hints = ol.RendererHints.createFromQueryData();
expect(hints).toEqual(['one']);
});
});
});
describe('ol.Map', function() {
describe('dispose', function() {