Skip to content

Added Test-cases InputValidator Plugin #4

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
merged 2 commits into from
Feb 25, 2025

Conversation

tasbi03
Copy link
Contributor

@tasbi03 tasbi03 commented Nov 28, 2024

Description

This pull request introduces comprehensive unit tests and configurations for the input-validator project, improving the test coverage, validating core functionality, and enhancing code quality and reliability.


What change does this PR introduce?

Added Unit Tests:

  • Core Functionality:

    • validateFile.test.ts: Tests various cases for file validation (valid, invalid, empty, and oversized files).
    • getValidator.test.ts: Ensures the getValidator utility retrieves correct validators or returns undefined for invalid cases.
    • getPromptStyles.test.ts: Validates style generation for different prompt types (error, success, etc.).
    • mergePluginConfig.test.ts: Ensures user configurations are merged properly with default plugin configurations.
    • useRcbPlugin.test.ts: Tests plugin behavior including text input, file upload validations, and event handling.
  • Configuration Files:

    • jest.config.js: Configures Jest for testing.
    • setup.jest.js: Adds polyfills (e.g., structuredClone) and sets up the environment for consistent test execution.

Closes issue #3

What is the proposed approach?

The PR covers:

  1. Comprehensive Testing:
    • Tests edge cases for file and text validation logic.
    • Ensures utility functions (mergePluginConfig, getValidator, getPromptStyles) behave correctly under various configurations.
    • Validates plugin behavior including event listeners and style restoration.
  2. Improved Code Coverage:
    • Focused on untested lines and branches to achieve near-complete coverage.
    • Adds tests for scenarios like null/undefined inputs, event listener behavior, and default configurations.
  3. Environment Setup:
    • Configures Jest and introduces setup.jest.js to provide consistent polyfills for structuredClone and other necessary utilities.

Checklist:

  • Added unit tests for validateFile, getValidator, mergePluginConfig, getPromptStyles, and useRcbPlugin.
  • Configured jest.config.js for comprehensive test runs.
  • Introduced setup.jest.js for environment consistency.
  • Verified test coverage and addressed untested lines or branches.

Testing Summary:

This PR ensures:

  • Core functionality and utility methods are validated against edge cases.
  • Styles and plugin configurations are correctly managed.
  • Event listeners in useRcbPlugin behave as expected for text inputs and file uploads.

Feel free to review and suggest additional improvements or scenarios for coverage.

Copy link
Member

@tjtanjin tjtanjin left a comment

Choose a reason for hiding this comment

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

Hey @tasbi03! Thanks for the PR, the test cases look great, though a couple of stuffs to cleanup:

  • Lint errors need to be fixed
  • Remove unnecessary packages in package file
  • Add the coverage folder to gitignore (coverage files shouldn't be committed)

@tasbi03 tasbi03 requested a review from tjtanjin December 7, 2024 03:27
@tjtanjin tjtanjin merged commit 7dd46b7 into React-ChatBotify-Plugins:main Feb 25, 2025
4 checks passed
@tjtanjin tjtanjin mentioned this pull request Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants