Hacktoberfest Adventure with `react-chatbotify`: From Shifted Issues to Success! 🎉
madhur Saluja
Posted on October 31, 2024
For my last Hacktoberfest contribution, I tackled an issue with react-chatbotify
, which was a thrilling shift from my original assignment. I initially had another issue, but after two weeks without hearing back from the project owner, I decided it was time for a new challenge. That’s how I stumbled upon issue #223, which was all about supercharging the ChatBotLoader component with new tests. Let’s dive in! 🚀
💥 The Issue at Hand
The issue #223 was a call to action for expanding test coverage on the ChatBotLoader component. This component is like the bot's brain loader—it initializes key configurations, styles, themes, and plugins. The goal? To make sure this component performs flawlessly in every scenario!
🔧 Getting Set Up
My first task was setting up the local environment to run the react-chatbotify
repository smoothly. I peeked into existing tests to understand the project’s testing structure, and it clicked. Once I got the hang of it, I was ready to take on the ChatBotLoader. Even though I was initially assigned to a different issue, I quickly adapted to this new one—it was refreshing and pushed me to learn a lot!
🚀 What I Learned
This issue was a treasure trove of learning opportunities, especially around testing components that use multiple contexts and props in React. The ChatBotLoader, in particular, interacts with various contexts like BotRefsContext
, BotStatesContext
, and more. I needed to mock these contexts to keep the tests isolated and to focus on the component's behavior.
I also had a fun encounter with the emitRcbEvent
function and RcbEvent.PRE_LOAD_CHATBOT
(sounds fancy, right? 😆). This allowed me to dive into event testing, both before and after configuration loading.
🧩 Breaking Down the Code Fix
Here's a high-level breakdown of each test I worked on:
🔗 Flow Reference Update: This test made sure the
flowRef
updates correctly with the given flow prop. By mockingflowRef
and verifying that it received the correct flow data, the test proved that the component properly sets up the flow.🚀 Pre-Load Event Emission: This test checked that the
rcbPreLoadChatBot
event fired just before the configuration load. Mocking the function’s return allowed me to simulate this event and verifyemitRcbEvent
was doing its thing.🎨 Theme Change Reloads Config: Here, I added a new theme to the list and watched for the config reload. This test checks how the component reacts to prop changes, ensuring that every time a new theme is introduced, the component reloads.
🎉 Post-Load Event Emission: Similar to the pre-load event, this one verified that
rcbPostLoadChatBot
triggered after the configuration loaded successfully, giving it a nice little “thumbs up” for a job well done.
💡 Challenges & Research
I have to admit, working with emitRcbEvent
threw a few curveballs. The defaultPrevented
attribute required special attention, and I had to mock return values to make sure everything interacted correctly.
And of course, mocking hooks and services to test the component without breaking it required some serious sleuthing. I went down a few rabbit holes researching testing techniques, especially around context-heavy components, but it was worth every second.
🎯 Final Thoughts & Next Steps
I’m waiting for the green light from the project owner to make sure these tests hit the mark. As soon as I get the nod, I'll submit my PR here - Add unit tests for ChatBotLoader (link to come!).
The Takeaway
Working on this issue showed me the flexibility needed in open-source projects. Switching from one issue to another, adjusting to unfamiliar code, and learning new testing methods all made this journey one for the books. I’m already pumped for the next adventure!
Thanks for following along, and here's to many more coding quests! 🎉👨💻👩💻
Posted on October 31, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.