Skip to content

Commit

Permalink
Merge pull request #458 from player-ui/switch-parsing-syntax-issue-pl…
Browse files Browse the repository at this point in the history
…aya-9067

Fixed switch parsing syntax issue for dynamic switches
  • Loading branch information
mrigankmg authored Jul 30, 2024
2 parents b2d782d + d99a152 commit 18cdf09
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
56 changes: 55 additions & 1 deletion core/player/src/view/__tests__/view.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion core/player/src/view/parser/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 18cdf09

Please sign in to comment.