diff --git a/.changeset/sweet-doors-sit.md b/.changeset/sweet-doors-sit.md new file mode 100644 index 000000000..bd1dcde86 --- /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 diff --git a/packages/context/src/api.ts b/packages/context/src/api.ts index f8eef92db..7514b0f15 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 8241da08b..9009351cc 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,87 @@ 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();