mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
Refactor AppReduced to use basepath config option
The `admin_basepath` configuration option has been renamed to `basepath` for clarity and consistency. This change affects how the admin base path is accessed and utilized within the `AppReduced` utility. Tests have been updated to reflect this renaming.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { describe, it, expect, beforeEach } from "vitest";
|
import { describe, it, expect, beforeEach } from "vitest";
|
||||||
import { AppReduced, type AppType } from "ui/client/utils/AppReduced";
|
import { AppReduced, type AppType } from "ui/client/utils/AppReduced";
|
||||||
import type { BkndAdminOptions } from "ui/client/BkndProvider";
|
import type { BkndAdminProps } from "ui/Admin";
|
||||||
|
|
||||||
// Import the normalizeAdminPath function for testing
|
// Import the normalizeAdminPath function for testing
|
||||||
// Note: This assumes the function is exported or we need to test it indirectly through public methods
|
// Note: This assumes the function is exported or we need to test it indirectly through public methods
|
||||||
@@ -23,9 +23,9 @@ describe("AppReduced", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("getSettingsPath", () => {
|
describe("getSettingsPath", () => {
|
||||||
it("should return settings path with admin_basepath", () => {
|
it("should return settings path with basepath", () => {
|
||||||
const options: BkndAdminOptions = {
|
const options: BkndAdminProps["config"] = {
|
||||||
admin_basepath: "/admin",
|
basepath: "/admin",
|
||||||
logo_return_path: "/",
|
logo_return_path: "/",
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -35,9 +35,9 @@ describe("AppReduced", () => {
|
|||||||
expect(result).toBe("~/admin/settings");
|
expect(result).toBe("~/admin/settings");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return settings path with empty admin_basepath", () => {
|
it("should return settings path with empty basepath", () => {
|
||||||
const options: BkndAdminOptions = {
|
const options: BkndAdminProps["config"] = {
|
||||||
admin_basepath: "",
|
basepath: "",
|
||||||
logo_return_path: "/",
|
logo_return_path: "/",
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -48,8 +48,8 @@ describe("AppReduced", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should append additional path segments", () => {
|
it("should append additional path segments", () => {
|
||||||
const options: BkndAdminOptions = {
|
const options: BkndAdminProps["config"] = {
|
||||||
admin_basepath: "/admin",
|
basepath: "/admin",
|
||||||
logo_return_path: "/",
|
logo_return_path: "/",
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -60,8 +60,8 @@ describe("AppReduced", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should normalize multiple slashes", () => {
|
it("should normalize multiple slashes", () => {
|
||||||
const options: BkndAdminOptions = {
|
const options: BkndAdminProps["config"] = {
|
||||||
admin_basepath: "//admin//",
|
basepath: "//admin//",
|
||||||
logo_return_path: "/",
|
logo_return_path: "/",
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -71,9 +71,9 @@ describe("AppReduced", () => {
|
|||||||
expect(result).toBe("~/admin/settings/user");
|
expect(result).toBe("~/admin/settings/user");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should handle admin_basepath without leading slash", () => {
|
it("should handle basepath without leading slash", () => {
|
||||||
const options: BkndAdminOptions = {
|
const options: BkndAdminProps["config"] = {
|
||||||
admin_basepath: "admin",
|
basepath: "admin",
|
||||||
logo_return_path: "/",
|
logo_return_path: "/",
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -85,9 +85,9 @@ describe("AppReduced", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("getAbsolutePath", () => {
|
describe("getAbsolutePath", () => {
|
||||||
it("should return absolute path with admin_basepath", () => {
|
it("should return absolute path with basepath", () => {
|
||||||
const options: BkndAdminOptions = {
|
const options: BkndAdminProps["config"] = {
|
||||||
admin_basepath: "/admin",
|
basepath: "/admin",
|
||||||
logo_return_path: "/",
|
logo_return_path: "/",
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -98,8 +98,8 @@ describe("AppReduced", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should return base path when no path provided", () => {
|
it("should return base path when no path provided", () => {
|
||||||
const options: BkndAdminOptions = {
|
const options: BkndAdminProps["config"] = {
|
||||||
admin_basepath: "/admin",
|
basepath: "/admin",
|
||||||
logo_return_path: "/",
|
logo_return_path: "/",
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -110,8 +110,8 @@ describe("AppReduced", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should normalize paths correctly", () => {
|
it("should normalize paths correctly", () => {
|
||||||
const options: BkndAdminOptions = {
|
const options: BkndAdminProps["config"] = {
|
||||||
admin_basepath: "//admin//",
|
basepath: "//admin//",
|
||||||
logo_return_path: "/",
|
logo_return_path: "/",
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -124,8 +124,8 @@ describe("AppReduced", () => {
|
|||||||
|
|
||||||
describe("options getter", () => {
|
describe("options getter", () => {
|
||||||
it("should return merged options with defaults", () => {
|
it("should return merged options with defaults", () => {
|
||||||
const customOptions: BkndAdminOptions = {
|
const customOptions: BkndAdminProps["config"] = {
|
||||||
admin_basepath: "/custom-admin",
|
basepath: "/custom-admin",
|
||||||
logo_return_path: "/custom-home",
|
logo_return_path: "/custom-home",
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -135,27 +135,27 @@ describe("AppReduced", () => {
|
|||||||
expect(options).toEqual({
|
expect(options).toEqual({
|
||||||
basepath: "/",
|
basepath: "/",
|
||||||
logo_return_path: "/custom-home",
|
logo_return_path: "/custom-home",
|
||||||
admin_basepath: "/custom-admin",
|
basepath: "/custom-admin",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should use default logo_return_path when not provided", () => {
|
it("should use default logo_return_path when not provided", () => {
|
||||||
const customOptions: BkndAdminOptions = {
|
const customOptions: BkndAdminProps["config"] = {
|
||||||
admin_basepath: "/admin",
|
basepath: "/admin",
|
||||||
};
|
};
|
||||||
|
|
||||||
appReduced = new AppReduced(mockAppJson, customOptions);
|
appReduced = new AppReduced(mockAppJson, customOptions);
|
||||||
const options = appReduced.options;
|
const options = appReduced.options;
|
||||||
|
|
||||||
expect(options.logo_return_path).toBe("/");
|
expect(options.logo_return_path).toBe("/");
|
||||||
expect(options.admin_basepath).toBe("/admin");
|
expect(options.basepath).toBe("/admin");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("path normalization behavior", () => {
|
describe("path normalization behavior", () => {
|
||||||
it("should normalize duplicate slashes in settings path", () => {
|
it("should normalize duplicate slashes in settings path", () => {
|
||||||
const options: BkndAdminOptions = {
|
const options: BkndAdminProps["config"] = {
|
||||||
admin_basepath: "/admin",
|
basepath: "/admin",
|
||||||
logo_return_path: "/",
|
logo_return_path: "/",
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -166,8 +166,8 @@ describe("AppReduced", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should handle root path normalization", () => {
|
it("should handle root path normalization", () => {
|
||||||
const options: BkndAdminOptions = {
|
const options: BkndAdminProps["config"] = {
|
||||||
admin_basepath: "/",
|
basepath: "/",
|
||||||
logo_return_path: "/",
|
logo_return_path: "/",
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -175,13 +175,13 @@ describe("AppReduced", () => {
|
|||||||
const result = appReduced.getAbsolutePath();
|
const result = appReduced.getAbsolutePath();
|
||||||
|
|
||||||
// The normalizeAdminPath function removes trailing slashes except for root "/"
|
// The normalizeAdminPath function removes trailing slashes except for root "/"
|
||||||
// When admin_basepath is "/", the result is "~/" which becomes "~" after normalization
|
// When basepath is "/", the result is "~/" which becomes "~" after normalization
|
||||||
expect(result).toBe("~");
|
expect(result).toBe("~");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should preserve entity paths ending with slash", () => {
|
it("should preserve entity paths ending with slash", () => {
|
||||||
const options: BkndAdminOptions = {
|
const options: BkndAdminProps["config"] = {
|
||||||
admin_basepath: "/admin",
|
basepath: "/admin",
|
||||||
logo_return_path: "/",
|
logo_return_path: "/",
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -192,8 +192,8 @@ describe("AppReduced", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should remove trailing slashes from non-entity paths", () => {
|
it("should remove trailing slashes from non-entity paths", () => {
|
||||||
const options: BkndAdminOptions = {
|
const options: BkndAdminProps["config"] = {
|
||||||
admin_basepath: "/admin",
|
basepath: "/admin",
|
||||||
logo_return_path: "/",
|
logo_return_path: "/",
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -205,21 +205,21 @@ describe("AppReduced", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("edge cases", () => {
|
describe("edge cases", () => {
|
||||||
it("should handle undefined admin_basepath", () => {
|
it("should handle undefined basepath", () => {
|
||||||
const options: BkndAdminOptions = {
|
const options: BkndAdminProps["config"] = {
|
||||||
logo_return_path: "/",
|
logo_return_path: "/",
|
||||||
};
|
};
|
||||||
|
|
||||||
appReduced = new AppReduced(mockAppJson, options);
|
appReduced = new AppReduced(mockAppJson, options);
|
||||||
const result = appReduced.getSettingsPath();
|
const result = appReduced.getSettingsPath();
|
||||||
|
|
||||||
// When admin_basepath is undefined, it defaults to empty string
|
// When basepath is undefined, it defaults to empty string
|
||||||
expect(result).toBe("~/settings");
|
expect(result).toBe("~/settings");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should handle null path segments", () => {
|
it("should handle null path segments", () => {
|
||||||
const options: BkndAdminOptions = {
|
const options: BkndAdminProps["config"] = {
|
||||||
admin_basepath: "/admin",
|
basepath: "/admin",
|
||||||
logo_return_path: "/",
|
logo_return_path: "/",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user