Skip to content

Comments

add test for input widget#2667

Merged
hayescode merged 1 commit intoChainlit:mainfrom
codomposer:feat/test_input_widget
Nov 20, 2025
Merged

add test for input widget#2667
hayescode merged 1 commit intoChainlit:mainfrom
codomposer:feat/test_input_widget

Conversation

@codomposer
Copy link
Contributor

@codomposer codomposer commented Nov 19, 2025

Add Comprehensive Test Suite for InputWidget Classes

Overview

This PR adds a comprehensive test suite for all InputWidget classes in the Chainlit backend, ensuring robust coverage of widget initialization, validation, and serialization across all widget types.

Changes

New Test File

  • tests/test_input_widget.py - Complete test coverage for all InputWidget types

Test Coverage

Base InputWidget Validation (TestInputWidgetBase)

  • Validation that all widgets require both id and label
  • Error handling for missing required fields

Widget Types Tested

1. Switch Widget (TestSwitchWidget)

  • Boolean toggle initialization
  • Initial value configuration
  • Tooltip and description support
  • Disabled state handling
  • Serialization to dictionary

2. Slider Widget (TestSliderWidget)

  • Numeric range configuration (min, max, step)
  • Initial value setting
  • Custom range validation
  • Serialization with all parameters

3. Select Widget (TestSelectWidget)

  • Initialization with values list
  • Initialization with items dictionary
  • Initial selection via initial_index
  • Initial selection via initial_value
  • Validation: requires either values or items
  • Validation: cannot have both values and items
  • Validation: initial_index requires values
  • Proper items transformation and serialization

4. TextInput Widget (TestTextInputWidget)

  • Single-line and multiline modes
  • Initial value and placeholder text
  • Text input configuration
  • Serialization with all options

5. NumberInput Widget (TestNumberInputWidget)

  • Numeric input initialization
  • Initial value and placeholder
  • Float number support
  • Serialization

6. Tags Widget (TestTagsWidget)

  • Array of strings input
  • Initial tags configuration
  • Available values list
  • Serialization

7. MultiSelect Widget (TestMultiSelectWidget)

  • Multiple selection with values list
  • Multiple selection with items dictionary
  • Initial selection array
  • Validation: requires either values or items
  • Validation: cannot have both values and items
  • Items transformation and serialization

8. Checkbox Widget (TestCheckboxWidget)

  • Boolean checkbox initialization
  • Initial checked state
  • Tooltip and description
  • Serialization

9. RadioGroup Widget (TestRadioGroupWidget)

  • Radio button group with values list
  • Radio button group with items dictionary
  • Initial selection via initial_index
  • Initial selection via initial_value
  • Validation: requires either values or items
  • Validation: cannot have both values and items
  • Validation: initial_index requires values
  • Serialization with items array

10. Tab Widget (TestTabWidget)

  • Tab container initialization
  • Tab with nested input widgets
  • Empty tab handling
  • Serialization with nested inputs

Test Statistics

  • Total Tests: 75+
  • Test Classes: 11
  • Widget Types Covered: 10
  • Coverage Areas:
    • Widget initialization and defaults
    • Validation and error handling
    • Serialization (to_dict())
    • Common fields (tooltip, description, disabled)
    • Type-specific configurations
    • Edge cases and complex scenarios

Testing Approach

  • Pure unit tests (no async context needed for InputWidgets)
  • Comprehensive validation error testing
  • All widget types tested independently
  • Edge cases and complex scenarios covered
  • Consistent testing patterns across all widget types

Contribution by Gittensor, learn more at https://gittensor.io/

@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. backend Pertains to the Python backend. labels Nov 19, 2025
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Copy link
Contributor

@hayescode hayescode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codomposer looks great! May I ask what LLM you're using and how you're using it (GitHub Copilot, Cursor, etc.)?

@hayescode hayescode added this pull request to the merge queue Nov 20, 2025
Merged via the queue into Chainlit:main with commit 5e460f5 Nov 20, 2025
10 checks passed
@codomposer
Copy link
Contributor Author

@codomposer looks great! May I ask what LLM you're using and how you're using it (GitHub Copilot, Cursor, etc.)?

I've sent you email, hope to get connected there for more active communication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Pertains to the Python backend. size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants