Skip to content
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
4 changes: 2 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
suite: [builder-frontend, builder-api, library-api, e2e]
suite: [builder-frontend, builder-api, library-api, examples, e2e]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -25,7 +25,7 @@ jobs:
uses: ./.github/actions/devbox-setup

- name: Cache Maven dependencies
if: matrix.suite != 'builder-frontend'
if: matrix.suite != 'builder-frontend' && matrix.suite != 'examples'
uses: actions/cache@v4
with:
path: ~/.m2/repository
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This is a monorepo for building and publishing benefit eligibility screeners. Ke
- Preferred one-time setup: `bin/install-devbox && devbox run setup`
- In worktrees, agents may create the ignored root `.env` from `.env.example` when needed to run Devbox commands. The preferred setup command above does this automatically.
- Start the development stack: `devbox services up`
- All tests: `devbox run test` (wrapper: `bin/run-all-tests`; accepts `--fail-fast` and suite names `builder-frontend`, `builder-api`, `library-api`, `e2e`)
- All tests: `devbox run test` (wrapper: `bin/run-all-tests`; accepts `--fail-fast` and suite names `builder-frontend`, `builder-api`, `library-api`, `examples`, `e2e`)
- Backend tests: `(cd builder-api && mvn test)`
- Library tests: `(cd library-api && mvn test)`; DMN API tests require a running library service, then `(cd library-api/test/bdt && bru run)`
- Frontend tests: `(cd builder-frontend && npm test)`; frontend build: `(cd builder-frontend && npm run build)`
Expand Down
20 changes: 17 additions & 3 deletions bin/run-all-tests
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
# 1. builder-frontend - Vitest unit tests (npm test)
# 2. builder-api - JVM unit/integration tests (mvn test)
# 3. library-api - JVM unit/integration tests (mvn test)
# 4. e2e - bin/run-e2e-tests, which boots the full dev stack with
# 4. examples - Node tests for the CRM examples (node --test)
# 5. e2e - bin/run-e2e-tests, which boots the full dev stack with
# devbox services and then runs the library-api Bruno
# collection followed by the Playwright suite.
#
# The unit suites run first because they need nothing but npm and Maven, while
# The unit suites run first because they need nothing but Node and Maven, while
# the e2e suite takes exclusive ownership of the local service ports and swaps
# the root emulator-data directory for the e2e fixtures.
#
Expand All @@ -27,7 +28,7 @@ source "$SCRIPT_DIR/functions"

cd "$PROJECT_ROOT"

ALL_SUITES=(builder-frontend builder-api library-api e2e)
ALL_SUITES=(builder-frontend builder-api library-api examples e2e)
FAIL_FAST=0

usage() {
Expand All @@ -42,6 +43,7 @@ Suites:
builder-frontend builder-frontend Vitest tests (npm test)
builder-api builder-api JVM tests (mvn test)
library-api library-api JVM tests (mvn test)
examples CRM example Node tests (node --test)
e2e full dev stack, library-api Bruno collection, Playwright suite

With no suite arguments, all suites run in the order listed above.
Expand Down Expand Up @@ -154,6 +156,10 @@ if suite_selected builder-api || suite_selected library-api; then
require_command mvn
fi

if suite_selected examples; then
require_command node
fi

# The JVM suites read component .env files directly, and bin/run-e2e-tests needs
# the root .env for the Devbox service graph. Create any that are missing from
# the checked-in examples before the first suite runs.
Expand Down Expand Up @@ -195,6 +201,10 @@ run_library_api_suite() {
)
}

