Skip to content

Commit

Permalink
Add utility test for value parser
Browse files Browse the repository at this point in the history
  • Loading branch information
guerler committed Oct 7, 2024
1 parent 4b25bfb commit b5b6e44
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/utilities/parseDefaults.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
export function parseDefaults(inputs) {
let dv = {};
if (inputs) {
inputs.forEach((input) => (dv[input.name] = input.value));
inputs.forEach((input) => {
if (input.name) {
dv[input.name] = input.value || null;
} else {
console.debug("Warning: Detected input element with no name.");
}
});
}
return dv;
}
13 changes: 13 additions & 0 deletions src/utilities/parseDefaults.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { parseDefaults } from "./parseDefaults.js";

test("parse defaults", () => {
expect(
parseDefaults([
{ name: "a", value: "b" },
{ name: "c", value: "d" },
{ name: "e", value: undefined },
{ name: "f" },
{ value: "g" },
]),
).toEqual({ a: "b", c: "d", "e": null, "f": null });
});
2 changes: 1 addition & 1 deletion src/utilities/parseIncoming.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function parseIncoming(config) {
const root = incoming.root || config?.root || "/";
const visualizationId = incoming.visualization_id;
const visualizationPlugin = incoming.visualization_plugin;
const visualizationTitle = incoming.visualization_title || config?.title || "New Chart";
const visualizationTitle = incoming.visualization_title || config?.title || "Unnamed Visualization";

// parse chart dict
let visualizationConfig = incoming.visualization_config || config;
Expand Down

0 comments on commit b5b6e44

Please sign in to comment.