refactor: replace EditDialog with DashboardCrudFormDialog for companies and quick replies
- Removed the EditDialog component from companies and quick replies. - Integrated DashboardCrudFormDialog to handle form submissions and editing for both entities. - Updated the CompanyPicker to utilize the new form dialog for creating companies. - Introduced DashboardCrudFieldControl for rendering form fields dynamically. - Added utility functions for building form values and normalizing submit values. - Updated tests to cover new form utilities and ensure correct behavior for form submissions.
This commit is contained in:
@@ -88,3 +88,58 @@ describe("normalizeDashboardCrudPageResult", () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("buildDashboardCrudFormValues", () => {
|
||||
it("uses defaults for create forms and item values for edit forms", async () => {
|
||||
const { buildDashboardCrudFormValues } = await loadModule()
|
||||
const fields = [
|
||||
{ name: "title", defaultValue: "Untitled" },
|
||||
{ name: "sortNo", type: "number", defaultValue: "0" },
|
||||
{
|
||||
name: "status",
|
||||
defaultValue: "0",
|
||||
valueFromItem: (item) => String(item.status),
|
||||
},
|
||||
]
|
||||
|
||||
assert.deepEqual(plain(buildDashboardCrudFormValues(fields)), {
|
||||
title: "Untitled",
|
||||
sortNo: "0",
|
||||
status: "0",
|
||||
})
|
||||
assert.deepEqual(
|
||||
plain(buildDashboardCrudFormValues(fields, { title: "Hello", sortNo: 7, status: 1 })),
|
||||
{
|
||||
title: "Hello",
|
||||
sortNo: "7",
|
||||
status: "1",
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("normalizeDashboardCrudSubmitValues", () => {
|
||||
it("trims strings and converts number fields", async () => {
|
||||
const { normalizeDashboardCrudSubmitValues } = await loadModule()
|
||||
const fields = [
|
||||
{ name: "title", trim: true },
|
||||
{ name: "sortNo", type: "number" },
|
||||
{ name: "status", type: "select", valueType: "number" },
|
||||
]
|
||||
|
||||
assert.deepEqual(
|
||||
plain(
|
||||
normalizeDashboardCrudSubmitValues(fields, {
|
||||
title: " Hello ",
|
||||
sortNo: "12",
|
||||
status: "1",
|
||||
})
|
||||
),
|
||||
{
|
||||
title: "Hello",
|
||||
sortNo: 12,
|
||||
status: 1,
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user