-
Notifications
You must be signed in to change notification settings - Fork 0
feat(ui): add SelectField renderer to InspectorPane for enum-constrained strings #375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+284
−0
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
eea9505
feat(ui): add SelectField renderer to InspectorPane for enum-constrai…
streamkit-devin 58fc9f6
fix(ui): resolve SelectField value when currentValue is not in enum
streamkit-devin 4114221
style: format InspectorPane test file
streamkit-devin 2c31030
fix: add missing NodeDefinition fields and type casts in InspectorPan…
streamkit-devin 0a95778
fix(ui): validate schema.default against enum options in SelectField
streamkit-devin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,222 @@ | ||
| // SPDX-FileCopyrightText: © 2025 StreamKit Contributors | ||
| // | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| import { render, screen, fireEvent } from '@testing-library/react'; | ||
| import { describe, it, expect, vi, beforeEach } from 'vitest'; | ||
|
|
||
| import type { NodeDefinition } from '@/types/types'; | ||
|
|
||
| vi.mock('jotai/react', () => ({ | ||
| useAtomValue: () => ({}), | ||
| })); | ||
|
|
||
| vi.mock('@/stores/sessionAtoms', () => ({ | ||
| nodeParamsAtom: () => 'mock-atom', | ||
| })); | ||
|
|
||
| // Import after mocks are set up | ||
| const { default: InspectorPane } = await import('./InspectorPane'); | ||
|
|
||
| const baseNodeDefinition: NodeDefinition = { | ||
| kind: 'test-node', | ||
| description: 'A test node', | ||
| inputs: [], | ||
| outputs: [], | ||
| param_schema: {}, | ||
| categories: [], | ||
| bidirectional: false, | ||
| }; | ||
|
|
||
| const baseNode = { | ||
| id: 'node-1', | ||
| type: 'custom', | ||
| position: { x: 0, y: 0 }, | ||
| data: { label: 'TestNode', kind: 'test-node', params: {} }, | ||
| }; | ||
|
|
||
| describe('InspectorPane', () => { | ||
| let onParamChange: (nodeId: string, paramName: string, value: unknown) => void; | ||
| let onLabelChange: (nodeId: string, newLabel: string) => void; | ||
|
|
||
| beforeEach(() => { | ||
| onParamChange = vi.fn<(nodeId: string, paramName: string, value: unknown) => void>(); | ||
| onLabelChange = vi.fn<(nodeId: string, newLabel: string) => void>(); | ||
| }); | ||
|
|
||
| it('renders a select dropdown for enum-constrained string properties', () => { | ||
| const definition = { | ||
| ...baseNodeDefinition, | ||
| param_schema: { | ||
| properties: { | ||
| resolution: { | ||
| type: 'string', | ||
| enum: ['640x480', '1280x720', '1920x1080'], | ||
| description: 'Viewport resolution', | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| render( | ||
| <InspectorPane | ||
| node={{ ...baseNode, data: { ...baseNode.data, params: { resolution: '1280x720' } } }} | ||
| nodeDefinition={definition as NodeDefinition} | ||
| onParamChange={onParamChange} | ||
| onLabelChange={onLabelChange} | ||
| /> | ||
| ); | ||
|
|
||
| const select = screen.getByRole('combobox', { name: 'Viewport resolution' }); | ||
| expect(select).toBeInTheDocument(); | ||
| expect(select).toHaveValue('1280x720'); | ||
|
|
||
| const options = screen.getAllByRole('option'); | ||
| expect(options).toHaveLength(3); | ||
| expect(options[0]).toHaveTextContent('640x480'); | ||
| expect(options[1]).toHaveTextContent('1280x720'); | ||
| expect(options[2]).toHaveTextContent('1920x1080'); | ||
| }); | ||
|
|
||
| it('falls back to first enum value when current value does not match any option', () => { | ||
| const definition = { | ||
| ...baseNodeDefinition, | ||
| param_schema: { | ||
| properties: { | ||
| resolution: { | ||
| type: 'string', | ||
| enum: ['640x480', '1280x720', '1920x1080'], | ||
| description: 'Viewport resolution', | ||
| tunable: true, | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| render( | ||
| <InspectorPane | ||
| node={baseNode} | ||
| nodeDefinition={definition as NodeDefinition} | ||
| onParamChange={onParamChange} | ||
| onLabelChange={onLabelChange} | ||
| /> | ||
| ); | ||
|
|
||
| const select = screen.getByRole('combobox', { name: 'Viewport resolution' }); | ||
| expect(select).toHaveValue('640x480'); | ||
| }); | ||
|
|
||
| it('falls back to first enum value when schema.default is not in enum', () => { | ||
| const definition = { | ||
| ...baseNodeDefinition, | ||
| param_schema: { | ||
| properties: { | ||
| resolution: { | ||
| type: 'string', | ||
| enum: ['640x480', '1280x720'], | ||
| default: 'not-a-valid-option', | ||
| description: 'Viewport resolution', | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| render( | ||
| <InspectorPane | ||
| node={baseNode} | ||
| nodeDefinition={definition as NodeDefinition} | ||
| onParamChange={onParamChange} | ||
| onLabelChange={onLabelChange} | ||
| /> | ||
| ); | ||
|
|
||
| const select = screen.getByRole('combobox', { name: 'Viewport resolution' }); | ||
| expect(select).toHaveValue('640x480'); | ||
| }); | ||
|
|
||
| it('sends UpdateParams on selection change', () => { | ||
| const definition = { | ||
| ...baseNodeDefinition, | ||
| param_schema: { | ||
| properties: { | ||
| mode: { | ||
| type: 'string', | ||
| enum: ['fast', 'balanced', 'quality'], | ||
| description: 'Processing mode', | ||
| tunable: true, | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| render( | ||
| <InspectorPane | ||
| node={{ ...baseNode, data: { ...baseNode.data, params: { mode: 'fast' } } }} | ||
| nodeDefinition={definition as NodeDefinition} | ||
| onParamChange={onParamChange} | ||
| onLabelChange={onLabelChange} | ||
| isMonitorView | ||
| /> | ||
| ); | ||
|
|
||
| const select = screen.getByRole('combobox', { name: 'Processing mode' }); | ||
| fireEvent.change(select, { target: { value: 'quality' } }); | ||
|
|
||
| expect(onParamChange).toHaveBeenCalledWith('node-1', 'mode', 'quality'); | ||
| }); | ||
|
|
||
| it('renders a text input for non-enum string properties', () => { | ||
| const definition = { | ||
| ...baseNodeDefinition, | ||
| param_schema: { | ||
| properties: { | ||
| title: { | ||
| type: 'string', | ||
| description: 'Display title', | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| render( | ||
| <InspectorPane | ||
| node={baseNode} | ||
| nodeDefinition={definition as NodeDefinition} | ||
| onParamChange={onParamChange} | ||
| onLabelChange={onLabelChange} | ||
| /> | ||
| ); | ||
|
|
||
| expect(screen.queryByRole('combobox')).not.toBeInTheDocument(); | ||
| expect(screen.getByRole('textbox', { name: 'Display title' })).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('disables enum select for non-tunable params in monitor view', () => { | ||
| const definition = { | ||
| ...baseNodeDefinition, | ||
| param_schema: { | ||
| properties: { | ||
| resolution: { | ||
| type: 'string', | ||
| enum: ['640x480', '1280x720'], | ||
| description: 'Viewport resolution', | ||
| tunable: false, | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| render( | ||
| <InspectorPane | ||
| node={{ ...baseNode, data: { ...baseNode.data, params: { resolution: '640x480' } } }} | ||
| nodeDefinition={definition as NodeDefinition} | ||
| onParamChange={onParamChange} | ||
| onLabelChange={onLabelChange} | ||
| isMonitorView | ||
| /> | ||
| ); | ||
|
|
||
| const select = screen.getByRole('combobox', { name: 'Viewport resolution' }); | ||
| expect(select).toBeDisabled(); | ||
| }); | ||
| }); |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.