From d99a152350abc67cb0b54f9f8542a923811bc725 Mon Sep 17 00:00:00 2001 From: Mrigank Mehta Date: Mon, 29 Jul 2024 13:23:04 -0400 Subject: [PATCH] Fixed switch parsing syntax issue for dynamic switches --- core/player/src/view/__tests__/view.test.ts | 56 ++++++++++++++++++++- core/player/src/view/parser/utils.ts | 2 +- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/core/player/src/view/__tests__/view.test.ts b/core/player/src/view/__tests__/view.test.ts index 521d33368..2c15674a4 100644 --- a/core/player/src/view/__tests__/view.test.ts +++ b/core/player/src/view/__tests__/view.test.ts @@ -81,7 +81,7 @@ describe("view", () => { expect(updated).toBe(resolved); }); - test("works with no valid switch cases in an array", () => { + test("works with no valid static switch cases in an array", () => { const model = withParser(new LocalModel({}), parseBinding); const evaluator = new ExpressionEvaluator({ model }); const schema = new SchemaController(); @@ -134,6 +134,60 @@ describe("view", () => { }); }); + test("works with no valid dynamic switch cases in an array", () => { + const model = withParser(new LocalModel({}), parseBinding); + const evaluator = new ExpressionEvaluator({ model }); + const schema = new SchemaController(); + + const view = new ViewInstance( + { + id: "test", + type: "view", + title: [ + { + dynamicSwitch: [ + { + case: false, + asset: { + id: "false-case", + type: "text", + value: "some text", + }, + }, + { + case: false, + asset: { + id: "false-case-2", + type: "text", + value: "some text", + }, + }, + ], + }, + ], + }, + { + model, + parseBinding, + evaluator, + schema, + }, + ); + + const pluginOptions = toNodeResolveOptions(view.resolverOptions); + new SwitchPlugin(pluginOptions).apply(view); + new MultiNodePlugin().apply(view); + new StringResolverPlugin().apply(view); + + const resolved = view.update(); + + expect(resolved).toStrictEqual({ + id: "test", + title: [], + type: "view", + }); + }); + it("does not return a field object if the case does not resolve an asset", () => { const model = withParser( new LocalModel({ diff --git a/core/player/src/view/parser/utils.ts b/core/player/src/view/parser/utils.ts index d7fd336b2..1db9b7695 100644 --- a/core/player/src/view/parser/utils.ts +++ b/core/player/src/view/parser/utils.ts @@ -17,7 +17,7 @@ export function hasTemplateValues(obj: any, localKey: string) { /** Check to see if the string is a valid switch key */ export function hasSwitchKey(localKey: string) { - return localKey === ("staticSwitch" || "dynamicSwitch"); + return localKey === "staticSwitch" || localKey === "dynamicSwitch"; } /** Check to see if the string is a valid template key */