-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix routing form field input loosing focus on typing (#18381)
Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
- Loading branch information
1 parent
b5bec79
commit ab942ed
Showing
2 changed files
with
175 additions
and
7 deletions.
There are no files selected for viewing
163 changes: 163 additions & 0 deletions
163
packages/app-store/routing-forms/__tests__/uiConfig.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
import type { Settings } from "react-awesome-query-builder"; | ||
import { describe, it, vi, expect } from "vitest"; | ||
|
||
import { | ||
ConfigFor, | ||
withRaqbSettingsAndWidgets, | ||
} from "../components/react-awesome-query-builder/config/uiConfig"; | ||
|
||
// Mock dependencies | ||
vi.mock("../components/react-awesome-query-builder/widgets", () => ({ | ||
default: { | ||
TextWidget: vi.fn(), | ||
TextAreaWidget: vi.fn(), | ||
MultiSelectWidget: vi.fn(), | ||
SelectWidget: vi.fn(), | ||
NumberWidget: vi.fn(), | ||
FieldSelect: vi.fn(), | ||
Conjs: vi.fn(), | ||
Button: vi.fn(), | ||
ButtonGroup: vi.fn(), | ||
Provider: vi.fn(), | ||
}, | ||
})); | ||
|
||
vi.mock("@calcom/ui", () => ({ | ||
EmailField: vi.fn(), | ||
})); | ||
|
||
describe("uiConfig", () => { | ||
const mockConfig = { | ||
widgets: { | ||
text: { | ||
type: "text", | ||
}, | ||
textarea: { | ||
type: "textarea", | ||
}, | ||
number: { | ||
type: "number", | ||
}, | ||
multiselect: { | ||
type: "multiselect", | ||
}, | ||
select: { | ||
type: "select", | ||
}, | ||
phone: { | ||
type: "phone", | ||
}, | ||
email: { | ||
type: "email", | ||
}, | ||
}, | ||
settings: {} as Settings, | ||
}; | ||
|
||
describe("withRaqbSettingsAndWidgets", () => { | ||
it("should add factory functions to all widgets", () => { | ||
const result = withRaqbSettingsAndWidgets({ | ||
config: mockConfig, | ||
configFor: ConfigFor.FormFields, | ||
}); | ||
|
||
// Verify each widget has a factory function | ||
expect(result.widgets.text).toHaveProperty("factory"); | ||
expect(result.widgets.textarea).toHaveProperty("factory"); | ||
expect(result.widgets.number).toHaveProperty("factory"); | ||
expect(result.widgets.multiselect).toHaveProperty("factory"); | ||
expect(result.widgets.select).toHaveProperty("factory"); | ||
expect(result.widgets.phone).toHaveProperty("factory"); | ||
expect(result.widgets.email).toHaveProperty("factory"); | ||
}); | ||
|
||
it("should add render functions to settings", () => { | ||
const result = withRaqbSettingsAndWidgets({ | ||
config: mockConfig, | ||
configFor: ConfigFor.FormFields, | ||
}); | ||
|
||
// Verify settings have all required render functions | ||
expect(result.settings).toHaveProperty("renderField"); | ||
expect(result.settings).toHaveProperty("renderOperator"); | ||
expect(result.settings).toHaveProperty("renderFunc"); | ||
expect(result.settings).toHaveProperty("renderConjs"); | ||
expect(result.settings).toHaveProperty("renderButton"); | ||
expect(result.settings).toHaveProperty("renderButtonGroup"); | ||
expect(result.settings).toHaveProperty("renderProvider"); | ||
}); | ||
|
||
it("should preserve existing widget properties while adding factory", () => { | ||
const configWithExistingProps = { | ||
...mockConfig, | ||
widgets: { | ||
...mockConfig.widgets, | ||
text: { | ||
type: "text", | ||
existingProp: "value", | ||
}, | ||
}, | ||
}; | ||
|
||
const result = withRaqbSettingsAndWidgets({ | ||
config: configWithExistingProps, | ||
configFor: ConfigFor.FormFields, | ||
}); | ||
|
||
expect(result.widgets.text).toHaveProperty("existingProp", "value"); | ||
expect(result.widgets.text).toHaveProperty("factory"); | ||
}); | ||
|
||
it("should set correct placeholder for phone widget", () => { | ||
const result = withRaqbSettingsAndWidgets({ | ||
config: mockConfig, | ||
configFor: ConfigFor.FormFields, | ||
}); | ||
|
||
expect(result.widgets.phone).toHaveProperty("valuePlaceholder", "Enter Phone Number"); | ||
}); | ||
|
||
it("should reuse same component fns for widgets - ensures remounting is not happening", () => { | ||
const configWithExistingProps = { | ||
...mockConfig, | ||
}; | ||
|
||
const result = withRaqbSettingsAndWidgets({ | ||
config: configWithExistingProps, | ||
configFor: ConfigFor.FormFields, | ||
}); | ||
|
||
// @ts-expect-error - TODO: fix this | ||
const textFactory = result.widgets.text.factory; | ||
|
||
const result2 = withRaqbSettingsAndWidgets({ | ||
config: configWithExistingProps, | ||
configFor: ConfigFor.FormFields, | ||
}); | ||
|
||
// @ts-expect-error - TODO: fix this | ||
// Using same reference | ||
expect(result2.widgets.text.factory).toBe(textFactory); | ||
}); | ||
|
||
it("should reuse same component fns for settings - ensures remounting is not happening", () => { | ||
const configWithExistingProps = { | ||
...mockConfig, | ||
}; | ||
|
||
const result1 = withRaqbSettingsAndWidgets({ | ||
config: configWithExistingProps, | ||
configFor: ConfigFor.FormFields, | ||
}); | ||
|
||
const renderFieldOnFirstCallOfWithRaqbSettingsAndWidgets = result1.settings.renderField; | ||
|
||
const result2 = withRaqbSettingsAndWidgets({ | ||
config: configWithExistingProps, | ||
configFor: ConfigFor.FormFields, | ||
}); | ||
|
||
expect(result2.settings.renderField).toBe(renderFieldOnFirstCallOfWithRaqbSettingsAndWidgets); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters