import { assert } from "chai" import { Schema } from "@mwater/expressions" import FormComponent from "../src/FormComponent" import ResponseRow from "../src/ResponseRow" import { FormDesign } from "../src/formDesign" import { ResponseData } from "../src/response" describe("FormComponent", function () { const schema = new Schema() const formDesign: FormDesign = { _type: "Form", _schema: 1, name: { _base: "en", en: "Test Form" }, locales: [{ code: "en", name: "English" }], contents: [], calculations: [] } const formCtx: any = { getEntityById: (entityType: string, entityId: string, callback: (entity: any) => void) => callback(null), getEntityByCode: (entityType: string, entityCode: string, callback: (entity: any) => void) => callback(null), getCustomTableRow: async () => null, getAssetById: async () => null } it("uses an injected response row factory", function () { const data: ResponseData = { q1: { value: "answer" } } const customRow = new ResponseRow({ responseData: data, formDesign, schema, getEntityById: formCtx.getEntityById, getEntityByCode: formCtx.getEntityByCode, getCustomTableRow: formCtx.getCustomTableRow, getAssetById: formCtx.getAssetById }) const component = new FormComponent({ formCtx, design: formDesign, data, onDataChange: () => null, schema, createResponseRow: (responseData) => { assert.strictEqual(responseData, data) return customRow } }) assert.strictEqual(component.createResponseRow(data), customRow) }) })