run_examples_suite() {
node --test examples/crm/*/tests/*.test.mjs
}

run_e2e_suite() {
bin/run-e2e-tests
}
Expand Down Expand Up @@ -266,6 +276,10 @@ if suite_selected library-api; then
run_suite "library-api" run_library_api_suite
fi

if suite_selected examples; then
run_suite "examples" run_examples_suite
fi

if suite_selected e2e; then
run_suite "e2e" run_e2e_suite
fi
Expand Down
35 changes: 34 additions & 1 deletion builder-frontend/public/integrations/host.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,30 @@ function randomId() {
).join("");
}

/**
* Returns a saved next-steps link if it's one the screener would send: HTTP(S)
* with a hostname (no underscores) and no credentials. Otherwise returns null.
* Validate saved snapshots with this before making a link clickable.
* @param {unknown} value
* @returns {string | null}
*/
export function safeHttpUrl(value) {
if (typeof value !== "string") return null;
let url;
try {
url = new URL(value);
} catch {
return null;
}
return ["http:", "https:"].includes(url.protocol) &&
url.hostname &&
!url.hostname.includes("_") &&
!url.username &&
!url.password
? url.href
: null;
}

/**
* BDT CRM host adapter. Install the listener before navigating the iframe/popup.
* Copy this module into your CRM's source tree if remote modules are restricted.
Expand Down Expand Up @@ -145,7 +169,16 @@ export function createCrmIntegration({
!Array.isArray(message.inputData) &&
typeof message.evaluatedAt === "string"
) {
onResult(message);
// nextSteps is optional: drop a malformed one, never the results.
const { nextSteps, ...rest } = message;
onResult(
nextSteps === undefined ||
(nextSteps &&
typeof nextSteps === "object" &&
!Array.isArray(nextSteps))
? message
: rest,
);
} else if (
message.type === "error" &&
["SCREENER_UNAVAILABLE", "ORIGIN_NOT_ALLOWED"].includes(message.code)
Expand Down
217 changes: 217 additions & 0 deletions builder-frontend/src/components/screener/FormRenderer.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @vitest-environment jsdom
import { createSignal } from "solid-js";
import { render } from "solid-js/web";
import { afterEach, describe, expect, it, vi } from "vitest";
import FormRenderer from "./FormRenderer";
Expand Down Expand Up @@ -31,6 +32,222 @@ describe("FormRenderer host prefill", () => {
document.body.innerHTML = "";
});

it("exports only the currently visible saved content and unregisters on unmount", async () => {
const register = vi.fn();
const container = document.body.appendChild(document.createElement("div"));
dispose = render(
() => (
<FormRenderer
schema={{
type: "default",
id: "next-steps-form",
schemaVersion: 18,
components: [
{
id: "show",
type: "checkbox",
key: "show",
label: "Show instructions",
},
{
id: "next",
type: "next_steps",
conditional: { hide: "=not(show)" },
benefitContent: {
benefit: { eligible: { body: "Saved instructions" } },
},
},
],
}}
formData={() => ({ show: true })}
hiddenQuestionPaths={() => []}
submitForm={() => {}}
registerNextStepsProvider={register}
/>
),
container,
);
await vi.waitFor(() => expect(register).toHaveBeenCalledOnce());
const results = {
benefit: { name: "Benefit", result: "TRUE" as const, check_results: {} },
};
const provider = register.mock.calls[0][0];
expect(provider(results).benefit.body.text).toBe("Saved instructions");
container
.querySelector<HTMLInputElement>('input[type="checkbox"]')!
.click();
// Follows the answers at once, without waiting for form-js to repaint.
expect(provider(results)).toBeUndefined();
dispose();
dispose = undefined;
expect(register).toHaveBeenLastCalledWith(undefined);
});

it("reads visibility from conditions, including groups, while the form re-imports", async () => {
const register = vi.fn();
const [hidden, setHidden] = createSignal<string[]>([]);
const content = (body: string) => ({
benefit: { eligible: { body } },
});
dispose = render(
() => (
<FormRenderer
schema={{
type: "default",
id: "next-steps-groups",
schemaVersion: 18,
components: [
{ id: "city", type: "textfield", key: "city", label: "City" },
{
id: "hiddenGroup",
type: "group",
conditional: { hide: "=true" },
components: [
{
id: "inHidden",
type: "next_steps",
benefitContent: content("Hidden group"),
},
],
},
{
id: "shownGroup",
type: "group",
components: [
{
id: "inShown",
type: "next_steps",
benefitContent: content("Shown group"),
},
],
},
],
}}
formData={() => ({})}
hiddenQuestionPaths={hidden}
submitForm={() => {}}
registerNextStepsProvider={register}
/>
),
document.body.appendChild(document.createElement("div")),
);
await vi.waitFor(() => expect(register).toHaveBeenCalledOnce());
const results = {
benefit: { name: "Benefit", result: "TRUE" as const, check_results: {} },
};
const provider = register.mock.calls[0][0];
expect(provider(results).benefit.body.text).toBe("Shown group");
// Hiding a question re-imports the form; the export must not see a gap.
setHidden(["city"]);
expect(provider(results).benefit.body.text).toBe("Shown group");
});

it("exports visible instructions from a dynamic list with repetition disabled", async () => {
const register = vi.fn();
const container = document.body.appendChild(document.createElement("div"));
dispose = render(
() => (
<FormRenderer
schema={{
type: "default",
id: "single-person",
schemaVersion: 18,
components: [
{
id: "person",
type: "dynamiclist",
path: "person",
isRepeating: false,
components: [
{
id: "show",
type: "checkbox",
key: "show",
label: "Show instructions",
},
{
id: "next",
type: "next_steps",
conditional: { hide: "=not(person.show)" },
benefitContent: {
benefit: {
eligible: { body: "Single-person instructions" },
},
},
},
],
},
],
}}
formData={() => ({ person: { show: true } })}
hiddenQuestionPaths={() => []}
submitForm={() => {}}
registerNextStepsProvider={register}
/>
),
container,
);
await vi.waitFor(() => expect(register).toHaveBeenCalledOnce());
const exported = register.mock.calls[0][0]({
benefit: { name: "Benefit", result: "TRUE", check_results: {} },
});
expect(exported.benefit.body.text).toBe("Single-person instructions");
});

it.each([
[[{ show: false }, { show: true }], "Per item"],
[[{ show: false }], undefined],
])(
"checks Next steps in a repeated group against each item (%j)",
async (people, body) => {
const register = vi.fn();
dispose = render(
() => (
<FormRenderer
schema={{
type: "default",
id: "next-steps-list",
schemaVersion: 18,
components: [
{
id: "people",
type: "dynamiclist",
path: "people",
components: [
{
id: "show",
type: "checkbox",
key: "show",
label: "Show",
},
{
id: "next",
type: "next_steps",
conditional: { hide: "=not(this.show)" },
benefitContent: {
benefit: { eligible: { body: "Per item" } },
},
},
],
},
],
}}
formData={() => ({ people })}
hiddenQuestionPaths={() => []}
submitForm={() => {}}
registerNextStepsProvider={register}
/>
),
document.body.appendChild(document.createElement("div")),
);
await vi.waitFor(() => expect(register).toHaveBeenCalledOnce());
const exported = register.mock.calls[0][0]({
benefit: { name: "Benefit", result: "TRUE", check_results: {} },
});
expect(exported?.benefit.body?.text).toBe(body);
},
);

it("evaluates unknown host answers as null until the user answers them", async () => {
const submitForm = vi.fn();
const container = document.body.appendChild(document.createElement("div"));
Expand Down
Loading
Loading