DEV Community

madhur Saluja
madhur Saluja

Posted on

Hacktoberfest Adventure with `react-chatbotify`: From Shifted Issues to Success! ๐ŸŽ‰

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:

  1. ๐Ÿ”— Flow Reference Update: This test made sure the flowRef updates correctly with the given flow prop. By mocking flowRef and verifying that it received the correct flow data, the test proved that the component properly sets up the flow.

  2. ๐Ÿš€ 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 verify emitRcbEvent was doing its thing.

  3. ๐ŸŽจ 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.

  4. ๐ŸŽ‰ 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! ๐ŸŽ‰๐Ÿ‘จโ€๐Ÿ’ป๐Ÿ‘ฉโ€๐Ÿ’ป

Top comments (0)