From a08c33334299ec7c4ad519a7f2112ecc158461f4 Mon Sep 17 00:00:00 2001 From: Maruf Rasully Date: Thu, 12 Dec 2024 13:34:09 +0100 Subject: [PATCH] fix: use latest version in case of s4 placeholder --- packages/context/src/api.ts | 5 +- packages/context/test/unit/api.test.ts | 81 +++++++++++++++++++++++++- 2 files changed, 82 insertions(+), 4 deletions(-) diff --git a/packages/context/src/api.ts b/packages/context/src/api.ts index f8eef92d..7514b0f1 100644 --- a/packages/context/src/api.ts +++ b/packages/context/src/api.ts @@ -6,7 +6,7 @@ import { } from "./manifest"; import { finAdpdManifestPath } from "./adp-manifest"; import { getServices } from "./services"; -import { Context } from "./types"; +import { Context, UI5_VERSION_S4_PLACEHOLDER } from "./types"; import { getSemanticModel } from "./ui5-model"; import { getYamlDetails } from "./ui5-yaml"; import { getViewFiles } from "./utils/view-files"; @@ -51,7 +51,8 @@ export async function getContext( let manifestPath = manifestDetails.manifestPath; const manifest = await getUI5Manifest(manifestPath); let minUI5Version = manifestDetails.minUI5Version; - if (manifest) { + // if minUi5Version is not S4 placeholder, get it from manifest + if (minUI5Version !== UI5_VERSION_S4_PLACEHOLDER && manifest) { minUI5Version = getMinimumUI5Version(manifest); } diff --git a/packages/context/test/unit/api.test.ts b/packages/context/test/unit/api.test.ts index 8241da08..970e602b 100644 --- a/packages/context/test/unit/api.test.ts +++ b/packages/context/test/unit/api.test.ts @@ -7,7 +7,7 @@ import * as viewFiles from "../../src/utils/view-files"; import * as controlIds from "../../src/utils/control-ids"; import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types"; import { getContext, isContext } from "../../src/api"; -import type { Context } from "../../src/types"; +import { UI5_VERSION_S4_PLACEHOLDER, type Context } from "../../src/types"; import * as projectAccess from "@sap-ux/project-access"; import { OPEN_FRAMEWORK } from "@ui5-language-assistant/constant"; @@ -69,7 +69,84 @@ describe("context", () => { expect(getMinimumUI5VersionSub).toHaveBeenCalled(); expect(getCustomViewIdStub).toHaveBeenCalled(); expect(getYamlDetailsStub).toHaveBeenCalled(); - expect(getSemanticModelStub).toHaveBeenCalled(); + expect(getSemanticModelStub).toHaveBeenCalledWith( + undefined, + "OpenUI5", + "1.126.0" + ); + expect(getServicesStub).toHaveBeenCalled(); + expect(finAdpdManifestPathStub).toHaveBeenCalled(); + expect(getViewFilesStub).toHaveBeenCalled(); + expect(getControlIdsStub).toHaveBeenCalled(); + expect(result).toContainAllKeys([ + "services", + "manifestDetails", + "yamlDetails", + "customViewId", + "ui5Model", + "viewFiles", + "controlIds", + "documentPath", + ]); + }); + it("get context - when minUI5Version is '${sap.ui5.dist.version}'", async () => { + // arrange + const getManifestDetailsStub = jest + .spyOn(manifest, "getManifestDetails") + .mockResolvedValue({ + appId: "", + manifestPath: "", + mainServicePath: "/", + customViews: {}, + flexEnabled: false, + minUI5Version: UI5_VERSION_S4_PLACEHOLDER, + }); + const getManifestStub = jest + .spyOn(manifest, "getUI5Manifest") + .mockResolvedValue({ + minUI5Version: UI5_VERSION_S4_PLACEHOLDER, + }); + const getMinimumUI5VersionSub = jest.spyOn( + projectAccess, + "getMinimumUI5Version" + ); + const getCustomViewIdStub = jest + .spyOn(manifest, "getCustomViewId") + .mockResolvedValue("customViewId"); + const getYamlDetailsStub = jest + .spyOn(ui5Yaml, "getYamlDetails") + .mockResolvedValue({ + framework: OPEN_FRAMEWORK, + version: undefined, + }); + const getSemanticModelStub = jest + .spyOn(ui5Model, "getSemanticModel") + .mockResolvedValue({} as UI5SemanticModel); + const getServicesStub = jest + .spyOn(services, "getServices") + .mockResolvedValue({}); + const finAdpdManifestPathStub = jest + .spyOn(adpManifest, "finAdpdManifestPath") + .mockResolvedValue("/path/to/app/variant"); + const getViewFilesStub = jest + .spyOn(viewFiles, "getViewFiles") + .mockResolvedValue({}); + const getControlIdsStub = jest + .spyOn(controlIds, "getControlIds") + .mockReturnValue(new Map()); + // act + const result = await getContext("path/to/xml/file", 'test-model-cache-path'); + // assert + expect(getManifestDetailsStub).toHaveBeenCalled(); + expect(getManifestStub).toHaveBeenCalled(); + expect(getMinimumUI5VersionSub).not.toHaveBeenCalled(); + expect(getCustomViewIdStub).toHaveBeenCalled(); + expect(getYamlDetailsStub).toHaveBeenCalled(); + expect(getSemanticModelStub).toHaveBeenCalledWith( + 'test-model-cache-path', + "OpenUI5", + UI5_VERSION_S4_PLACEHOLDER + ); expect(getServicesStub).toHaveBeenCalled(); expect(finAdpdManifestPathStub).toHaveBeenCalled(); expect(getViewFilesStub).toHaveBeenCalled();