mirror of
https://github.com/grafana/grafana.git
synced 2025-02-10 15:45:43 -06:00
Urls: Parsing key values will not convert to numbers (#33982)
* Urls: Parsing key values will not convert to numbers * Tests: fixes broken tests * Tests: fixes broken test * Tests: fixes broken test * Chore: forcing drone to rebuild
This commit is contained in:
parent
a735c51202
commit
7a55a6385c
@ -37,16 +37,21 @@ describe('parseKeyValue', () => {
|
||||
|
||||
it('should parse numeric params', () => {
|
||||
const obj = urlUtil.parseKeyValue('num1=12&num2=12.2');
|
||||
expect(obj).toEqual({ num1: 12, num2: 12.2 });
|
||||
expect(obj).toEqual({ num1: '12', num2: '12.2' });
|
||||
});
|
||||
|
||||
it('should not parse empty strinhg as number', () => {
|
||||
it('should not parse empty string as number', () => {
|
||||
const obj = urlUtil.parseKeyValue('num1=&num2=12.2');
|
||||
expect(obj).toEqual({ num1: '', num2: 12.2 });
|
||||
expect(obj).toEqual({ num1: '', num2: '12.2' });
|
||||
});
|
||||
|
||||
it('should parse boolean params', () => {
|
||||
const obj = urlUtil.parseKeyValue('bool1&bool2=true&bool3=false');
|
||||
expect(obj).toEqual({ bool1: true, bool2: true, bool3: false });
|
||||
});
|
||||
|
||||
it('should parse number like params as strings', () => {
|
||||
const obj = urlUtil.parseKeyValue('custom=&custom1=001&custom2=002&custom3');
|
||||
expect(obj).toEqual({ custom: '', custom1: '001', custom2: '002', custom3: true });
|
||||
});
|
||||
});
|
||||
|
@ -2,7 +2,6 @@
|
||||
* @preserve jquery-param (c) 2015 KNOWLEDGECODE | MIT
|
||||
*/
|
||||
|
||||
import { toNumber } from 'lodash';
|
||||
import { ExploreUrlState } from '../types/explore';
|
||||
|
||||
/**
|
||||
@ -156,7 +155,7 @@ export function parseKeyValue(keyValue: string) {
|
||||
|
||||
let parsedVal: any;
|
||||
if (typeof val === 'string' && val !== '') {
|
||||
parsedVal = val === 'true' || val === 'false' ? val === 'true' : toNumber(val);
|
||||
parsedVal = val === 'true' || val === 'false' ? val === 'true' : val;
|
||||
} else {
|
||||
parsedVal = val;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ describe('LocationService', () => {
|
||||
|
||||
expect(locationService.getSearchObject()).toEqual({
|
||||
query1: false,
|
||||
query2: 123,
|
||||
query2: '123',
|
||||
query3: 'text',
|
||||
});
|
||||
});
|
||||
|
@ -85,19 +85,19 @@ describe('AngularLocationWrapper', () => {
|
||||
|
||||
it('search() should accept object', function () {
|
||||
locationService.push('/path/b');
|
||||
wrapper.search({ one: 1, two: true });
|
||||
expect(wrapper.search()).toEqual({ one: 1, two: true });
|
||||
wrapper.search({ one: '1', two: true });
|
||||
expect(wrapper.search()).toEqual({ one: '1', two: true });
|
||||
expect(wrapper.absUrl()).toBe('http://www.domain.com:9877/path/b?one=1&two');
|
||||
});
|
||||
|
||||
it('should copy object', function () {
|
||||
locationService.push('/path/b');
|
||||
const obj: Record<string, any> = { one: 1, two: true, three: null };
|
||||
const obj: Record<string, any> = { one: '1', two: true, three: null };
|
||||
wrapper.search(obj);
|
||||
expect(obj).toEqual({ one: 1, two: true, three: null });
|
||||
expect(obj).toEqual({ one: '1', two: true, three: null });
|
||||
obj.one = 'changed';
|
||||
|
||||
expect(wrapper.search()).toEqual({ one: 1, two: true });
|
||||
expect(wrapper.search()).toEqual({ one: '1', two: true });
|
||||
expect(wrapper.absUrl()).toBe('http://www.domain.com:9877/path/b?one=1&two');
|
||||
});
|
||||
|
||||
@ -117,8 +117,8 @@ describe('AngularLocationWrapper', () => {
|
||||
|
||||
it('should remove multiple parameters', function () {
|
||||
locationService.push('/path/b');
|
||||
wrapper.search({ one: 1, two: true });
|
||||
expect(wrapper.search()).toEqual({ one: 1, two: true });
|
||||
wrapper.search({ one: '1', two: true });
|
||||
expect(wrapper.search()).toEqual({ one: '1', two: true });
|
||||
|
||||
wrapper.search({ one: null, two: null });
|
||||
expect(wrapper.search()).toEqual({});
|
||||
|
@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
||||
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
||||
import Wrapper from './Wrapper';
|
||||
import { configureStore } from '../../store/configureStore';
|
||||
import { Provider } from 'react-redux';
|
||||
@ -52,7 +52,7 @@ describe('Wrapper', () => {
|
||||
|
||||
// At this point url should be initialised to some defaults
|
||||
expect(locationService.getSearchObject()).toEqual({
|
||||
orgId: 1,
|
||||
orgId: '1',
|
||||
left: JSON.stringify(['now-1h', 'now', 'loki', {}]),
|
||||
});
|
||||
expect(datasources.loki.query).not.toBeCalled();
|
||||
@ -74,7 +74,7 @@ describe('Wrapper', () => {
|
||||
|
||||
// We did not change the url
|
||||
expect(locationService.getSearchObject()).toEqual({
|
||||
orgId: 1,
|
||||
orgId: '1',
|
||||
...query,
|
||||
});
|
||||
|
||||
@ -141,7 +141,7 @@ describe('Wrapper', () => {
|
||||
await screen.findByText('elastic Editor input:');
|
||||
expect(datasources.elastic.query).not.toBeCalled();
|
||||
expect(locationService.getSearchObject()).toEqual({
|
||||
orgId: 1,
|
||||
orgId: '1',
|
||||
left: JSON.stringify(['now-1h', 'now', 'elastic', {}]),
|
||||
});
|
||||
});
|
||||
@ -183,7 +183,7 @@ describe('Wrapper', () => {
|
||||
|
||||
// We did not change the url
|
||||
expect(locationService.getSearchObject()).toEqual({
|
||||
orgId: 1,
|
||||
orgId: '1',
|
||||
...query,
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user