Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
test(web): move form behavior suites to browser mode (#45483)
Stephen Zhou6d557e1093e7
diff --git a/web/app/components/base/form/__tests__/index.spec.tsx b/web/app/components/base/form/__tests__/index.browser.spec.tsxsimilarity index 56%rename from web/app/components/base/form/__tests__/index.spec.tsxrename to web/app/components/base/form/__tests__/index.browser.spec.tsxindex 4ed4726e04f..67d0793ee1a 100644--- a/web/app/components/base/form/__tests__/index.spec.tsx+++ b/web/app/components/base/form/__tests__/index.browser.spec.tsx@@ -1,5 +1,6 @@-import { render, screen, waitFor } from '@testing-library/react'-import userEvent from '@testing-library/user-event'+import { page, userEvent } from 'vite-plus/test/browser'+import { render } from 'vitest-browser-react'+import { guardUnexpectedFetch } from '@/test/unexpected-fetch'import { useAppForm } from '../index'const FormHarness = ({ onSubmit }: { onSubmit: (value: Record<string, unknown>) => void }) => {@@ -26,16 +27,19 @@ const FormHarness = ({ onSubmit }: { onSubmit: (value: Record<string, unknown>)describe('app form field integration', () => {it('should submit values through the generated app form', async () => {const onSubmit = vi.fn()- const user = userEvent.setup()- render(<FormHarness onSubmit={onSubmit} />)- const input = screen.getByRole('textbox', { name: 'Title' })- await user.clear(input)- await user.type(input, 'Updated title')- await user.click(screen.getByRole('button', { name: /submit/i }))+ await render(<FormHarness onSubmit={onSubmit} />)- await waitFor(() => {- expect(onSubmit).toHaveBeenCalledWith({ title: 'Updated title' })- })+ const input = page.getByRole('textbox', { name: 'Title' })+ await input.fill('')+ await input.fill('Updated title')+ await userEvent.keyboard('{Enter}')++ await expect.poll(() => onSubmit.mock.calls).toEqual([[{ title: 'Updated title' }]])})})++beforeEach(async () => {+ await page.viewport(1280, 900)+ onTestFinished(guardUnexpectedFetch())+})diff --git a/web/app/components/base/form/components/base/__tests__/base-field.spec.tsx b/web/app/components/base/form/components/base/__tests__/base-field.browser.spec.tsxsimilarity index 58%rename from web/app/components/base/form/components/base/__tests__/base-field.spec.tsxrename to web/app/components/base/form/components/base/__tests__/base-field.browser.spec.tsxindex f76a0f77066..ab865c5799e 100644--- a/web/app/components/base/form/components/base/__tests__/base-field.spec.tsx+++ b/web/app/components/base/form/components/base/__tests__/base-field.browser.spec.tsx@@ -1,9 +1,10 @@import type { AnyFieldApi } from '@tanstack/react-form'import type { FormSchema } from '@/app/components/base/form/types'import { useForm } from '@tanstack/react-form'-import { render, screen } from '@testing-library/react'-import userEvent from '@testing-library/user-event'+import { page, userEvent } from 'vite-plus/test/browser'+import { render } from 'vitest-browser-react'import { FormItemValidateStatusEnum, FormTypeEnum } from '@/app/components/base/form/types'+import { guardUnexpectedFetch } from '@/test/unexpected-fetch'import BaseField from '../base-field'const mockDynamicOptions = vi.fn()@@ -54,7 +55,7 @@ const renderBaseField = ({</form.Field>{showCurrentValue && (<form.Subscribe selector={(state) => state.values[formSchema.name]}>- {(value) => <div data-testid="field-value">{String(value)}</div>}+ {(value) => <output aria-label="Field value">{String(value)}</output>}</form.Subscribe>)}</>@@ -66,7 +67,6 @@ const renderBaseField = ({describe('BaseField', () => {beforeEach(() => {- vi.clearAllMocks()mockDynamicOptions.mockReturnValue({data: undefined,isLoading: false,@@ -80,29 +80,27 @@ describe('BaseField', () => {])('copies the $type field value through its keyboard-accessible action',async ({ type, value, copied }) => {- const user = userEvent.setup()- renderBaseField({+ await renderBaseField({formSchema: { type, name: 'value', label: 'Value', required: false, showCopy: true },defaultValues: { value },})- await user.click(screen.getByLabelText('Value'))- await user.tab()- const copyButton = screen.getByRole('button', { name: 'common.operation.copy' })- expect(copyButton).toHaveFocus()- await user.keyboard('{Enter}')+ await page.getByLabelText('Value').click()+ await userEvent.tab()+ const copyButton = page.getByRole('button', { name: 'common.operation.copy' })+ await expect.element(copyButton).toHaveFocus()+ await userEvent.keyboard('{Enter}')expect(mockCopy).toHaveBeenCalledWith(copied)- expect(copyButton).toHaveFocus()- expect(screen.getByLabelText('Value')).toHaveValue(String(value))+ await expect.element(copyButton).toHaveFocus()+ await expect.element(page.getByLabelText('Value')).toHaveValue(String(value))},)it.each([FormTypeEnum.textInput, FormTypeEnum.secretInput, FormTypeEnum.textNumber])('associates the visible label, description and required state for %s',async (type) => {- const user = userEvent.setup()- renderBaseField({+ await renderBaseField({formSchema: {type,name: 'credential',@@ -112,12 +110,12 @@ describe('BaseField', () => {options: [{ label: 'Primary', value: 'primary' }],},})- const control = screen.getByLabelText('Credential')- expect(control).toHaveAccessibleName('Credential')- expect(control).toHaveAccessibleDescription('Use the workspace credential')- expect(control).toBeRequired()- await user.click(screen.getByText('Credential'))- expect(control).toHaveFocus()+ const control = page.getByLabelText('Credential')+ await expect.element(control).toHaveAccessibleName('Credential')+ await expect.element(control).toHaveAccessibleDescription('Use the workspace credential')+ await expect.element(control).toBeRequired()+ await page.getByText('Credential').click()+ await expect.element(control).toHaveFocus()},)@@ -129,14 +127,13 @@ describe('BaseField', () => {])('focuses the $type trigger from its label and supports keyboard selection (multiple: $multiple)',async ({ type, multiple }) => {- const user = userEvent.setup()const options = [{ label: 'Primary', value: 'primary' }]mockDynamicOptions.mockReturnValue({data: { options },isLoading: false,error: null,})- renderBaseField({+ await renderBaseField({formSchema: {type,multiple,@@ -155,30 +152,31 @@ describe('BaseField', () => {showCurrentValue: true,})- const control = screen.getByRole('combobox', { name: 'Credential' })- expect(control).toHaveAccessibleDescription(- 'Use the workspace credential Choose a credential',- )- expect(control).toBeInvalid()- expect(control).toBeRequired()- expect(screen.getByRole('button', { name: 'Credential' })).toBeInTheDocument()- await user.click(screen.getByText('Credential'))- expect(control).toHaveFocus()- expect(control).toHaveAttribute('aria-expanded', 'false')- expect(screen.queryByRole('listbox')).not.toBeInTheDocument()-- await user.keyboard('{ArrowDown}')- expect(control).toHaveAttribute('aria-expanded', 'true')- expect(screen.getByRole('option', { name: 'Primary' })).toHaveFocus()- await user.keyboard('{Enter}')- expect(screen.getByTestId('field-value')).toHaveTextContent('primary')+ const control = page.getByRole('combobox', { name: 'Credential' })+ await expect+ .element(control)+ .toHaveAccessibleDescription('Use the workspace credential Choose a credential')+ await expect.element(control).toBeInvalid()+ await expect.element(control).toBeRequired()+ await expect.element(page.getByRole('button', { name: 'Credential' })).toBeVisible()+ await page.getByText('Credential').click()+ await expect.element(control).toHaveFocus()+ await expect.element(control).toHaveAttribute('aria-expanded', 'false')+ await expect.element(page.getByRole('listbox')).not.toBeInTheDocument()++ await userEvent.keyboard('{ArrowDown}')+ await expect.element(control).toHaveAttribute('aria-expanded', 'true')+ await expect.element(page.getByRole('option', { name: 'Primary' })).toHaveFocus()+ await userEvent.keyboard('{Enter}')+ await expect+ .element(page.getByRole('status', { name: 'Field value' }))+ .toHaveTextContent('primary')},)it('should render text input and propagate changes', async () => {- const user = userEvent.setup()const onChange = vi.fn()- renderBaseField({+ await renderBaseField({formSchema: {type: FormTypeEnum.textInput,name: 'title',@@ -189,18 +187,17 @@ describe('BaseField', () => {onChange,})- const input = screen.getByDisplayValue('Hello')- expect(input).toHaveValue('Hello')+ const input = page.getByRole('textbox', { name: 'Title' })+ await expect.element(input).toHaveValue('Hello')- await user.clear(input)- await user.type(input, 'Updated')+ await input.fill('')+ await input.fill('Updated')expect(onChange).toHaveBeenCalledWith('title', 'Updated')- expect(input).toHaveValue('Updated')+ await expect.element(input).toHaveValue('Updated')})it('should render only options that satisfy show_on conditions', async () => {- const user = userEvent.setup()- renderBaseField({+ await renderBaseField({formSchema: {type: FormTypeEnum.select,name: 'mode',@@ -214,12 +211,13 @@ describe('BaseField', () => {defaultValues: { mode: 'alpha', enabled: 'no' },})- await user.click(screen.getByText('Alpha'))- expect(screen.queryByText('Beta')).not.toBeInTheDocument()+ await page.getByRole('combobox', { name: 'Mode' }).click()+ await expect.element(page.getByRole('option', { name: 'Alpha' })).toBeVisible()+ await expect.element(page.getByText('Beta')).not.toBeInTheDocument()})- it('should not render current select value when it is filtered out by show_on conditions', () => {- renderBaseField({+ it('should not render current select value when it is filtered out by show_on conditions', async () => {+ await renderBaseField({formSchema: {type: FormTypeEnum.select,name: 'mode',@@ -233,20 +231,20 @@ describe('BaseField', () => {defaultValues: { mode: 'beta', enabled: 'no' },})- expect(screen.getByRole('combobox', { name: 'Mode' })).not.toHaveTextContent('beta')- expect(screen.getByRole('combobox', { name: 'Mode' })).toHaveTextContent(- 'common.placeholder.input',- )+ await expect.element(page.getByRole('combobox', { name: 'Mode' })).not.toHaveTextContent('beta')+ await expect+ .element(page.getByRole('combobox', { name: 'Mode' }))+ .toHaveTextContent('common.placeholder.input')})- it('should render dynamic select loading state', () => {+ it('should render dynamic select loading state', async () => {mockDynamicOptions.mockReturnValue({data: undefined,isLoading: true,error: null,})- renderBaseField({+ await renderBaseField({formSchema: {type: FormTypeEnum.dynamicSelect,name: 'plugin',@@ -256,13 +254,12 @@ describe('BaseField', () => {defaultValues: { plugin: '' },})- expect(screen.getByText('common.dynamicSelect.loading')).toBeInTheDocument()+ await expect.element(page.getByText('common.dynamicSelect.loading')).toBeVisible()})it('should update value when users click a radio option', async () => {- const user = userEvent.setup()const onChange = vi.fn()- renderBaseField({+ await renderBaseField({formSchema: {type: FormTypeEnum.radio,name: 'visibility',@@ -277,38 +274,43 @@ describe('BaseField', () => {onChange,})- await user.click(screen.getByText('Private'))+ await page.getByText('Private').click()expect(onChange).toHaveBeenCalledWith('visibility', 'private')- expect(screen.getByRole('radio', { name: 'Private' })).toBeChecked()+ await expect.element(page.getByRole('radio', { name: 'Private' })).toBeChecked()})it.each([{ type: FormTypeEnum.select, role: 'combobox' },{ type: FormTypeEnum.radio, role: 'radiogroup' },{ type: FormTypeEnum.checkbox, role: 'group' },- ])('associates $type validation and description with the named control', ({ type, role }) => {- renderBaseField({- formSchema: {- type,- name: 'access',- label: 'Access level',- description: 'Choose an access level',- required: true,- options: [{ label: 'Public', value: 'public' }],- },- defaultValues: { access: type === FormTypeEnum.checkbox ? [] : '' },- fieldState: {- validateStatus: FormItemValidateStatusEnum.Error,- errors: ['Choose an option'],- },- })- const control = screen.getByRole(role, { name: 'Access level' })- expect(control).toHaveAttribute('aria-invalid', 'true')- expect(control).toHaveAccessibleDescription('Choose an access level Choose an option')- })+ ])(+ 'associates $type validation and description with the named control',+ async ({ type, role }) => {+ await renderBaseField({+ formSchema: {+ type,+ name: 'access',+ label: 'Access level',+ description: 'Choose an access level',+ required: true,+ options: [{ label: 'Public', value: 'public' }],+ },+ defaultValues: { access: type === FormTypeEnum.checkbox ? [] : '' },+ fieldState: {+ validateStatus: FormItemValidateStatusEnum.Error,+ errors: ['Choose an option'],+ },+ })+ const control = page.getByRole(role, { name: 'Access level' })+ await expect.element(control).toHaveAttribute('aria-invalid', 'true')+ await expect+ .element(control)+ .toHaveAccessibleDescription('Choose an access level Choose an option')+ },+ )- it('should show validation message when field state has an error', () => {- renderBaseField({+ it('should show validation message when field state has an error', async () => {+ await renderBaseField({formSchema: {type: FormTypeEnum.textInput,name: 'name',@@ -321,13 +323,13 @@ describe('BaseField', () => {},})- const input = screen.getByRole('textbox', { name: 'Name' })- expect(input).toBeInvalid()- expect(input).toHaveAccessibleDescription('Name is required')+ const input = page.getByRole('textbox', { name: 'Name' })+ await expect.element(input).toBeInvalid()+ await expect.element(input).toHaveAccessibleDescription('Name is required')})- it('should render description and help link when provided', () => {- renderBaseField({+ it('should render description and help link when provided', async () => {+ await renderBaseField({formSchema: {type: FormTypeEnum.textInput,name: 'doc',@@ -340,15 +342,14 @@ describe('BaseField', () => {defaultValues: { doc: '' },})- expect(screen.getByText('Read the description')).toBeInTheDocument()- expect(screen.getByRole('link', { name: 'Open help docs' })).toHaveAttribute(- 'href',- 'https://example.com/help',- )+ await expect.element(page.getByText('Read the description')).toBeVisible()+ await expect+ .element(page.getByRole('link', { name: 'Open help docs' }))+ .toHaveAttribute('href', 'https://example.com/help')})- it('should render secret input with password type', () => {- renderBaseField({+ it('should render secret input with password type', async () => {+ await renderBaseField({formSchema: {type: FormTypeEnum.secretInput,name: 'token',@@ -358,13 +359,12 @@ describe('BaseField', () => {defaultValues: { token: 'abc' },})- expect(screen.getByDisplayValue('abc')).toHaveAttribute('type', 'password')+ await expect.element(page.getByLabelText('Token')).toHaveAttribute('type', 'password')})it('keeps numeric edits, zero and an empty value distinct at the form boundary', async () => {- const user = userEvent.setup()const onChange = vi.fn()- renderBaseField({+ await renderBaseField({formSchema: {type: FormTypeEnum.textNumber,name: 'count',@@ -375,23 +375,23 @@ describe('BaseField', () => {onChange,})- const input = screen.getByRole('textbox', { name: 'Count' })- expect(input).toHaveValue('7')- await user.clear(input)- await user.type(input, '3.5')- await user.tab()+ const input = page.getByRole('textbox', { name: 'Count' })+ await expect.element(input).toHaveValue('7')+ await input.fill('')+ await input.fill('3.5')+ await userEvent.tab()expect(onChange).toHaveBeenLastCalledWith('count', 3.5)- await user.clear(input)- await user.type(input, '0')- await user.tab()+ await input.fill('')+ await input.fill('0')+ await userEvent.tab()expect(onChange).toHaveBeenLastCalledWith('count', 0)- await user.clear(input)- await user.tab()+ await input.fill('')+ await userEvent.tab()expect(onChange).toHaveBeenLastCalledWith('count', null)})- it('should render translated object label content', () => {- renderBaseField({+ it('should render translated object label content', async () => {+ await renderBaseField({formSchema: {type: FormTypeEnum.textInput,name: 'title_i18n',@@ -401,11 +401,10 @@ describe('BaseField', () => {defaultValues: { title_i18n: '' },})- expect(screen.getByText('Localized title')).toBeInTheDocument()+ await expect.element(page.getByText('Localized title')).toBeVisible()})it('should render dynamic options and allow selecting one', async () => {- const user = userEvent.setup()mockDynamicOptions.mockReturnValue({data: {options: [{ label: { en_US: 'Option A', zh_Hans: '选项A' }, value: 'a' }],@@ -414,7 +413,7 @@ describe('BaseField', () => {error: null,})- renderBaseField({+ await renderBaseField({formSchema: {type: FormTypeEnum.dynamicSelect,name: 'plugin_option',@@ -424,13 +423,14 @@ describe('BaseField', () => {defaultValues: { plugin_option: '' },})- await user.click(screen.getByRole('combobox', { name: 'Plugin option' }))- await user.click(screen.getByRole('option', { name: 'Option A' }))- expect(screen.getByRole('combobox', { name: 'Plugin option' })).toHaveTextContent('Option A')+ await page.getByRole('combobox', { name: 'Plugin option' }).click()+ await page.getByRole('option', { name: 'Option A' }).click()+ await expect+ .element(page.getByRole('combobox', { name: 'Plugin option' }))+ .toHaveTextContent('Option A')})it('should preserve multiple dynamic select values', async () => {- const user = userEvent.setup()mockDynamicOptions.mockReturnValue({data: {options: [@@ -442,7 +442,7 @@ describe('BaseField', () => {error: null,})- renderBaseField({+ await renderBaseField({formSchema: {type: FormTypeEnum.dynamicSelect,name: 'plugin_options',@@ -454,19 +454,18 @@ describe('BaseField', () => {showCurrentValue: true,})- expect(screen.getByRole('combobox', { name: 'Plugin options' })).toHaveTextContent(- 'common.dynamicSelect.selected',- )+ await expect+ .element(page.getByRole('combobox', { name: 'Plugin options' }))+ .toHaveTextContent('common.dynamicSelect.selected:{"count":1}')- await user.click(screen.getByRole('combobox', { name: 'Plugin options' }))- await user.click(screen.getByRole('option', { name: 'Option B' }))+ await page.getByRole('combobox', { name: 'Plugin options' }).click()+ await page.getByRole('option', { name: 'Option B' }).click()- expect(screen.getByTestId('field-value')).toHaveTextContent('a,b')+ await expect.element(page.getByRole('status', { name: 'Field value' })).toHaveTextContent('a,b')})it('should update boolean field when users choose false', async () => {- const user = userEvent.setup()- renderBaseField({+ await renderBaseField({formSchema: {type: FormTypeEnum.boolean,name: 'enabled',@@ -477,13 +476,17 @@ describe('BaseField', () => {showCurrentValue: true,})- expect(screen.getByTestId('field-value')).toHaveTextContent('true')- await user.click(screen.getByText('False'))- expect(screen.getByTestId('field-value')).toHaveTextContent('false')+ await expect+ .element(page.getByRole('status', { name: 'Field value' }))+ .toHaveTextContent('true')+ await page.getByText('False').click()+ await expect+ .element(page.getByRole('status', { name: 'Field value' }))+ .toHaveTextContent('false')})- it('should render warning message when field state has a warning', () => {- renderBaseField({+ it('should render warning message when field state has a warning', async () => {+ await renderBaseField({formSchema: {type: FormTypeEnum.textInput,name: 'warning_field',@@ -496,13 +499,11 @@ describe('BaseField', () => {},})- expect(screen.getByText('This is a warning')).toBeInTheDocument()+ await expect.element(page.getByText('This is a warning')).toBeVisible()})it('should render infotip when tooltip content is provided', async () => {- const user = userEvent.setup()-- renderBaseField({+ await renderBaseField({formSchema: {type: FormTypeEnum.textInput,name: 'info',@@ -512,16 +513,15 @@ describe('BaseField', () => {},})- expect(screen.getByText('Info')).toBeInTheDocument()+ await expect.element(page.getByText('Info')).toBeVisible()- await user.click(screen.getByRole('button', { name: 'Info' }))+ await page.getByRole('button', { name: 'Info' }).click()- expect(screen.getByText('Extra info')).toBeInTheDocument()+ await expect.element(page.getByText('Extra info')).toBeVisible()})it('should render checkbox list and handle changes', async () => {- const user = userEvent.setup()- renderBaseField({+ await renderBaseField({formSchema: {type: FormTypeEnum.checkbox,name: 'features',@@ -535,22 +535,21 @@ describe('BaseField', () => {defaultValues: { features: ['a'] },})- expect(screen.getByText('Feature A')).toBeInTheDocument()- expect(screen.getByText('Feature B')).toBeInTheDocument()- await user.click(screen.getByText('Feature B'))+ await expect.element(page.getByText('Feature A')).toBeVisible()+ await expect.element(page.getByText('Feature B')).toBeVisible()+ await page.getByText('Feature B').click()- const checkboxB = screen.getByRole('checkbox', { name: 'Feature B' })- expect(checkboxB).toHaveAttribute('aria-checked', 'true')+ const checkboxB = page.getByRole('checkbox', { name: 'Feature B' })+ await expect.element(checkboxB).toHaveAttribute('aria-checked', 'true')})it('should handle dynamic select error state', async () => {- const user = userEvent.setup()mockDynamicOptions.mockReturnValue({data: undefined,isLoading: false,error: new Error('Failed'),})- renderBaseField({+ await renderBaseField({formSchema: {type: FormTypeEnum.dynamicSelect,name: 'ds_error',@@ -558,19 +557,18 @@ describe('BaseField', () => {required: false,},})- await user.click(screen.getByRole('combobox', { name: 'DS Error' }))- expect(screen.getByText('common.dynamicSelect.error')).toBeInTheDocument()- expect(screen.queryByRole('option')).not.toBeInTheDocument()+ await page.getByRole('combobox', { name: 'DS Error' }).click()+ await expect.element(page.getByText('common.dynamicSelect.error')).toBeVisible()+ await expect.element(page.getByRole('option')).not.toBeInTheDocument()})it('should handle dynamic select no data state', async () => {- const user = userEvent.setup()mockDynamicOptions.mockReturnValue({data: { options: [] },isLoading: false,error: null,})- renderBaseField({+ await renderBaseField({formSchema: {type: FormTypeEnum.dynamicSelect,name: 'ds_empty',@@ -578,17 +576,16 @@ describe('BaseField', () => {required: false,},})- await user.click(screen.getByRole('combobox', { name: 'DS Empty' }))- expect(screen.getByText('common.dynamicSelect.noData')).toBeInTheDocument()- expect(screen.queryByRole('option')).not.toBeInTheDocument()+ await page.getByRole('combobox', { name: 'DS Empty' }).click()+ await expect.element(page.getByText('common.dynamicSelect.noData')).toBeVisible()+ await expect.element(page.getByRole('option')).not.toBeInTheDocument()})it.each([{ type: FormTypeEnum.boolean, role: 'radio', label: 'False', value: true },{ type: FormTypeEnum.checkbox, role: 'checkbox', label: 'Choice', value: [] },])('keeps disabled $type values unchanged', async ({ type, role, label, value }) => {- const user = userEvent.setup()- renderBaseField({+ await renderBaseField({formSchema: {type,name: 'locked',@@ -600,9 +597,16 @@ describe('BaseField', () => {defaultValues: { locked: value },showCurrentValue: true,})- const control = screen.getByRole(role, { name: label })- await user.click(control)- expect(control).not.toBeChecked()- expect(screen.getByTestId('field-value').textContent).toBe(String(value))+ const control = page.getByRole(role, { name: label })+ await expect.element(control).toBeDisabled()+ await expect.element(control).not.toBeChecked()+ await expect+ .element(page.getByRole('status', { name: 'Field value' }))+ .toHaveTextContent(String(value))})})++beforeEach(async () => {+ await page.viewport(1280, 900)+ onTestFinished(guardUnexpectedFetch())+})diff --git a/web/app/components/base/form/components/base/__tests__/base-form.browser.spec.tsx b/web/app/components/base/form/components/base/__tests__/base-form.browser.spec.tsxnew file mode 100644index 00000000000..506227b0841--- /dev/null+++ b/web/app/components/base/form/components/base/__tests__/base-form.browser.spec.tsx@@ -0,0 +1,199 @@+import type { FormRefObject, FormSchema } from '@/app/components/base/form/types'+import { useForm, useSelector } from '@tanstack/react-form'+import { createRef } from 'react'+import { page, userEvent } from 'vite-plus/test/browser'+import { render } from 'vitest-browser-react'+import { FormItemValidateStatusEnum, FormTypeEnum } from '@/app/components/base/form/types'+import { guardUnexpectedFetch } from '@/test/unexpected-fetch'+import BaseForm from '../base-form'++vi.mock('@/service/use-triggers', () => ({+ useTriggerPluginDynamicOptions: () => ({ data: undefined, isLoading: false, error: null }),+}))++const baseSchemas: FormSchema[] = [+ { type: FormTypeEnum.textInput, name: 'kind', label: 'Kind', required: false, default: 'show' },+ {+ type: FormTypeEnum.textInput,+ name: 'title',+ label: 'Title',+ required: true,+ default: 'Initial title',+ show_on: [{ variable: 'kind', value: 'show' }],+ },+]++beforeEach(async () => {+ await page.viewport(1280, 900)+ onTestFinished(guardUnexpectedFetch())+})++it('uses schema defaults and hides a conditional field when its controlling value changes', async () => {+ const onChange = vi.fn()+ await render(<BaseForm formSchemas={baseSchemas} onChange={onChange} />)+ await expect.element(page.getByRole('textbox', { name: 'Title' })).toHaveValue('Initial title')+ await page.getByRole('textbox', { name: 'Kind' }).fill('hide')+ await expect.element(page.getByRole('textbox', { name: 'Title' })).not.toBeInTheDocument()+ expect(onChange).toHaveBeenLastCalledWith('kind', 'hide')+})++it('omits conditional fields when supplied defaults do not match', async () => {+ await render(+ <BaseForm formSchemas={baseSchemas} defaultValues={{ kind: 'hide', title: 'Hidden title' }} />,+ )+ await expect.element(page.getByRole('textbox', { name: 'Kind' })).toHaveValue('hide')+ await expect.element(page.getByRole('textbox', { name: 'Title' })).not.toBeInTheDocument()+})++// setFields/getFormValues are BaseForm's public API used by credential request callers.+it.each([+ {+ name: 'server value and error',+ fields: [{ name: 'title', value: 'Changed title', errors: ['Title is invalid'] }],+ message: 'Title is invalid',+ title: 'Changed title',+ },+ {+ name: 'warning without a value change',+ fields: [{ name: 'title', warnings: ['Title warning'] }],+ message: 'Title warning',+ title: 'Initial title',+ },+ {+ name: 'explicit error status',+ fields: [+ {+ name: 'title',+ validateStatus: FormItemValidateStatusEnum.Error,+ errors: ['Explicit error'],+ },+ ],+ message: 'Explicit error',+ title: 'Initial title',+ },+ {+ name: 'error without a value change',+ fields: [{ name: 'title', errors: ['Error only'] }],+ message: 'Error only',+ title: 'Initial title',+ },+ {+ name: 'value without validation state',+ fields: [{ name: 'title', value: 'Changed title' }],+ message: undefined,+ title: 'Changed title',+ },+])(+ 'applies $name through the caller and returns the displayed values',+ async ({ fields, message, title }) => {+ const ref = createRef<FormRefObject>()+ const saved = vi.fn()+ await render(+ <>+ <BaseForm ref={ref} formSchemas={baseSchemas} />+ <button type="button" onClick={() => ref.current?.setFields(fields)}>+ Apply response+ </button>+ <button+ type="button"+ onClick={() => saved(ref.current?.getFormValues({ needCheckValidatedValues: false }))}+ >+ Read values+ </button>+ </>,+ )+ await page.getByRole('button', { name: 'Apply response' }).click()+ await expect.element(page.getByRole('textbox', { name: 'Title' })).toHaveValue(title)+ if (message)+ await expect+ .element(page.getByRole('textbox', { name: 'Title' }))+ .toHaveAccessibleDescription(message)+ await page.getByRole('button', { name: 'Read values' }).click()+ expect(saved).toHaveBeenCalledWith({ values: { kind: 'show', title }, isCheckValidated: true })+ },+)++it('uses the supplied form for editing and conditional field visibility', async () => {+ function ExternalForm() {+ const form = useForm({ defaultValues: { kind: 'show', title: 'External title' } })+ const kind = useSelector(form.store, (state) => state.values.kind)+ return (+ <>+ <BaseForm formSchemas={baseSchemas} formFromProps={form} />+ <output>{kind}</output>+ </>+ )+ }+ await render(<ExternalForm />)+ await expect.element(page.getByRole('textbox', { name: 'Title' })).toHaveValue('External title')+ await page.getByRole('textbox', { name: 'Kind' }).fill('hide')+ await expect.element(page.getByRole('status')).toHaveTextContent('hide')+ await expect.element(page.getByRole('textbox', { name: 'Title' })).not.toBeInTheDocument()+})++it.each([false, true])(+ 'delivers native Enter submission with preventDefaultSubmit=%s',+ async (preventDefaultSubmit) => {+ const submitted = vi.fn()+ await render(+ <BaseForm+ formSchemas={[baseSchemas[0]!]}+ preventDefaultSubmit={preventDefaultSubmit}+ onSubmit={(event) => {+ submitted({+ preventedByOwner: event.defaultPrevented,+ values: Object.fromEntries(new FormData(event.currentTarget)),+ })+ // The consumer prevents navigation when the BaseForm owner leaves that choice to it.+ event.preventDefault()+ }}+ />,+ )+ await page.getByRole('textbox', { name: 'Kind' }).fill('edited')+ await userEvent.keyboard('{Enter}')+ expect(submitted).toHaveBeenCalledExactlyOnceWith({+ preventedByOwner: preventDefaultSubmit,+ values: { kind: 'edited' },+ })+ },+)++it('preserves false and zero schema defaults in submitted values', async () => {+ const ref = createRef<FormRefObject>()+ const saved = vi.fn()+ const schemas: FormSchema[] = [+ {+ type: FormTypeEnum.boolean,+ name: 'enabled',+ label: 'Enabled',+ required: false,+ default: false,+ },+ { type: FormTypeEnum.textNumber, name: 'count', label: 'Count', required: false, default: 0 },+ {+ type: FormTypeEnum.textInput,+ name: 'reason',+ label: 'Reason',+ required: false,+ default: 'Disabled by default',+ },+ ]+ await render(+ <>+ <BaseForm formSchemas={schemas} ref={ref} />+ <button+ type="button"+ onClick={() => saved(ref.current?.getFormValues({ needCheckValidatedValues: false }))}+ >+ Save+ </button>+ </>,+ )+ await expect.element(page.getByRole('radio', { name: 'False' })).toBeChecked()+ await expect.element(page.getByRole('textbox', { name: 'Count' })).toHaveValue('0')+ await page.getByRole('button', { name: 'Save' }).click()+ expect(saved).toHaveBeenCalledWith({+ values: { enabled: false, count: 0, reason: 'Disabled by default' },+ isCheckValidated: true,+ })+})diff --git a/web/app/components/base/form/components/base/__tests__/base-form.spec.tsx b/web/app/components/base/form/components/base/__tests__/base-form.spec.tsxdeleted file mode 100644index fe625ccd5a4..00000000000--- a/web/app/components/base/form/components/base/__tests__/base-form.spec.tsx+++ /dev/null@@ -1,220 +0,0 @@-import type { FormRefObject, FormSchema } from '@/app/components/base/form/types'-import { useForm, useSelector } from '@tanstack/react-form'-import { act, fireEvent, render, screen } from '@testing-library/react'-import userEvent from '@testing-library/user-event'-import { FormItemValidateStatusEnum, FormTypeEnum } from '@/app/components/base/form/types'-import BaseForm from '../base-form'--vi.mock('@/service/use-triggers', () => ({- useTriggerPluginDynamicOptions: () => ({- data: undefined,- isLoading: false,- error: null,- }),-}))--const baseSchemas: FormSchema[] = [- {- type: FormTypeEnum.textInput,- name: 'kind',- label: 'Kind',- required: false,- default: 'show',- },- {- type: FormTypeEnum.textInput,- name: 'title',- label: 'Title',- required: true,- default: 'Initial title',- show_on: [{ variable: 'kind', value: 'show' }],- },-]--describe('BaseForm', () => {- it('should render fields with default values from schema', () => {- render(<BaseForm formSchemas={baseSchemas} />)-- expect(screen.getByDisplayValue('show'))!.toBeInTheDocument()- expect(screen.getByDisplayValue('Initial title'))!.toBeInTheDocument()- })-- it('should hide conditional fields when show_on conditions are not met', () => {- render(- <BaseForm- formSchemas={baseSchemas}- defaultValues={{ kind: 'hide', title: 'Hidden title' }}- />,- )-- expect(screen.getByDisplayValue('hide'))!.toBeInTheDocument()- expect(screen.queryByDisplayValue('Hidden title')).not.toBeInTheDocument()- })-- it('should expose ref API for updating values and field states', async () => {- const formRef = { current: null } as { current: FormRefObject | null }- render(<BaseForm formSchemas={baseSchemas} ref={formRef} />)-- expect(formRef.current).not.toBeNull()-- await act(async () => {- formRef.current?.setFields([- {- name: 'title',- value: 'Changed title',- errors: ['Title is invalid'],- },- ])- })-- expect(screen.getByDisplayValue('Changed title'))!.toBeInTheDocument()- expect(screen.getByText('Title is invalid'))!.toBeInTheDocument()- expect(formRef.current?.getFormValues({ needCheckValidatedValues: false })).toEqual({- values: { kind: 'show', title: 'Changed title' },- isCheckValidated: true,- })- })-- it('should derive warning status when setFields receives warnings only', async () => {- const formRef = { current: null } as { current: FormRefObject | null }- render(<BaseForm formSchemas={baseSchemas} ref={formRef} />)-- await act(async () => {- formRef.current?.setFields([- {- name: 'title',- warnings: ['Title warning'],- },- ])- })-- expect(screen.getByText('Title warning'))!.toBeInTheDocument()- })-- it('uses the supplied form for editing and conditional field visibility', async () => {- const user = userEvent.setup()- const ExternalForm = () => {- const form = useForm({ defaultValues: { kind: 'show', title: 'External title' } })- const kind = useSelector(form.store, (state) => state.values.kind)- return (- <>- <BaseForm formSchemas={baseSchemas} formFromProps={form} />- <output>{kind}</output>- </>- )- }- render(<ExternalForm />)- expect(screen.getByDisplayValue('External title')).toBeInTheDocument()- await user.clear(screen.getByDisplayValue('show'))- await user.type(screen.getAllByRole('textbox')[0]!, 'hide')- expect(screen.getByRole('status')).toHaveTextContent('hide')- expect(screen.queryByDisplayValue('External title')).not.toBeInTheDocument()- })-- it('should handle setFields with explicit validateStatus', async () => {- const formRef = { current: null } as { current: FormRefObject | null }- render(<BaseForm formSchemas={baseSchemas} ref={formRef} />)-- await act(async () => {- formRef.current?.setFields([- {- name: 'kind',- validateStatus: FormItemValidateStatusEnum.Error,- errors: ['Explicit error'],- },- ])- })- expect(screen.getByText('Explicit error'))!.toBeInTheDocument()- })-- it('should handle setFields with no value change', async () => {- const formRef = { current: null } as { current: FormRefObject | null }- render(<BaseForm formSchemas={baseSchemas} ref={formRef} />)-- await act(async () => {- formRef.current?.setFields([- {- name: 'kind',- errors: ['Error only'],- },- ])- })- expect(screen.getByText('Error only'))!.toBeInTheDocument()- expect(screen.getByDisplayValue('show')).toBeInTheDocument()- })-- it('should handle submit without preventDefaultSubmit', async () => {- const onSubmit = vi.fn()- const { container } = render(<BaseForm formSchemas={baseSchemas} onSubmit={onSubmit} />)- await act(async () => {- fireEvent.submit(container.querySelector('form') as HTMLFormElement)- })- expect(onSubmit).toHaveBeenCalled()- })-- it('should handle preventDefaultSubmit', async () => {- const onSubmit = vi.fn()- const { container } = render(- <BaseForm formSchemas={baseSchemas} onSubmit={onSubmit} preventDefaultSubmit={true} />,- )- const event = new Event('submit', { cancelable: true, bubbles: true })- const form = container.querySelector('form') as HTMLFormElement- await act(async () => {- fireEvent(form, event)- })- expect(event.defaultPrevented).toBe(true)- expect(onSubmit).toHaveBeenCalled()- })-- it('should call onChange when field value changes', async () => {- const onChange = vi.fn()- render(<BaseForm formSchemas={baseSchemas} onChange={onChange} />)- const input = screen.getByDisplayValue('show')- await act(async () => {- fireEvent.change(input, { target: { value: 'new-value' } })- })- expect(onChange).toHaveBeenCalledWith('kind', 'new-value')- })-- it('should handle setFields with no status, errors, or warnings', async () => {- const formRef = { current: null } as { current: FormRefObject | null }- render(<BaseForm formSchemas={baseSchemas} ref={formRef} />)-- await act(async () => {- formRef.current?.setFields([- {- name: 'kind',- value: 'new-show',- },- ])- })- expect(screen.getByDisplayValue('new-show'))!.toBeInTheDocument()- })-})--it('preserves false and zero schema defaults in submitted values', () => {- const ref = { current: null as FormRefObject | null }- const schemas: FormSchema[] = [- {- type: FormTypeEnum.boolean,- name: 'enabled',- label: 'Enabled',- required: false,- default: false,- },- { type: FormTypeEnum.textNumber, name: 'count', label: 'Count', required: false, default: 0 },- {- type: FormTypeEnum.textInput,- name: 'reason',- label: 'Reason',- required: false,- default: 'Disabled by default',- },- ]- render(<BaseForm formSchemas={schemas} ref={ref} />)- expect(screen.getByDisplayValue('Disabled by default')).toBeInTheDocument()- expect(ref.current?.getFormValues({ needCheckValidatedValues: false })).toEqual({- values: { enabled: false, count: 0, reason: 'Disabled by default' },- isCheckValidated: true,- })-})diff --git a/web/app/components/base/form/components/base/__tests__/validation-accessibility.spec.tsx b/web/app/components/base/form/components/base/__tests__/validation-accessibility.browser.spec.tsxsimilarity index 50%rename from web/app/components/base/form/components/base/__tests__/validation-accessibility.spec.tsxrename to web/app/components/base/form/components/base/__tests__/validation-accessibility.browser.spec.tsxindex 7ab15a9b325..8c31b2e9460 100644--- a/web/app/components/base/form/components/base/__tests__/validation-accessibility.spec.tsx+++ b/web/app/components/base/form/components/base/__tests__/validation-accessibility.browser.spec.tsx@@ -1,14 +1,11 @@import type { FormRefObject, FormSchema } from '@/app/components/base/form/types'-import { act, render, screen } from '@testing-library/react'-import userEvent from '@testing-library/user-event'import { createRef } from 'react'+import { page } from 'vite-plus/test/browser'+import { render } from 'vitest-browser-react'import { FormTypeEnum } from '@/app/components/base/form/types'+import { guardUnexpectedFetch } from '@/test/unexpected-fetch'import BaseForm from '../base-form'-vi.mock('@/hooks/use-i18n', () => ({- useRenderI18nObject: () => (content: Record<string, string>) => content.en_US ?? '',-}))-vi.mock('@/service/use-triggers', () => ({useTriggerPluginDynamicOptions: () => ({ data: undefined, isLoading: false, error: null }),}))@@ -21,7 +18,6 @@ const requiredSchema = (label: string): FormSchema => ({type: FormTypeEnum.secretInput,required: true,description: 'Paste your API token',- tooltip: 'Find this token in the provider settings',validators: {onMount: ({ value }: { value: unknown }) => (!value ? 'Token is required' : undefined),onChange: ({ value }: { value: unknown }) => (!value ? 'Token is required' : undefined),@@ -30,45 +26,53 @@ const requiredSchema = (label: string): FormSchema => ({describe('BaseForm validation accessibility', () => {it('shows client validation again after editing clears a server error', async () => {- const user = userEvent.setup()const ref = createRef<FormRefObject>()- render(+ await render(<><BaseFormref={ref}formSchemas={[requiredSchema('API token')]}onChange={(name) => ref.current?.setFields([{ name, errors: [] }])}/>+ <button+ type="button"+ onClick={() =>+ ref.current?.setFields([{ name: 'token', errors: ['Token was rejected'] }])+ }+ >+ Apply server error+ </button><button type="button" onClick={() => ref.current?.getFormValues({})}>Save credentials</button></>,)- const input = screen.getByLabelText('API token', { selector: 'input' })- await user.type(input, 'rejected-token')- act(() => {- ref.current?.setFields([{ name: 'token', errors: ['Token was rejected'] }])- })- expect(input).toBeInvalid()- expect(input).toHaveAccessibleDescription('Paste your API token Token was rejected')+ const input = page.getByLabelText('API token')+ await input.fill('rejected-token')+ await page.getByRole('button', { name: 'Apply server error' }).click()+ await expect.element(input).toBeInvalid()+ await expect+ .element(input)+ .toHaveAccessibleDescription('Paste your API token Token was rejected')- await user.clear(input)- await user.click(screen.getByRole('button', { name: 'Save credentials' }))- expect(input).toHaveFocus()- expect(input).toBeInvalid()- expect(input).toHaveAccessibleDescription('Paste your API token Token is required')- expect(screen.queryByText('Token was rejected')).not.toBeInTheDocument()+ await input.fill('')+ await page.getByRole('button', { name: 'Save credentials' }).click()+ await expect.element(input).toHaveFocus()+ await expect.element(input).toBeInvalid()+ await expect+ .element(input)+ .toHaveAccessibleDescription('Paste your API token Token is required')+ await expect.element(page.getByText('Token was rejected')).not.toBeInTheDocument()- await user.type(input, 'valid-token')- expect(input).not.toBeInvalid()- expect(input).toHaveAccessibleDescription('Paste your API token')- expect(screen.queryByText('Token is required')).not.toBeInTheDocument()+ await input.fill('valid-token')+ await expect.element(input).not.toBeInvalid()+ await expect.element(input).toHaveAccessibleDescription('Paste your API token')+ await expect.element(page.getByText('Token is required')).not.toBeInTheDocument()})it('focuses the invalid field in the submitting form and associates the error until corrected', async () => {- const user = userEvent.setup()const ref = createRef<FormRefObject>()- render(+ await render(<><BaseForm formSchemas={[requiredSchema('Other token')]} /><BaseForm ref={ref} formSchemas={[requiredSchema('API token')]} />@@ -77,24 +81,25 @@ describe('BaseForm validation accessibility', () => {</button></>,)- const input = screen.getByLabelText('API token', { selector: 'input' })- expect(input).not.toBeInvalid()- await user.click(screen.getByRole('button', { name: 'Save credentials' }))- expect(input).toHaveFocus()- expect(input).toBeInvalid()- expect(input).toHaveAccessibleDescription('Paste your API token Token is required')- expect(screen.getByLabelText('Other token', { selector: 'input' })).not.toBeInvalid()+ const input = page.getByLabelText('API token')+ await expect.element(input).not.toBeInvalid()+ await page.getByRole('button', { name: 'Save credentials' }).click()+ await expect.element(input).toHaveFocus()+ await expect.element(input).toBeInvalid()+ await expect+ .element(input)+ .toHaveAccessibleDescription('Paste your API token Token is required')+ await expect.element(page.getByLabelText('Other token')).not.toBeInvalid()- await user.type(input, 'valid-token')- expect(input).not.toBeInvalid()- expect(input).toHaveAccessibleDescription('Paste your API token')- expect(screen.queryByText('Token is required')).not.toBeInTheDocument()+ await input.fill('valid-token')+ await expect.element(input).not.toBeInvalid()+ await expect.element(input).toHaveAccessibleDescription('Paste your API token')+ await expect.element(page.getByText('Token is required')).not.toBeInTheDocument()})it('skips hidden field errors and focuses the first visible invalid field in schema order', async () => {- const user = userEvent.setup()const ref = createRef<FormRefObject>()- render(+ await render(<><BaseFormref={ref}@@ -114,8 +119,13 @@ describe('BaseForm validation accessibility', () => {</button></>,)- await user.click(screen.getByRole('button', { name: 'Save credentials' }))- expect(screen.getByLabelText('Visible token', { selector: 'input' })).toHaveFocus()- expect(screen.queryByLabelText('Hidden token', { selector: 'input' })).not.toBeInTheDocument()+ await page.getByRole('button', { name: 'Save credentials' }).click()+ await expect.element(page.getByLabelText('Visible token')).toHaveFocus()+ await expect.element(page.getByLabelText('Hidden token')).not.toBeInTheDocument()})})++beforeEach(async () => {+ await page.viewport(1280, 900)+ onTestFinished(guardUnexpectedFetch())+})diff --git a/web/app/components/base/form/components/field/__tests__/field-integration.browser.spec.tsx b/web/app/components/base/form/components/field/__tests__/field-integration.browser.spec.tsxnew file mode 100644index 00000000000..afd51b4693a--- /dev/null+++ b/web/app/components/base/form/components/field/__tests__/field-integration.browser.spec.tsx@@ -0,0 +1,216 @@+import type { ReactElement } from 'react'+import { page, userEvent } from 'vite-plus/test/browser'+import { render } from 'vitest-browser-react'+import { useAppForm } from '@/app/components/base/form'+import { SupportUploadFileTypes } from '@/app/components/workflow/types'+import { consoleQuery } from '@/service/console'+import { createConsoleQueryClient, createConsoleQueryWrapper } from '@/test/console/query-data'+import { createFileUploadConfigFixture } from '@/test/fixtures/file-upload-config'+import { guardUnexpectedFetch } from '@/test/unexpected-fetch'+import { TransferMethod } from '@/types/app'+import CheckboxField from '../checkbox'+import FileTypesField from '../file-types'+import FileUploaderField from '../file-uploader'+import InputTypeSelectField from '../input-type-select'+import NumberInputField from '../number-input'+import NumberSliderField from '../number-slider'+import OptionsField from '../options'+import SelectField from '../select'+import TextAreaField from '../text-area'++vi.mock('@/next/navigation', async (importOriginal) => ({+ ...(await importOriginal<typeof import('@/next/navigation')>()),+ useParams: () => ({ token: 'test-token' }),+ usePathname: () => '/',+}))++const renderField = async (field: ReactElement, initialValue: unknown) => {+ const Harness = () => {+ const form = useAppForm({ defaultValues: { value: initialValue } })+ return (+ <>+ <form.AppField name="value">{() => field}</form.AppField>+ <form.Subscribe selector={(state) => state.values}>+ {(values) => <output aria-label="Form values">{JSON.stringify(values)}</output>}+ </form.Subscribe>+ </>+ )+ }+ const queryClient = createConsoleQueryClient()+ queryClient.setQueryData(+ consoleQuery.files.upload.get.queryKey(),+ createFileUploadConfigFixture(),+ )+ const { wrapper: Wrapper } = createConsoleQueryWrapper({ queryClient })+ const screen = await render(+ <Wrapper>+ <Harness />+ </Wrapper>,+ )+ await expect.element(page.getByRole('status', { name: 'Form values' })).toBeVisible()+ return screen+}+const readValue = () =>+ JSON.parse(page.getByRole('status', { name: 'Form values' }).element().textContent!).value++it('writes checkbox changes to the form and supports toggling twice', async () => {+ await renderField(<CheckboxField label="Enabled" />, false)+ const checkbox = page.getByRole('checkbox', { name: 'Enabled' })+ await checkbox.click()+ await expect.element(checkbox).toBeChecked()+ await expect.poll(readValue).toBe(true)+ await checkbox.click()+ await expect.poll(readValue).toBe(false)+})++it('writes textarea edits into the form', async () => {+ await renderField(<TextAreaField label="Note" />, 'Initial')+ const input = page.getByRole('textbox', { name: 'Note' })+ await input.fill('')+ await input.fill('Updated')+ await expect.poll(readValue).toBe('Updated')+ await expect.element(input).toHaveValue('Updated')+})++it('writes numeric values, clamps edits and resets cleared values to zero', async () => {+ await renderField(<NumberInputField label="Count" min={0} max={10} />, 2)+ await page.getByRole('button', { name: 'Increment value' }).click()+ await expect.poll(readValue).toBe(3)+ const input = page.getByRole('textbox', { name: 'Count' })+ await input.fill('12')+ await userEvent.tab()+ await expect.poll(readValue).toBe(10)+ await input.click()+ await userEvent.tab()+ await expect.element(input).toHaveValue('10')+ await input.fill('')+ await expect.poll(readValue).toBe(0)+})++it('writes slider changes and clamps numeric input on blur', async () => {+ await renderField(<NumberSliderField label="Threshold" min={0} max={10} />, 2)+ const slider = page.getByRole('slider', { name: 'Threshold' })+ await page.getByRole('spinbutton', { name: 'Threshold' }).click()+ await userEvent.tab()+ await expect.element(slider).toHaveFocus()+ await userEvent.keyboard('{ArrowRight}')+ await expect.poll(readValue).toBe(3)+ const input = page.getByRole('spinbutton', { name: 'Threshold' })+ await input.fill('')+ await input.fill('12')+ await userEvent.tab()+ await expect.poll(readValue).toBe(10)+})++it('keeps the empty selection label and writes the chosen option to the form', async () => {+ await renderField(+ <SelectField+ label="Mode"+ options={[+ { label: 'None', value: '' },+ { label: 'Beta', value: 'beta' },+ ]}+ />,+ '',+ )+ const select = page.getByRole('combobox', { name: 'Mode' })+ await expect.element(select).toHaveTextContent('None')+ await select.click()+ await page.getByRole('option', { name: 'Beta' }).click()+ await expect.element(select).toHaveTextContent('Beta')+ await expect.poll(readValue).toBe('beta')+})++it('adds, edits and removes option strings in the form', async () => {+ await renderField(<OptionsField label="Options" />, ['Existing'])+ await page.getByRole('button', { name: 'appDebug.variableConfig.addOption' }).click()+ await page.getByRole('textbox', { name: 'appDebug.variableConfig.options 2' }).fill('Added')+ await expect.poll(readValue).toEqual(['Existing', 'Added'])+ await page.getByRole('button', { name: 'common.operation.delete' }).nth(0).click()+ await expect.poll(readValue).toEqual(['Added'])+})++it('switches between custom and standard file types without losing custom extensions', async () => {+ await renderField(<FileTypesField label="Allowed files" />, {+ allowedFileTypes: ['document'],+ allowedFileExtensions: [],+ })+ const customName = 'appDebug.variableConfig.file.custom.name'+ await page.getByRole('checkbox', { name: customName }).click()+ await expect.poll(readValue).toEqual({ allowedFileTypes: ['custom'], allowedFileExtensions: [] })+ await page.getByRole('textbox', { name: customName }).fill('.csv')+ await userEvent.keyboard('{Enter}')+ await expect+ .poll(readValue)+ .toEqual({ allowedFileTypes: ['custom'], allowedFileExtensions: ['.csv'] })+ await page.getByRole('checkbox', { name: 'appDebug.variableConfig.file.image.name' }).click()+ await expect+ .poll(readValue)+ .toEqual({ allowedFileTypes: ['image'], allowedFileExtensions: ['.csv'] })+ await page.getByRole('checkbox', { name: 'appDebug.variableConfig.file.image.name' }).click()+ await expect.poll(() => readValue().allowedFileTypes).toEqual([])+})++it.each([true, false])(+ 'writes input type choices and honors file support=%s',+ async (supportFile) => {+ await renderField(+ <InputTypeSelectField label="Input type" supportFile={supportFile} />,+ 'text-input',+ )+ await page.getByRole('combobox', { name: 'Input type' }).click()+ for (const name of [+ /appDebug.variableConfig.single-file/,+ /appDebug.variableConfig.multi-files/,+ ]) {+ if (supportFile) await expect.element(page.getByRole('option', { name })).toBeVisible()+ else await expect.element(page.getByRole('option', { name })).not.toBeInTheDocument()+ }+ if (supportFile) {+ await page.getByRole('option', { name: /appDebug.variableConfig.single-file/ }).click()+ await expect.poll(readValue).toBe('file')+ await expect.element(page.getByRole('listbox')).not.toBeInTheDocument()+ await page.getByRole('combobox', { name: 'Input type' }).click()+ await page.getByRole('option', { name: /appDebug.variableConfig.multi-files/ }).click()+ await expect.poll(readValue).toBe('file-list')+ await expect.element(page.getByRole('listbox')).not.toBeInTheDocument()+ await page.getByRole('combobox', { name: 'Input type' }).click()+ }+ await page.getByRole('option', { name: /appDebug.variableConfig.number/ }).click()+ await expect.poll(readValue).toBe('number')+ },+)++it('removes an uploaded file from both the field and the form state', async () => {+ await renderField(+ <FileUploaderField+ label="Attachments"+ fileConfig={{+ allowed_file_upload_methods: [TransferMethod.local_file],+ allowed_file_types: [SupportUploadFileTypes.document],+ }}+ />,+ [+ {+ id: 'file-1',+ name: 'report.pdf',+ size: 1024,+ type: 'application/pdf',+ progress: 100,+ transferMethod: TransferMethod.local_file,+ supportFileType: SupportUploadFileTypes.document,+ uploadedId: 'uploaded-1',+ url: 'https://example.com/report.pdf',+ },+ ],+ )+ await expect.element(page.getByText('report.pdf')).toBeVisible()+ await page.getByRole('button', { name: /remove|delete/i }).click()+ await expect.element(page.getByText('report.pdf')).not.toBeInTheDocument()+ await expect.poll(readValue).toEqual([])+})++beforeEach(async () => {+ await page.viewport(1280, 900)+ onTestFinished(guardUnexpectedFetch())+})diff --git a/web/app/components/base/form/components/field/__tests__/field-integration.spec.tsx b/web/app/components/base/form/components/field/__tests__/field-integration.spec.tsxdeleted file mode 100644index d57bd099879..00000000000--- a/web/app/components/base/form/components/field/__tests__/field-integration.spec.tsx+++ /dev/null@@ -1,199 +0,0 @@-import type { ReactElement } from 'react'-import { fireEvent, screen, waitFor } from '@testing-library/react'-import userEvent from '@testing-library/user-event'-import { useAppForm } from '@/app/components/base/form'-import { SupportUploadFileTypes } from '@/app/components/workflow/types'-import { consoleQuery } from '@/service/console'-import { createConsoleQueryClient, renderWithConsoleQuery } from '@/test/console/query-data'-import { createFileUploadConfigFixture } from '@/test/fixtures/file-upload-config'-import { TransferMethod } from '@/types/app'-import CheckboxField from '../checkbox'-import FileTypesField from '../file-types'-import FileUploaderField from '../file-uploader'-import InputTypeSelectField from '../input-type-select'-import NumberInputField from '../number-input'-import NumberSliderField from '../number-slider'-import OptionsField from '../options'-import SelectField from '../select'-import TextAreaField from '../text-area'--vi.mock('@/next/navigation', async (importOriginal) => ({- ...(await importOriginal<typeof import('@/next/navigation')>()),- useParams: () => ({ token: 'test-token' }),- usePathname: () => '/',-}))--const renderField = (field: ReactElement, initialValue: unknown) => {- const Harness = () => {- const form = useAppForm({ defaultValues: { value: initialValue } })- return (- <>- <form.AppField name="value">{() => field}</form.AppField>- <form.Subscribe selector={(state) => state.values}>- {(values) => <output aria-label="Form values">{JSON.stringify(values)}</output>}- </form.Subscribe>- </>- )- }- const queryClient = createConsoleQueryClient()- queryClient.setQueryData(- consoleQuery.files.upload.get.queryKey(),- createFileUploadConfigFixture(),- )- return renderWithConsoleQuery(<Harness />, { queryClient })-}-const readValue = () =>- JSON.parse(screen.getByRole('status', { name: 'Form values' }).textContent!).value--it('writes checkbox changes to the form and supports toggling twice', async () => {- const user = userEvent.setup()- renderField(<CheckboxField label="Enabled" />, false)- const checkbox = screen.getByRole('checkbox', { name: 'Enabled' })- await user.click(checkbox)- expect(checkbox).toBeChecked()- expect(readValue()).toBe(true)- await user.click(checkbox)- expect(readValue()).toBe(false)-})--it('writes textarea edits into the form', async () => {- const user = userEvent.setup()- renderField(<TextAreaField label="Note" />, 'Initial')- const input = screen.getByRole('textbox', { name: 'Note' })- await user.clear(input)- await user.type(input, 'Updated')- expect(readValue()).toBe('Updated')- expect(input).toHaveValue('Updated')-})--it('writes numeric values, clamps edits and resets cleared values to zero', async () => {- const user = userEvent.setup()- renderField(<NumberInputField label="Count" min={0} max={10} />, 2)- await user.click(screen.getByRole('button', { name: 'Increment value' }))- expect(readValue()).toBe(3)- const input = screen.getByRole('textbox', { name: 'Count' })- fireEvent.change(input, { target: { value: '12' } })- expect(readValue()).toBe(10)- await user.click(input)- await user.tab()- await waitFor(() => expect(input).toHaveValue('10'))- await user.clear(input)- expect(readValue()).toBe(0)-})--it('writes slider changes and clamps numeric input on blur', async () => {- const user = userEvent.setup()- renderField(<NumberSliderField label="Threshold" min={0} max={10} />, 2)- const slider = screen.getByRole('slider', { name: 'Threshold' })- slider.focus()- await user.keyboard('{ArrowRight}')- expect(readValue()).toBe(3)- const input = screen.getByRole('spinbutton', { name: 'Threshold' })- await user.clear(input)- await user.type(input, '12')- await user.tab()- expect(readValue()).toBe(10)-})--it('keeps the empty selection label and writes the chosen option to the form', async () => {- const user = userEvent.setup()- renderField(- <SelectField- label="Mode"- options={[- { label: 'None', value: '' },- { label: 'Beta', value: 'beta' },- ]}- />,- '',- )- const select = screen.getByRole('combobox', { name: 'Mode' })- expect(select).toHaveTextContent('None')- await user.click(select)- await user.click(screen.getByRole('option', { name: 'Beta' }))- expect(select).toHaveTextContent('Beta')- expect(readValue()).toBe('beta')-})--it('adds, edits and removes option strings in the form', async () => {- const user = userEvent.setup()- renderField(<OptionsField label="Options" />, ['Existing'])- await user.click(screen.getByRole('button', { name: 'appDebug.variableConfig.addOption' }))- await user.type(- screen.getByRole('textbox', { name: 'appDebug.variableConfig.options 2' }),- 'Added',- )- expect(readValue()).toEqual(['Existing', 'Added'])- await user.click(screen.getAllByRole('button', { name: 'common.operation.delete' })[0]!)- expect(readValue()).toEqual(['Added'])-})--it('switches between custom and standard file types without losing custom extensions', async () => {- const user = userEvent.setup()- renderField(<FileTypesField label="Allowed files" />, {- allowedFileTypes: ['document'],- allowedFileExtensions: [],- })- const customName = 'appDebug.variableConfig.file.custom.name'- await user.click(screen.getByRole('checkbox', { name: customName }))- expect(readValue()).toEqual({ allowedFileTypes: ['custom'], allowedFileExtensions: [] })- await user.type(screen.getByRole('textbox', { name: customName }), '.csv{Enter}')- expect(readValue()).toEqual({ allowedFileTypes: ['custom'], allowedFileExtensions: ['.csv'] })- await user.click(- screen.getByRole('checkbox', { name: 'appDebug.variableConfig.file.image.name' }),- )- expect(readValue()).toEqual({ allowedFileTypes: ['image'], allowedFileExtensions: ['.csv'] })- await user.click(- screen.getByRole('checkbox', { name: 'appDebug.variableConfig.file.image.name' }),- )- expect(readValue().allowedFileTypes).toEqual([])-})--it.each([true, false])(- 'writes input type choices and honors file support=%s',- async (supportFile) => {- const user = userEvent.setup()- renderField(<InputTypeSelectField label="Input type" supportFile={supportFile} />, 'text-input')- await user.click(screen.getByRole('combobox', { name: 'Input type' }))- if (supportFile)- expect(- screen.getByRole('option', { name: /appDebug.variableConfig.single-file/ }),- ).toBeInTheDocument()- else- expect(- screen.queryByRole('option', { name: /appDebug.variableConfig.single-file/ }),- ).not.toBeInTheDocument()- await user.click(screen.getByRole('option', { name: /appDebug.variableConfig.number/ }))- expect(readValue()).toBe('number')- },-)--it('removes an uploaded file from both the field and the form state', async () => {- const user = userEvent.setup()- renderField(- <FileUploaderField- label="Attachments"- fileConfig={{- allowed_file_upload_methods: [TransferMethod.local_file],- allowed_file_types: [SupportUploadFileTypes.document],- }}- />,- [- {- id: 'file-1',- name: 'report.pdf',- size: 1024,- type: 'application/pdf',- progress: 100,- transferMethod: TransferMethod.local_file,- supportFileType: SupportUploadFileTypes.document,- uploadedId: 'uploaded-1',- url: 'https://example.com/report.pdf',- },- ],- )- expect(screen.getByText('report.pdf')).toBeInTheDocument()- await user.click(screen.getByRole('button', { name: /remove|delete/i }))- expect(screen.queryByText('report.pdf')).not.toBeInTheDocument()- expect(readValue()).toEqual([])-})diff --git a/web/app/components/base/form/components/field/__tests__/upload-method.browser.spec.tsx b/web/app/components/base/form/components/field/__tests__/upload-method.browser.spec.tsxnew file mode 100644index 00000000000..6bb04eb34c9--- /dev/null+++ b/web/app/components/base/form/components/field/__tests__/upload-method.browser.spec.tsx@@ -0,0 +1,64 @@+import { page, userEvent } from 'vite-plus/test/browser'+import { render } from 'vitest-browser-react'+import { guardUnexpectedFetch } from '@/test/unexpected-fetch'+import { TransferMethod } from '@/types/app'+import { useAppForm } from '../../..'++const UploadMethodForm = ({ onSubmit }: { onSubmit: (value: TransferMethod[]) => void }) => {+ const form = useAppForm({+ defaultValues: { methods: [TransferMethod.local_file] as TransferMethod[] },+ onSubmit: ({ value }) => onSubmit(value.methods),+ })++ return (+ <form+ onSubmit={(event) => {+ event.preventDefault()+ void form.handleSubmit()+ }}+ >+ <form.AppField name="methods">+ {(field) => <field.UploadMethodField label="Upload methods" />}+ </form.AppField>+ <button type="submit">Save</button>+ </form>+ )+}++describe('UploadMethodField', () => {+ it('saves both upload methods as the existing array representation', async () => {+ const onSubmit = vi.fn()+ await render(<UploadMethodForm onSubmit={onSubmit} />)++ await expect.element(page.getByRole('radiogroup', { name: 'Upload methods' })).toBeVisible()+ await userEvent.tab()+ await expect+ .element(page.getByRole('radio', { name: 'appDebug.variableConfig.localUpload' }))+ .toHaveFocus()+ await userEvent.keyboard('{ArrowRight}')+ await expect.element(page.getByRole('radio', { name: 'URL' })).toBeChecked()+ await userEvent.keyboard('{ArrowRight}')+ await expect+ .element(page.getByRole('radio', { name: 'appDebug.variableConfig.both' }))+ .toBeChecked()+ await page.getByRole('button', { name: 'Save' }).click()+ await expect+ .poll(() => onSubmit.mock.calls)+ .toEqual([[[TransferMethod.local_file, TransferMethod.remote_url]]])+ })++ it('lets users select a card by its visible label and saves only URL upload', async () => {+ const onSubmit = vi.fn()+ await render(<UploadMethodForm onSubmit={onSubmit} />)++ await page.getByRole('radio', { name: 'URL' }).click()+ await expect.element(page.getByRole('radio', { name: 'URL' })).toBeChecked()+ await page.getByRole('button', { name: 'Save' }).click()+ await expect.poll(() => onSubmit.mock.calls).toEqual([[[TransferMethod.remote_url]]])+ })+})++beforeEach(async () => {+ await page.viewport(1280, 900)+ onTestFinished(guardUnexpectedFetch())+})diff --git a/web/app/components/base/form/components/field/__tests__/upload-method.spec.tsx b/web/app/components/base/form/components/field/__tests__/upload-method.spec.tsxdeleted file mode 100644index 0816171aa01..00000000000--- a/web/app/components/base/form/components/field/__tests__/upload-method.spec.tsx+++ /dev/null@@ -1,49 +0,0 @@-import { render, screen } from '@testing-library/react'-import userEvent from '@testing-library/user-event'-import { TransferMethod } from '@/types/app'-import { useAppForm } from '../../..'--const UploadMethodForm = ({ onSubmit }: { onSubmit: (value: TransferMethod[]) => void }) => {- const form = useAppForm({- defaultValues: { methods: [TransferMethod.local_file] as TransferMethod[] },- onSubmit: ({ value }) => onSubmit(value.methods),- })-- return (- <form- onSubmit={(event) => {- event.preventDefault()- void form.handleSubmit()- }}- >- <form.AppField name="methods">- {(field) => <field.UploadMethodField label="Upload methods" />}- </form.AppField>- <button type="submit">Save</button>- </form>- )-}--describe('UploadMethodField', () => {- it('saves both upload methods as the existing array representation', async () => {- const user = userEvent.setup()- const onSubmit = vi.fn()- render(<UploadMethodForm onSubmit={onSubmit} />)-- expect(screen.getByRole('radiogroup', { name: 'Upload methods' })).toBeInTheDocument()- await user.click(screen.getByRole('radio', { name: 'appDebug.variableConfig.both' }))- await user.click(screen.getByRole('button', { name: 'Save' }))- expect(onSubmit).toHaveBeenCalledWith([TransferMethod.local_file, TransferMethod.remote_url])- })-- it('lets users select a card by its visible label and saves only URL upload', async () => {- const user = userEvent.setup()- const onSubmit = vi.fn()- render(<UploadMethodForm onSubmit={onSubmit} />)-- await user.click(screen.getByRole('radio', { name: 'URL' }))- expect(screen.getByRole('radio', { name: 'URL' })).toBeChecked()- await user.click(screen.getByRole('button', { name: 'Save' }))- expect(onSubmit).toHaveBeenCalledWith([TransferMethod.remote_url])- })-})diff --git a/web/app/components/base/form/components/field/input-type-select/__tests__/hooks.spec.tsx b/web/app/components/base/form/components/field/input-type-select/__tests__/hooks.spec.tsxdeleted file mode 100644index 34e9ecc0a46..00000000000--- a/web/app/components/base/form/components/field/input-type-select/__tests__/hooks.spec.tsx+++ /dev/null@@ -1,20 +0,0 @@-import { renderHook } from '@testing-library/react'-import { useInputTypeOptions } from '../hooks'--describe('useInputTypeOptions', () => {- it('should include file options when supportFile is true', () => {- const { result } = renderHook(() => useInputTypeOptions(true))- const values = result.current.map((item) => item.value)-- expect(values).toContain('file')- expect(values).toContain('file-list')- })-- it('should exclude file options when supportFile is false', () => {- const { result } = renderHook(() => useInputTypeOptions(false))- const values = result.current.map((item) => item.value)-- expect(values).not.toContain('file')- expect(values).not.toContain('file-list')- })-})diff --git a/web/app/components/base/form/components/form/__tests__/actions.spec.tsx b/web/app/components/base/form/components/form/__tests__/actions.browser.spec.tsxsimilarity index 58%rename from web/app/components/base/form/components/form/__tests__/actions.spec.tsxrename to web/app/components/base/form/components/form/__tests__/actions.browser.spec.tsxindex b349149a7d8..a8614bd00b5 100644--- a/web/app/components/base/form/components/form/__tests__/actions.spec.tsx+++ b/web/app/components/base/form/components/form/__tests__/actions.browser.spec.tsx@@ -1,6 +1,7 @@import type { CustomActionsProps } from '../actions'-import { act, render, screen, waitFor } from '@testing-library/react'-import userEvent from '@testing-library/user-event'+import { page, userEvent } from 'vite-plus/test/browser'+import { render } from 'vitest-browser-react'+import { guardUnexpectedFetch } from '@/test/unexpected-fetch'import { useAppForm } from '../../..'const TestForm = ({@@ -26,33 +27,31 @@ const TestForm = ({describe('Actions', () => {it('disables submission when the form is invalid', async () => {- render(<TestForm invalid />)- await waitFor(() =>- expect(screen.getByRole('button', { name: 'common.operation.submit' })).toBeDisabled(),- )+ await render(<TestForm invalid />)+ await expect+ .element(page.getByRole('button', { name: 'common.operation.submit' }))+ .toBeDisabled()})it('keeps the pending button focusable and prevents duplicate submissions', async () => {- const user = userEvent.setup()let finishSubmit!: () => voidconst pending = new Promise<void>((resolve) => {finishSubmit = resolve})const onSubmit = vi.fn(() => pending)- render(<TestForm onSubmit={onSubmit} />)- const button = screen.getByRole('button', { name: 'common.operation.submit' })- await user.click(button)- await waitFor(() => expect(button).toHaveAttribute('aria-disabled', 'true'))- expect(button).not.toBeDisabled()- expect(button).toHaveFocus()- await user.click(button)+ await render(<TestForm onSubmit={onSubmit} />)+ const button = page.getByRole('button', { name: 'common.operation.submit' })+ await button.click()+ await expect.element(button).toHaveAttribute('aria-disabled', 'true')+ await expect.element(button).not.toHaveAttribute('disabled')+ await expect.element(button).toHaveFocus()+ await userEvent.keyboard('{Enter}')expect(onSubmit).toHaveBeenCalledOnce()- await act(async () => finishSubmit())- await waitFor(() => expect(button).not.toHaveAttribute('aria-disabled', 'true'))+ finishSubmit()+ await expect.element(button).not.toHaveAttribute('aria-disabled', 'true')})it('lets custom actions submit the form and observe pending state', async () => {- const user = userEvent.setup()let finish!: () => voidconst onSubmit = vi.fn(() =>@@ -60,7 +59,7 @@ describe('Actions', () => {finish = resolve}),)- render(+ await render(<TestFormonSubmit={onSubmit}CustomActions={({ form, isSubmitting, canSubmit }) => (@@ -75,10 +74,15 @@ describe('Actions', () => {/>,)- await user.click(screen.getByRole('button', { name: 'Save' }))- expect(await screen.findByRole('button', { name: 'Saving' })).toBeDisabled()+ await page.getByRole('button', { name: 'Save' }).click()+ await expect.element(page.getByRole('button', { name: 'Saving' })).toBeDisabled()expect(onSubmit).toHaveBeenCalledOnce()- await act(async () => finish())- expect(await screen.findByRole('button', { name: 'Save' })).toBeEnabled()+ finish()+ await expect.element(page.getByRole('button', { name: 'Save' })).toBeEnabled()})})++beforeEach(async () => {+ await page.viewport(1280, 900)+ onTestFinished(guardUnexpectedFetch())+})diff --git a/web/app/components/base/form/form-scenarios/base/__tests__/field.browser.spec.tsx b/web/app/components/base/form/form-scenarios/base/__tests__/field.browser.spec.tsxnew file mode 100644index 00000000000..5fd89169442--- /dev/null+++ b/web/app/components/base/form/form-scenarios/base/__tests__/field.browser.spec.tsx@@ -0,0 +1,87 @@+import type { BaseConfiguration } from '../types'+import { useMemo } from 'react'+import { page, userEvent } from 'vite-plus/test/browser'+import { render } from 'vitest-browser-react'+import { guardUnexpectedFetch } from '@/test/unexpected-fetch'+import { useAppForm } from '../../..'+import BaseField from '../field'+import { BaseFieldType } from '../types'++const configs: BaseConfiguration[] = [+ {+ type: BaseFieldType.checkbox,+ variable: 'enabled',+ label: 'Advanced settings',+ required: false,+ showConditions: [],+ },+ {+ type: BaseFieldType.textInput,+ variable: 'token',+ label: 'Token',+ required: false,+ showConditions: [+ { variable: 'enabled', value: true },+ { variable: 'mode', value: 'custom' },+ ],+ },+ {+ type: BaseFieldType.select,+ variable: 'mode',+ label: 'Mode',+ required: false,+ showConditions: [],+ options: [+ { value: 'default', label: 'Default' },+ { value: 'custom', label: 'Custom' },+ ],+ },+]+const initialData: Record<string, unknown> = {+ enabled: false,+ token: 'saved-token',+ mode: 'default',+}+function Form() {+ const form = useAppForm({ defaultValues: initialData })+ const fields = useMemo(() => configs.map((config) => BaseField({ initialData, config })), [])+ return (+ <>+ {fields.map((Field, index) => (+ <Field key={configs[index]!.variable} form={form} />+ ))}+ <form.Subscribe selector={(state) => state.values}>+ {(values) => <output aria-label="Form values">{JSON.stringify(values)}</output>}+ </form.Subscribe>+ </>+ )+}++it('uses live field values to reveal a field only when all conditions match and preserves its value while hidden', async () => {+ await render(<Form />)+ await expect.element(page.getByRole('textbox', { name: 'Token' })).not.toBeInTheDocument()+ await page.getByRole('checkbox', { name: 'Advanced settings' }).click()+ await expect.element(page.getByRole('textbox', { name: 'Token' })).not.toBeInTheDocument()+ await page.getByRole('combobox', { name: 'Mode' }).click()+ await expect.element(page.getByRole('option', { name: 'Default' })).toHaveFocus()+ await userEvent.keyboard('{ArrowDown}')+ await expect.element(page.getByRole('option', { name: 'Custom' })).toHaveFocus()+ await userEvent.keyboard('{Enter}')+ await expect.element(page.getByRole('listbox')).not.toBeInTheDocument()+ const token = page.getByRole('textbox', { name: 'Token' })+ await expect.element(token).toHaveValue('saved-token')+ await token.fill('')+ await token.fill('new-token')+ await expect+ .element(page.getByRole('status', { name: 'Form values' }))+ .toHaveTextContent('{"enabled":true,"token":"new-token","mode":"custom"}')+ await page.getByRole('checkbox', { name: 'Advanced settings' }).click()+ await expect.element(page.getByRole('textbox', { name: 'Token' })).not.toBeInTheDocument()+ await page.getByRole('checkbox', { name: 'Advanced settings' }).click()+ await expect.element(page.getByRole('textbox', { name: 'Token' })).toHaveValue('new-token')+})++beforeEach(async () => {+ await page.viewport(1280, 900)+ onTestFinished(guardUnexpectedFetch())+})diff --git a/web/app/components/base/form/form-scenarios/base/__tests__/field.spec.tsx b/web/app/components/base/form/form-scenarios/base/__tests__/field.spec.tsxdeleted file mode 100644index baf1c5e00f2..00000000000--- a/web/app/components/base/form/form-scenarios/base/__tests__/field.spec.tsx+++ /dev/null@@ -1,78 +0,0 @@-import type { BaseConfiguration } from '../types'-import { render, screen } from '@testing-library/react'-import userEvent from '@testing-library/user-event'-import { useMemo } from 'react'-import { useAppForm } from '../../..'-import BaseField from '../field'-import { BaseFieldType } from '../types'--const configs: BaseConfiguration[] = [- {- type: BaseFieldType.checkbox,- variable: 'enabled',- label: 'Advanced settings',- required: false,- showConditions: [],- },- {- type: BaseFieldType.textInput,- variable: 'token',- label: 'Token',- required: false,- showConditions: [- { variable: 'enabled', value: true },- { variable: 'mode', value: 'custom' },- ],- },- {- type: BaseFieldType.select,- variable: 'mode',- label: 'Mode',- required: false,- showConditions: [],- options: [- { value: 'default', label: 'Default' },- { value: 'custom', label: 'Custom' },- ],- },-]-const initialData: Record<string, unknown> = {- enabled: false,- token: 'saved-token',- mode: 'default',-}-function Form() {- const form = useAppForm({ defaultValues: initialData })- const fields = useMemo(() => configs.map((config) => BaseField({ initialData, config })), [])- return (- <>- {fields.map((Field, index) => (- <Field key={configs[index]!.variable} form={form} />- ))}- <form.Subscribe selector={(state) => state.values}>- {(values) => <output aria-label="Form values">{JSON.stringify(values)}</output>}- </form.Subscribe>- </>- )-}--it('uses live field values to reveal a field only when all conditions match and preserves its value while hidden', async () => {- const user = userEvent.setup()- render(<Form />)- expect(screen.queryByRole('textbox', { name: 'Token' })).not.toBeInTheDocument()- await user.click(screen.getByRole('checkbox', { name: 'Advanced settings' }))- expect(screen.queryByRole('textbox', { name: 'Token' })).not.toBeInTheDocument()- await user.click(screen.getByRole('combobox', { name: 'Mode' }))- await user.click(await screen.findByRole('option', { name: 'Custom' }))- const token = screen.getByRole('textbox', { name: 'Token' })- expect(token).toHaveValue('saved-token')- await user.clear(token)- await user.type(token, 'new-token')- expect(screen.getByRole('status', { name: 'Form values' })).toHaveTextContent(- '"token":"new-token"',- )- await user.click(screen.getByRole('checkbox', { name: 'Advanced settings' }))- expect(screen.queryByRole('textbox', { name: 'Token' })).not.toBeInTheDocument()- await user.click(screen.getByRole('checkbox', { name: 'Advanced settings' }))- expect(screen.getByRole('textbox', { name: 'Token' })).toHaveValue('new-token')-})diff --git a/web/app/components/base/form/form-scenarios/input-field/__tests__/field.spec.tsx b/web/app/components/base/form/form-scenarios/input-field/__tests__/field.browser.spec.tsxsimilarity index 56%rename from web/app/components/base/form/form-scenarios/input-field/__tests__/field.spec.tsxrename to web/app/components/base/form/form-scenarios/input-field/__tests__/field.browser.spec.tsxindex 2644c34df06..774c76a1565 100644--- a/web/app/components/base/form/form-scenarios/input-field/__tests__/field.spec.tsx+++ b/web/app/components/base/form/form-scenarios/input-field/__tests__/field.browser.spec.tsx@@ -1,7 +1,8 @@import type { InputFieldConfiguration } from '../types'-import { render, screen } from '@testing-library/react'-import userEvent from '@testing-library/user-event'import { useMemo } from 'react'+import { page, userEvent } from 'vite-plus/test/browser'+import { render } from 'vitest-browser-react'+import { guardUnexpectedFetch } from '@/test/unexpected-fetch'import { useAppForm } from '../../..'import InputField from '../field'import { InputFieldType } from '../types'@@ -51,16 +52,29 @@ it('notifies a field listener with the edited value and reveals dependent config</>)}- const user = userEvent.setup()- render(<Form />)- await user.type(screen.getByRole('textbox', { name: /Name/ }), 'Input name')++ await render(<Form />)+ await page.getByRole('textbox', { name: /Name/ }).fill('Input name')expect(onChange).toHaveBeenLastCalledWith('Input name')- expect(screen.getByRole('status', { name: 'Form values' })).toHaveTextContent(- '"name":"Input name"',- )- expect(screen.queryByRole('textbox', { name: 'Description' })).not.toBeInTheDocument()- await user.click(screen.getByRole('checkbox', { name: 'Enable description' }))- expect(screen.getByRole('textbox', { name: 'Description' })).toHaveValue('Saved description')- await user.click(screen.getByRole('checkbox', { name: 'Enable description' }))- expect(screen.queryByRole('textbox', { name: 'Description' })).not.toBeInTheDocument()+ await expect+ .element(page.getByRole('status', { name: 'Form values' }))+ .toHaveTextContent('{"name":"Input name","enabled":false,"description":"Saved description"}')+ await expect.element(page.getByRole('textbox', { name: 'Description' })).not.toBeInTheDocument()+ await userEvent.tab()+ await expect.element(page.getByRole('checkbox', { name: 'Enable description' })).toHaveFocus()+ await userEvent.keyboard(' ')+ await expect+ .element(page.getByRole('textbox', { name: 'Description' }))+ .toHaveValue('Saved description')+ await userEvent.tab()+ await expect.element(page.getByRole('textbox', { name: 'Description' })).toHaveFocus()+ await userEvent.tab({ shift: true })+ await expect.element(page.getByRole('checkbox', { name: 'Enable description' })).toHaveFocus()+ await userEvent.keyboard(' ')+ await expect.element(page.getByRole('textbox', { name: 'Description' })).not.toBeInTheDocument()+})++beforeEach(async () => {+ await page.viewport(1280, 900)+ onTestFinished(guardUnexpectedFetch())})