Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed switch parsing syntax issue for dynamic switches #458

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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