diff --git a/app/client/src/WidgetProvider/factory/helpers.tabOrder.test.ts b/app/client/src/WidgetProvider/factory/helpers.tabOrder.test.ts new file mode 100644 index 000000000000..f580adae5231 --- /dev/null +++ b/app/client/src/WidgetProvider/factory/helpers.tabOrder.test.ts @@ -0,0 +1,249 @@ +import type { + PropertyPaneConfig, + PropertyPaneControlConfig, + PropertyPaneSectionConfig, +} from "constants/PropertyControlConstants"; +import { ValidationTypes } from "constants/WidgetValidation"; +import { loadAllWidgets } from "widgets"; +import WidgetFactory from "WidgetProvider/factory"; +import { registerWidgets } from "WidgetProvider/factory/registrationHelper"; +import type { WidgetProps } from "widgets/BaseWidget"; +import { + addTabOrderToPropertyPaneConfig, + createTabOrderPropertyPaneSection, + shouldExposeTabOrderProperty, + TAB_ORDER_PROPERTY_NAME, + TAB_ORDER_SECTION_NAME, +} from "./helpers"; + +function collectTabOrderControls( + config: readonly PropertyPaneConfig[], +): PropertyPaneControlConfig[] { + const controls: PropertyPaneControlConfig[] = []; + + for (const item of config) { + const control = item as PropertyPaneControlConfig; + + if (control.propertyName === TAB_ORDER_PROPERTY_NAME) { + controls.push(control); + } + + if (item.children) { + controls.push(...collectTabOrderControls(item.children)); + } + } + + return controls; +} + +function assertSharedTabOrderControl(control: PropertyPaneControlConfig) { + expect(control.label).toBe("Tab order"); + expect(control.helpText).toBe( + "Optional. Lower numbers receive keyboard focus first, among widgets in the same container. Leave blank for automatic order. Fields inside a form follow the form's own order.", + ); + expect(control.controlType).toBe("CLEARABLE_NUMERIC_INPUT"); + // TODO: Fix this the next time the file is edited + // eslint-disable-next-line @typescript-eslint/no-explicit-any + expect((control as any).placeholderText).toBe("Auto"); + expect(control.isJSConvertible).toBe(false); + expect(control.isBindProperty).toBe(false); + expect(control.isTriggerProperty).toBe(false); + expect(control.validation).toEqual({ + type: ValidationTypes.NUMBER, + params: { min: 0, natural: true }, + }); +} + +describe("shouldExposeTabOrderProperty", () => { + it("includes focusable / interactive standard non-Anvil widgets", () => { + for (const type of [ + "BUTTON_WIDGET", + "INPUT_WIDGET_V2", + "TABLE_WIDGET_V2", + "CONTAINER_WIDGET", + "MODAL_WIDGET", + "JSON_FORM_WIDGET", + "CHECKBOX_GROUP_WIDGET", + // native