|
|
|
@ -10,6 +10,7 @@ import { getKcContextFromWindow } from "./getKcContextFromWindow";
|
|
|
|
|
import { pathJoin } from "../../bin/tools/pathJoin";
|
|
|
|
|
import { pathBasename } from "../tools/pathBasename";
|
|
|
|
|
import { mockTestingResourcesCommonPath } from "../../bin/mockTestingResourcesPath";
|
|
|
|
|
import { symToStr } from "tsafe/symToStr";
|
|
|
|
|
|
|
|
|
|
export function getKcContext<KcContextExtended extends { pageId: string } = never>(params?: {
|
|
|
|
|
mockPageId?: ExtendsKcContextBase<KcContextExtended>["pageId"];
|
|
|
|
@ -17,9 +18,19 @@ export function getKcContext<KcContextExtended extends { pageId: string } = neve
|
|
|
|
|
}): { kcContext: ExtendsKcContextBase<KcContextExtended> | undefined } {
|
|
|
|
|
const { mockPageId, mockData } = params ?? {};
|
|
|
|
|
|
|
|
|
|
if (mockPageId !== undefined) {
|
|
|
|
|
const realKcContext = getKcContextFromWindow<KcContextExtended>();
|
|
|
|
|
|
|
|
|
|
if (mockPageId !== undefined && realKcContext === undefined) {
|
|
|
|
|
//TODO maybe trow if no mock fo custom page
|
|
|
|
|
|
|
|
|
|
console.log(
|
|
|
|
|
[
|
|
|
|
|
`%cKeycloakify: ${symToStr({ mockPageId })} set to ${mockPageId}.`,
|
|
|
|
|
`If assets are missing make sure you have built your Keycloak theme at least once.`
|
|
|
|
|
].join(" "),
|
|
|
|
|
"background: red; color: yellow; font-size: medium"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const kcContextDefaultMock = kcContextMocks.find(({ pageId }) => pageId === mockPageId);
|
|
|
|
|
|
|
|
|
|
const partialKcContextCustomMock = mockData?.find(({ pageId }) => pageId === mockPageId);
|
|
|
|
@ -106,13 +117,15 @@ export function getKcContext<KcContextExtended extends { pageId: string } = neve
|
|
|
|
|
return { kcContext };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const kcContext = getKcContextFromWindow<KcContextExtended>();
|
|
|
|
|
if (realKcContext === undefined) {
|
|
|
|
|
return { "kcContext": undefined };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (kcContext !== undefined) {
|
|
|
|
|
const { url } = kcContext;
|
|
|
|
|
{
|
|
|
|
|
const { url } = realKcContext;
|
|
|
|
|
|
|
|
|
|
url.resourcesCommonPath = pathJoin(url.resourcesPath, pathBasename(mockTestingResourcesCommonPath));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return { kcContext };
|
|
|
|
|
return { "kcContext": realKcContext };
|
|
|
|
|
}
|
|
|
|
|