From a08c33334299ec7c4ad519a7f2112ecc158461f4 Mon Sep 17 00:00:00 2001 From: Maruf Rasully Date: Thu, 12 Dec 2024 13:34:09 +0100 Subject: [PATCH 1/3] 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(); From ca1f47bc942f79ef55c3fa1d834983bc1ae6437e Mon Sep 17 00:00:00 2001 From: Maruf Rasully Date: Thu, 12 Dec 2024 13:35:16 +0100 Subject: [PATCH 2/3] fix: add changset --- .changeset/sweet-doors-sit.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changeset/sweet-doors-sit.md diff --git a/.changeset/sweet-doors-sit.md b/.changeset/sweet-doors-sit.md new file mode 100644 index 00000000..bd1dcde8 --- /dev/null +++ b/.changeset/sweet-doors-sit.md @@ -0,0 +1,7 @@ +--- +"@ui5-language-assistant/context": patch +"vscode-ui5-language-assistant": patch +"@ui5-language-assistant/vscode-ui5-language-assistant-bas-ext": patch +--- + +fix: use latest ui5 version incase of s4 placeholder From 8b3bf53237197a730a4367034827f92b004bcedf Mon Sep 17 00:00:00 2001 From: Maruf Rasully Date: Thu, 12 Dec 2024 13:45:55 +0100 Subject: [PATCH 3/3] fix: format --- packages/context/test/unit/api.test.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/context/test/unit/api.test.ts b/packages/context/test/unit/api.test.ts index 970e602b..9009351c 100644 --- a/packages/context/test/unit/api.test.ts +++ b/packages/context/test/unit/api.test.ts @@ -135,7 +135,10 @@ describe("context", () => { .spyOn(controlIds, "getControlIds") .mockReturnValue(new Map()); // act - const result = await getContext("path/to/xml/file", 'test-model-cache-path'); + const result = await getContext( + "path/to/xml/file", + "test-model-cache-path" + ); // assert expect(getManifestDetailsStub).toHaveBeenCalled(); expect(getManifestStub).toHaveBeenCalled(); @@ -143,7 +146,7 @@ describe("context", () => { expect(getCustomViewIdStub).toHaveBeenCalled(); expect(getYamlDetailsStub).toHaveBeenCalled(); expect(getSemanticModelStub).toHaveBeenCalledWith( - 'test-model-cache-path', + "test-model-cache-path", "OpenUI5", UI5_VERSION_S4_PLACEHOLDER );