@tsed/schema-formio
Version:
Transform Ts.ED Schema & JsonSchema to a valid Formio schema
89 lines (85 loc) • 1.92 kB
text/typescript
import {getFormioSchema} from "../utils/getFormioSchema.js";
import {DataSourceJson} from "./dataSourceJson.js";
import {Select} from "./select.js";
describe("DataSourceJson", () => {
it("should declare datasource", async () => {
class Model {
@Select()
@DataSourceJson([
{
id: "id",
value: "value"
}
])
test: string;
}
expect(await getFormioSchema(Model)).toEqual({
components: [
{
data: {
json: '[{"id":"id","value":"value"}]'
},
dataSrc: "json",
disabled: false,
input: true,
label: "Test",
key: "test",
selectThreshold: 0.3,
type: "select",
validate: {
required: false
},
widget: "choicesjs"
}
],
display: "form",
machineName: "model",
name: "model",
title: "Model",
type: "form",
submissionAccess: [],
access: [],
tags: []
});
});
it("should declare datasource from resolver", async () => {
class Model {
@Select()
@DataSourceJson(() => [
{
id: "id",
value: "value"
}
])
test: string;
}
expect(await getFormioSchema(Model)).toEqual({
components: [
{
data: {
json: '[{"id":"id","value":"value"}]'
},
dataSrc: "json",
disabled: false,
input: true,
label: "Test",
key: "test",
selectThreshold: 0.3,
type: "select",
validate: {
required: false
},
widget: "choicesjs"
}
],
display: "form",
machineName: "model",
name: "model",
title: "Model",
type: "form",
submissionAccess: [],
access: [],
tags: []
});
});
});