/
githubmirror
/
alluxio
Обзор
Документация
Войти
/
githubmirror
/
alluxio
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
webui/common/src/utilities/misc/queryStringUtils.test.tsx
94 строки
3 KB
Jason Tieu
Update Web UI query string utility functions
29 мар 2022, 02:01
Не верифицирован
29 мар 2022, 02:01
4101a3c
Код
Авторство
О чём код?
/* * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 * (the "License"). You may not use this work except in compliance with the License, which is * available at www.apache.org/licenses/LICENSE-2.0 * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied, as more fully set forth in the License. * * See the NOTICE file distributed with this work for information regarding copyright ownership. */ import { createEncodedQueryString, parseQueryString } from './queryStringUtils'; describe('queryStringUtils', () => { describe('createEncodedQueryString', () => { it('single parameter', () => { expect( createEncodedQueryString({ name: 'hello', }), ).toEqual('?name=hello'); }); it('multiple parameters', () => { expect( createEncodedQueryString({ name: 'hello', obj: '56', }), ).toEqual('?name=hello&obj=56'); }); it('parameter with equal sign (=) in value', () => { expect( createEncodedQueryString({ path: 'test/user/path/db=2323', }), ).toEqual('?path=test%2Fuser%2Fpath%2Fdb%3D2323'); }); it('mix parameters', () => { expect( createEncodedQueryString({ name: 'hello', obj: '56', path: 'test/user/path/db=2323', }), ).toEqual('?name=hello&obj=56&path=test%2Fuser%2Fpath%2Fdb%3D2323'); }); }); describe('parseQueryString', () => { it('single parameter', () => { expect(parseQueryString('?name=hello')).toEqual({ name: 'hello', }); }); it('multiple parameters', () => { expect(parseQueryString('?name=hello&obj=56')).toEqual({ name: 'hello', obj: '56', }); }); it('parameter with equal sign (=) in value', () => { expect(parseQueryString('?path=test/user/path/db=2323')).toEqual({ path: 'test/user/path/db=2323', }); }); it('mix parameters', () => { expect(parseQueryString('?name=hello&obj=56&path=test/user/path/db=2323')).toEqual({ name: 'hello', obj: '56', path: 'test/user/path/db=2323', }); }); it('ignore trailing &', () => { expect(parseQueryString('?name=hello&')).toEqual({ name: 'hello', }); }); it('trailing = in value', () => { expect(parseQueryString('?name=hello=')).toEqual({ name: 'hello=', }); }); it('empty parameters', () => { expect(parseQueryString('?=&')).toEqual({}); expect(parseQueryString('?&=')).toEqual({}); expect(parseQueryString('&?=')).toEqual({}); expect(parseQueryString('&=?')).toEqual({}); expect(parseQueryString('=&?')).toEqual({}); expect(parseQueryString('=?&')).toEqual({}); }); it('throw if parameter with missing value', () => { expect(() => parseQueryString('?name=')).toThrow('unable to parse querystring'); }); }); });