mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-07 22:15:45 +01:00
Remember Path when switching to commits or file search
The path gets remembered by a query parameter. Using React state to remember the current path has two downsides. First you would need to wrap the components in a context and store the current state there. Second the remembered state gets lost by refreshing the state. By using a query parameter those two downside get avoided. Committed-by: Thomas Zerr<thomas.zerr@cloudogu.com> Co-authored-by: Thomas Zerr<thomas.zerr@cloudogu.com> Pushed-by: Thomas Zerr<thomas.zerr@cloudogu.com>
This commit is contained in:
@@ -24,7 +24,9 @@
|
||||
|
||||
import {
|
||||
concat,
|
||||
createPrevSourcePathQuery,
|
||||
getNamespaceAndPageFromMatch,
|
||||
getPrevSourcePathFromLocation,
|
||||
getQueryStringFromLocation,
|
||||
getValueStringFromLocationByKey,
|
||||
withEndingSlash,
|
||||
@@ -143,3 +145,32 @@ describe("tests for getValueStringFromLocationByKey", () => {
|
||||
expect(getValueStringFromLocationByKey(location, "namespace")).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("tests for getPrevSourcePathFromLocation", () => {
|
||||
it("should return the value string", () => {
|
||||
const location = { search: "?prevSourcePath=src%2Fsub%25%2Ffile%26%252F.abc" };
|
||||
expect(getPrevSourcePathFromLocation(location)).toBe("src/sub%/file&%2F.abc");
|
||||
});
|
||||
|
||||
it("should return undefined, because query parameter is missing", () => {
|
||||
const location = { search: "?q=abc" };
|
||||
expect(getPrevSourcePathFromLocation(location)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("should return undefined, because query parameter is missing", () => {
|
||||
const location = { search: "?q=abc" };
|
||||
expect(getPrevSourcePathFromLocation(location)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("tests for createPrevSourcePathQuery", () => {
|
||||
it("should return empty string if file path is empty", () => {
|
||||
const encodedPath = createPrevSourcePathQuery("");
|
||||
expect(encodedPath).toBe("");
|
||||
});
|
||||
|
||||
it("should return the encoded path as query parameter", () => {
|
||||
const encodedPath = createPrevSourcePathQuery("src/sub%/file&%2F.abc");
|
||||
expect(encodedPath).toBe("prevSourcePath=src%2Fsub%25%2Ffile%26%252F.abc");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user