DEV Community

Cleo Buenaventura
Cleo Buenaventura

Posted on

Learning and Growing Through Open Source Contributions

Contributing to open-source projects is always an opportunity to refine skills and face new challenges. This time, I worked on improving unit test coverage for two components ,LoadingSpinner and FileAttachmentButton, in the React project react-chatbotify. These contributions allowed me to explore more advanced testing techniques, particularly mocking, and ensured robust functionality and styling validation.

GitHub logo tjtanjin / react-chatbotify

A modern React library for creating flexible and extensible chatbots.

React ChatBotify

Table of Contents

Introduction

Welcome to React ChatBotify, an intuitive and versatile library that allows you to build responsive chatbots with ease. Whether you're aiming to create a simple FAQ bot or a sophisticated conversational interface integrated with Large Language Models (LLMs), React ChatBotify provides the tools and flexibility you need to bring your vision to life.

Designed with developers in mind, React ChatBotify simplifies the chatbot development process without compromising on functionality. Its intuitive API and comprehensive customization options allow you to tailor your chatbot to meet specific project requirements seamlessly. From handling basic interactions to managing complex and advanced conversational flows, our library empowers you to deliver engaging user experiences. Head over to our community showcases or join our discord to get inspired and start crafting your chatbot today!

React ChatBotify is currently compatible with React versions




Issues and PR

LoadingSpinner Component

Issue: Add unit test cases for LoadingSpinner.
PR: Validating the rendering and styling of the LoadingSpinner component.

The goal of this contribution was to ensure that the LoadingSpinner component behaves as expected across various contexts, including:

  • Rendering Verification: Ensuring that all spinner elements are correctly rendered in the DOM.
  • Primary Color Application: Validating that the spinner's border color aligns with the primary color set in the settings context.
  • Custom Style Application: Verifying that additional styles passed via the styles context are correctly applied, including properties like border-radius, width, and height.

This approach guaranteed that the spinner maintains visual and functional consistency within the app's design system.

FileAttachmentButton Component

Issue: Add unit test cases for FileAttachmentButton.
PR: Testing the behavior and rendering of the FileAttachmentButton component.

The complexity of the FileAttachmentButton component required testing various states and functionalities, such as:

  • State-Dependent Icon Rendering: Validating different icons for enabled and disabled states based on context.

  • File Upload Handling: Ensuring the handleUpload function processes files correctly and calls necessary callbacks.

  • Preventing Invalid Actions: Ensuring that file uploads do not proceed if preconditions (e.g., valid file path) are not met.

The testing strategy ensured reliability in user interaction and maintained robust support for various configurations and edge cases.

Learning and Challenges

Unit testing is an area I have been aiming to improve, especially in mocking dependencies and isolating components effectively. These contributions were a great chance to apply my newfound knowledge from a recent lab task.

A significant challenge was understanding how the existing components functioned to write meaningful tests without altering the code being tested. This required delving into the codebase and determining how to simulate scenarios accurately. Another challenge was achieving comprehensive test coverage while avoiding redundant tests, which required identifying edge cases and state-specific behavior.

Mocking dependencies, such as contexts and hooks, played a pivotal role in testing these components efficiently. Through this experience, I developed a deeper appreciation for the design of testable code and the importance of clear boundaries between logic and presentation.

Conclusion

This contribution emphasized the value of testing in maintaining and scaling open-source projects. By thoroughly validating the LoadingSpinner and FileAttachmentButton components, I ensured they remain reliable across different use cases. The challenges I faced in mocking and achieving good coverage further honed my testing skills, preparing me for future contributions and projects.

Top comments (0)