mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-07 22:15:45 +01:00
move getQueryStringFromLocation to ui-components
This commit is contained in:
@@ -22,6 +22,7 @@ export { default as ProtectedRoute } from "./ProtectedRoute.js";
|
||||
export { default as Help } from "./Help";
|
||||
export { default as HelpIcon } from "./HelpIcon";
|
||||
export { default as Tooltip } from "./Tooltip";
|
||||
// TODO do we need this? getPageFromMatch is already exported by urls
|
||||
export { getPageFromMatch } from "./urls";
|
||||
export { default as Autocomplete} from "./Autocomplete";
|
||||
export { default as BranchSelector } from "./BranchSelector";
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
// @flow
|
||||
import queryString from "query-string";
|
||||
|
||||
export const contextPath = window.ctxPath || "";
|
||||
|
||||
export function withContextPath(path: string) {
|
||||
@@ -27,3 +29,7 @@ export function getPageFromMatch(match: any) {
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
export function getQueryStringFromLocation(location: any) {
|
||||
return location.search ? queryString.parse(location.search).q : undefined;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// @flow
|
||||
import {concat, getPageFromMatch, withEndingSlash} from "./urls";
|
||||
import { concat, getPageFromMatch, getQueryStringFromLocation, withEndingSlash } from "./urls";
|
||||
|
||||
describe("tests for withEndingSlash", () => {
|
||||
|
||||
@@ -47,3 +47,28 @@ describe("tests for getPageFromMatch", () => {
|
||||
expect(getPageFromMatch(match)).toBe(42);
|
||||
});
|
||||
});
|
||||
|
||||
describe("tests for getQueryStringFromLocation", () => {
|
||||
|
||||
function createLocation(search: string) {
|
||||
return {
|
||||
search
|
||||
};
|
||||
}
|
||||
|
||||
it("should return the query string", () => {
|
||||
const location = createLocation("?q=abc");
|
||||
expect(getQueryStringFromLocation(location)).toBe("abc");
|
||||
});
|
||||
|
||||
it("should return query string from multiple parameters", () => {
|
||||
const location = createLocation("?x=a&y=b&q=abc&z=c");
|
||||
expect(getQueryStringFromLocation(location)).toBe("abc");
|
||||
});
|
||||
|
||||
it("should return undefined if q is not available", () => {
|
||||
const location = createLocation("?x=a&y=b&z=c");
|
||||
expect(getQueryStringFromLocation(location)).toBeUndefined();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user