IDEMSInternational / open-app-builder

PLH App Frontend
GNU General Public License v3.0
5 stars 24 forks source link

Feat/plh calc functions #2127

Closed chrismclarke closed 10 months ago

chrismclarke commented 10 months ago

PR Checklist

Description

Building from #2124, creates named calc functions for plh context and adds spec tests

Author Notes

Creates the following functions to use with @calc statements:

plh_add_family(existingFamilies, memberA, memberB,...)

plh_merge_families(existingFamilies, familyAMember, familyBMember)

plh_remove_family_member(existingFamilies, memberA)

See further details in function and test code

Review Notes

I've kept the original code from 2124 for the merge_sub_arrays function, but suggest removing post-merge if not required (once authoring updated)

See example inputs/outputs from the spec test to see if behaves as expected. Feel free to add any more test cases as required (I haven't had a chance to author into any sheets unfortunately)

Git Issues

Closes #2124

Screenshots/Videos

Copy-paste from test code to demonstrate syntax and expected results (can also view in Files changed)

import { PLH_CALC_FUNCTIONS } from "./plh-calc-functions";

/** Testing mock input. Called as function to avoid manipulation across tests */
const MOCK_FAMILES = () => [["Ada", "Blaise"], ["Charles"], ["Daniel", "Eva"]];

/**
 * Unit tests for plh calc functions (do not require angular test runner but implemented here for convenience)
 * yarn ng test --include src\app\shared\components\template\services\template-calc-functions\plh-calc-functions.spec.ts
 */
describe("Template Calc - PLH Functions", () => {
  it("Add family", () => {
    const res = PLH_CALC_FUNCTIONS.plh_add_family(MOCK_FAMILES(), "Friedrich", "Graham", "Hannah");
    expect(res).toEqual([
      ["Ada", "Blaise"],
      ["Charles"],
      ["Daniel", "Eva"],
      ["Friedrich", "Graham", "Hannah"],
    ]);
  });
  it("Merges families", () => {
    const res = PLH_CALC_FUNCTIONS.plh_merge_families(MOCK_FAMILES(), "Daniel", "Ada");
    expect(res).toEqual([["Ada", "Blaise", "Daniel", "Eva"], ["Charles"]]);
  });
  it("Removes family member", () => {
    const res = PLH_CALC_FUNCTIONS.plh_remove_family_member(MOCK_FAMILES(), "Charles");
    expect(res).toEqual([
      ["Ada", "Blaise"],
      ["Daniel", "Eva"],
    ]);
  });
});